<commit_before>package de.htwg.zeta.parser.shape.check

import de.htwg.zeta.common.models.project.concept.Concept
import de.htwg.zeta.common.models.project.concept.elements.MClass
import de.htwg.zeta.common.models.project.concept.elements.MReference
import de.htwg.zeta.parser.shape.parsetree.EdgeAttributes.EdgeStyle
import de.htwg.zeta.parser.shape.parsetree.ShapeParseTree
import de.htwg.zeta.parser.shape.parsetree.EdgeParseTree
import de.htwg.zeta.parser.shape.parsetree.EdgeAttributes.Target
import org.scalatest.Inside
import org.scalatest.Matchers
import org.scalatest.FreeSpec

class CheckEdgesForUndefinedConceptElementsTest extends FreeSpec with Matchers with Inside {

  "the check should" - {

    "succeed" - {

      "for a valid concept class and a valid edge reference" in {
        val myClass1 = "MyClass1"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$myClass1.$connection", target = myClass1)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = List(
            createConceptReference(name = connection, from = myClass1, to = myClass1)
          )
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe Nil
      }
    }

    "fail" - {

      "for a non existing target class" in {
        val myClass1 = "MyClass1"
        val noSuchConceptClass = "noSuchConceptClass"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$myClass1.$connection", target = noSuchConceptClass)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = List(
            createConceptReference(name = connection, from = myClass1, to = myClass1)
          )
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe List(
          "Target 'noSuchConceptClass' for edge 'myEdge' is not a concept class!"
        )
      }

      "for a non existing class reference" in {
        val myClass1 = "MyClass1"
        val noSuchConceptClass = "noSuchConceptClass"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$noSuchConceptClass.$connection", target = myClass1)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = List(
            createConceptReference(name = connection, from = myClass1, to = myClass1)
          )
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe List(
          "Concept class 'noSuchConceptClass' for edge 'myEdge' does not exist!"
        )
      }

      "for a non existing concept reference" in {
        val myClass1 = "MyClass1"
        val noSuchConnection = "noSuchConnection"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$myClass1.$noSuchConnection", target = myClass1)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = Nil
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe List(
          "Concept connection 'noSuchConnection' (in class 'MyClass1') for edge 'myEdge' does not exist!"
        )
      }

    }
  }

  private def createConcept(classes: List[MClass], references: List[MReference]): Concept = Concept(
    classes,
    references,
    enums = Nil,
    attributes = Nil,
    methods = Nil,
    uiState = ""
  )

  private def createConceptReference(name: String, from: String, to: String): MReference = MReference(
    name,
    description = "",
    sourceDeletionDeletesTarget = false,
    targetDeletionDeletesSource = false,
    sourceClassName = from,
    targetClassName = to,
    attributes = Nil,
    methods = Nil
  )

  private def createConceptClass(name: String, superTypeNames: List[String] = Nil): MClass = MClass(<commit_msg>#148 fix compile errors and travis build<commit_after>package de.htwg.zeta.parser.shape.check

import de.htwg.zeta.common.models.project.concept.Concept
import de.htwg.zeta.common.models.project.concept.elements.MClass
import de.htwg.zeta.common.models.project.concept.elements.MReference
import de.htwg.zeta.parser.shape.parsetree.EdgeAttributes.EdgeStyle
import de.htwg.zeta.parser.shape.parsetree.ShapeParseTree
import de.htwg.zeta.parser.shape.parsetree.EdgeParseTree
import de.htwg.zeta.parser.shape.parsetree.EdgeAttributes.Target
import org.scalatest.Inside
import org.scalatest.Matchers
import org.scalatest.FreeSpec

class CheckEdgesForUndefinedConceptElementsTest extends FreeSpec with Matchers with Inside {

  "the check should" - {

    "succeed" - {

      "for a valid concept class and a valid edge reference" in {
        val myClass1 = "MyClass1"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$myClass1.$connection", target = myClass1)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = List(
            createConceptReference(name = connection, from = myClass1, to = myClass1)
          )
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe Nil
      }
    }

    "fail" - {

      "for a non existing target class" in {
        val myClass1 = "MyClass1"
        val noSuchConceptClass = "noSuchConceptClass"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$myClass1.$connection", target = noSuchConceptClass)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = List(
            createConceptReference(name = connection, from = myClass1, to = myClass1)
          )
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe List(
          "Target 'noSuchConceptClass' for edge 'myEdge' is not a concept class!"
        )
      }

      "for a non existing class reference" in {
        val myClass1 = "MyClass1"
        val noSuchConceptClass = "noSuchConceptClass"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$noSuchConceptClass.$connection", target = myClass1)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = List(
            createConceptReference(name = connection, from = myClass1, to = myClass1)
          )
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe List(
          "Concept class 'noSuchConceptClass' for edge 'myEdge' does not exist!"
        )
      }

      "for a non existing concept reference" in {
        val myClass1 = "MyClass1"
        val noSuchConnection = "noSuchConnection"
        val connection = "inheritance"

        val shapes: List[ShapeParseTree] = List(
          createEdgeParseTree(connection = s"$myClass1.$noSuchConnection", target = myClass1)
        )
        val concept = createConcept(
          classes = List(
            createConceptClass(name = myClass1)
          ),
          references = Nil
        )

        val check = CheckEdgesForUndefinedConceptElements(shapes, concept)
        val errors = check.check()
        errors shouldBe List(
          "Concept connection 'noSuchConnection' (in class 'MyClass1') for edge 'myEdge' does not exist!"
        )
      }

    }
  }

  private def createConcept(classes: List[MClass], references: List[MReference]): Concept = Concept(
    classes,
    references,
    enums = Nil,
    attributes = Nil,
    methods = Nil,
    uiState = ""
  )

  private def createConceptReference(name: String, from: String, to: String): MReference = MReference(
    name,
    description = "",
    sourceDeletionDeletesTarget = false,
    targetDeletionDeletesSource = false,
    sourceClassName = from,
    targetClassName = to,
    sourceLowerBounds = 0,
    sourceUpperBounds = 0,
    targetLowerBounds = 0,
    targetUpperBounds = 0,
    attributes = Nil,
    methods = Nil
  )

  private def createConceptClass(name: String, superTypeNames: List[String] = Nil): MClass = MClass(
{'fraction_non_alphanumeric': 0.0856519367157665, 'fraction_numerical': 0.006219312602291326, 'mean_word_length': 2.5240292195309495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4945974', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2557, 'n_words': 627}