Search in sources :

Example 26 with UMLDiagram

use of de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram in project ArTEMiS by ls1intum.

the class UMLComponentDiagramTest method parseComponentDiagramModelCorrectly.

@Test
void parseComponentDiagramModelCorrectly() throws IOException {
    UMLDiagram diagram = UMLModelParser.buildModelFromJSON(parseString(UMLComponentDiagrams.COMPONENT_MODEL_3).getAsJsonObject(), 1L);
    assertThat(diagram).isInstanceOf(UMLComponentDiagram.class);
    UMLComponentDiagram componentDiagram = (UMLComponentDiagram) diagram;
    // 4 Components A, B, C and D
    assertThat(componentDiagram.getComponentList()).hasSize(4);
    UMLComponent componentA = getComponent(componentDiagram, "A");
    UMLComponent componentB = getComponent(componentDiagram, "B");
    UMLComponent componentC = getComponent(componentDiagram, "C");
    UMLComponent componentD = getComponent(componentDiagram, "D");
    // 5 Interfaces: I1, I2, I3, I4, I5
    assertThat(componentDiagram.getComponentInterfaceList()).hasSize(5);
    UMLComponentInterface interfaceI1 = getInterface(componentDiagram, "I1");
    UMLComponentInterface interfaceI2 = getInterface(componentDiagram, "I2");
    UMLComponentInterface interfaceI3 = getInterface(componentDiagram, "I3");
    UMLComponentInterface interfaceI4 = getInterface(componentDiagram, "I4");
    UMLComponentInterface interfaceI5 = getInterface(componentDiagram, "I5");
    // 8 relationships: 3 ComponentInterfaceProvided, 3 ComponentInterfaceRequired, 2 Dependencies
    assertThat(componentDiagram.getComponentRelationshipList()).hasSize(8);
    UMLComponentRelationship relationship1 = getRelationship(componentDiagram, componentA, componentA);
    UMLComponentRelationship relationship2 = getRelationship(componentDiagram, interfaceI1, interfaceI2);
    UMLComponentRelationship relationship3 = getRelationship(componentDiagram, componentA, interfaceI5);
    UMLComponentRelationship relationship4 = getRelationship(componentDiagram, componentD, interfaceI5);
    UMLComponentRelationship relationship5 = getRelationship(componentDiagram, componentD, componentC);
    UMLComponentRelationship relationship6 = getRelationship(componentDiagram, componentD, componentA);
    UMLComponentRelationship relationship7 = getRelationship(componentDiagram, componentB, interfaceI3);
    UMLComponentRelationship relationship8 = getRelationship(componentDiagram, componentC, interfaceI3);
    assertThat(relationship1.getRelationshipType()).isEqualByComparingTo(COMPONENT_DEPENDENCY);
    assertThat(relationship2.getRelationshipType()).isEqualByComparingTo(COMPONENT_INTERFACE_PROVIDED);
    assertThat(relationship3.getRelationshipType()).isEqualByComparingTo(COMPONENT_INTERFACE_PROVIDED);
    assertThat(relationship4.getRelationshipType()).isEqualByComparingTo(COMPONENT_INTERFACE_REQUIRED);
    assertThat(relationship5.getRelationshipType()).isEqualByComparingTo(COMPONENT_DEPENDENCY);
    assertThat(relationship6.getRelationshipType()).isEqualByComparingTo(COMPONENT_INTERFACE_REQUIRED);
    assertThat(relationship7.getRelationshipType()).isEqualByComparingTo(COMPONENT_INTERFACE_REQUIRED);
    assertThat(relationship8.getRelationshipType()).isEqualByComparingTo(COMPONENT_INTERFACE_PROVIDED);
    // check owner relationships
    assertThat(componentA.getParentElement()).isNull();
    assertThat(componentB.getParentElement()).isEqualTo(componentA);
    assertThat(componentC.getParentElement()).isEqualTo(componentB);
    assertThat(componentD.getParentElement()).isNull();
    assertThat(interfaceI1.getParentElement()).isNull();
    assertThat(interfaceI2.getParentElement()).isEqualTo(componentA);
    assertThat(interfaceI3.getParentElement()).isEqualTo(componentB);
    assertThat(interfaceI4.getParentElement()).isEqualTo(componentC);
    assertThat(interfaceI5.getParentElement()).isNull();
}
Also used : UMLDiagram(de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram) Test(org.junit.jupiter.api.Test) AbstractUMLDiagramTest(de.tum.in.www1.artemis.service.compass.umlmodel.AbstractUMLDiagramTest)

Example 27 with UMLDiagram

use of de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram in project ArTEMiS by ls1intum.

the class UMLDeploymentDiagramTest method parseDeploymentDiagramModelCorrectly.

@Test
void parseDeploymentDiagramModelCorrectly() throws IOException {
    UMLDiagram diagram = UMLModelParser.buildModelFromJSON(parseString(UMLDeploymentDiagrams.DEPLOYMENT_MODEL_3).getAsJsonObject(), 1L);
    assertThat(diagram).isInstanceOf(UMLDeploymentDiagram.class);
    UMLDeploymentDiagram deploymentDiagram = (UMLDeploymentDiagram) diagram;
    assertThat(deploymentDiagram.getComponentList()).hasSize(3);
    assertThat(deploymentDiagram.getComponentInterfaceList()).hasSize(1);
    assertThat(deploymentDiagram.getArtifactList()).hasSize(3);
    assertThat(deploymentDiagram.getNodeList()).hasSize(2);
    assertThat(deploymentDiagram.getComponentRelationshipList()).hasSize(7);
    assertThat(deploymentDiagram.getElementByJSONID("d821e11d-6cf1-497b-8462-6533047cb0e8")).isInstanceOf(UMLNode.class);
    assertThat(deploymentDiagram.getElementByJSONID("035638ac-9bb1-4bfb-a2c1-028310ae4c3e")).isInstanceOf(UMLComponent.class);
    assertThat(deploymentDiagram.getElementByJSONID("800db443-242f-4c40-8106-6b2a5fa99d2f")).isInstanceOf(UMLArtifact.class);
}
Also used : UMLDiagram(de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram) Test(org.junit.jupiter.api.Test) AbstractUMLDiagramTest(de.tum.in.www1.artemis.service.compass.umlmodel.AbstractUMLDiagramTest)

Example 28 with UMLDiagram

use of de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram in project ArTEMiS by ls1intum.

the class FlowchartTest method parseFlowchartModelCorrectly.

@Test
void parseFlowchartModelCorrectly() throws IOException {
    UMLDiagram diagram = UMLModelParser.buildModelFromJSON(parseString(FLOWCHART_MODEL_1B).getAsJsonObject(), 1L);
    assertThat(diagram).isInstanceOf(Flowchart.class);
    Flowchart flowchart = (Flowchart) diagram;
    assertThat(flowchart.getTerminals()).hasSize(2);
    assertThat(flowchart.getInputOutputs()).hasSize(2);
    assertThat(flowchart.getDecisions()).hasSize(2);
    assertThat(flowchart.getProcesses()).hasSize(2);
    assertThat(flowchart.getFlowLines()).hasSize(10);
    assertThat(flowchart.getFunctionCalls()).hasSize(1);
    assertThat(flowchart.getElementByJSONID("129c296b-1927-49e4-b021-5d496d33f5f6")).asInstanceOf(type(FlowchartTerminal.class)).satisfies(terminal -> {
        assertThat(terminal.getName()).isEqualTo("Start");
    });
    assertThat(flowchart.getElementByJSONID("cdc6ac64-2d3d-4468-8540-0cf9ed8ce8ec")).asInstanceOf(type(FlowchartInputOutput.class)).satisfies(inputOutput -> {
        assertThat(inputOutput.getName()).isEqualTo("x=readInt(); y=readInt();");
    });
    assertThat(flowchart.getElementByJSONID("0763f5e8-3ac0-4fa2-b52c-c8df0c5df563")).asInstanceOf(type(FlowchartDecision.class)).satisfies(decision -> {
        assertThat(decision.getName()).isEqualTo("x < y");
    });
    assertThat(flowchart.getElementByJSONID("74d972c6-efb6-4a6e-bd10-2e5b1fd8c3b8")).asInstanceOf(type(FlowchartProcess.class)).satisfies(process -> {
        assertThat(process.getName()).isEqualTo("y = y - x;");
    });
    assertThat(flowchart.getElementByJSONID("8b86b06b-baf8-48d0-a8f0-925a11fd552d")).asInstanceOf(type(FlowchartFunctionCall.class)).satisfies(functionCall -> {
        assertThat(functionCall.getName()).isEqualTo("x = max();");
    });
    assertThat(flowchart.getElementByJSONID("5c178df3-686e-435c-88bc-1fca2d20d090")).asInstanceOf(type(FlowchartFlowline.class)).satisfies(flowline -> {
        assertThat(flowline.getSource()).isNotNull().isSameAs(flowchart.getElementByJSONID("129c296b-1927-49e4-b021-5d496d33f5f6"));
        assertThat(flowline.getTarget()).isNotNull().isSameAs(flowchart.getElementByJSONID("cdc6ac64-2d3d-4468-8540-0cf9ed8ce8ec"));
    });
}
Also used : UMLDiagram(de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram) Test(org.junit.jupiter.api.Test) AbstractUMLDiagramTest(de.tum.in.www1.artemis.service.compass.umlmodel.AbstractUMLDiagramTest)

Example 29 with UMLDiagram

use of de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram in project Artemis by ls1intum.

the class UMLModelParserTest method buildModelFromJSON_componentDiagram_empty.

@Test
void buildModelFromJSON_componentDiagram_empty() throws Exception {
    JsonObject componentDiagramJson = loadFileFromResources("test-data/model-submission/empty-component-diagram.json");
    UMLDiagram umlDiagram = UMLModelParser.buildModelFromJSON(componentDiagramJson, 123456789);
    assertThat(umlDiagram.getModelSubmissionId()).isEqualTo(123456789);
    assertThat(umlDiagram.getAllModelElements()).isEmpty();
}
Also used : UMLDiagram(de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test)

Example 30 with UMLDiagram

use of de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram in project Artemis by ls1intum.

the class UMLModelParserTest method buildModelFromJSON_classDiagram_packageRelationship.

@Test
void buildModelFromJSON_classDiagram_packageRelationship() throws Exception {
    JsonObject classDiagramJson = loadFileFromResources("test-data/model-submission/example-class-diagram-package-relationship.json");
    UMLPackage umlPackage = new UMLPackage("Package", emptyList(), "94d565ec-c92c-422c-b3bd-347974936348");
    UMLClass umlClass = new UMLClass("Class", emptyList(), emptyList(), "ac9c281b-5b2c-4b3d-87c0-db798bd1f513", UMLClassType.CLASS);
    UMLDiagram umlDiagram = UMLModelParser.buildModelFromJSON(classDiagramJson, 123456789);
    assertThat(umlDiagram.getModelSubmissionId()).isEqualTo(123456789);
    assertThat(umlDiagram.getAllModelElements()).containsExactlyInAnyOrder(umlClass, umlPackage);
}
Also used : UMLDiagram(de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test)

Aggregations

UMLDiagram (de.tum.in.www1.artemis.service.compass.umlmodel.UMLDiagram)38 Test (org.junit.jupiter.api.Test)36 JsonObject (com.google.gson.JsonObject)20 AbstractUMLDiagramTest (de.tum.in.www1.artemis.service.compass.umlmodel.AbstractUMLDiagramTest)16 UMLElement (de.tum.in.www1.artemis.service.compass.umlmodel.UMLElement)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonParser.parseString (com.google.gson.JsonParser.parseString)2 PlagiarismCheckState (de.tum.in.www1.artemis.domain.PlagiarismCheckState)2 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)2 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)2 Participation (de.tum.in.www1.artemis.domain.participation.Participation)2 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)2 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)2 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)2 ModelingSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingSubmissionElement)2 UMLModelParser (de.tum.in.www1.artemis.service.compass.umlmodel.parsers.UMLModelParser)2 IOException (java.io.IOException)2 java.util (java.util)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2