Search in sources :

Example 11 with OTRelationMapping

use of org.eclipse.winery.model.tosca.extensions.OTRelationMapping in project winery by eclipse.

the class TestRefinementTest method applyRefinementTest.

@Test
public void applyRefinementTest() {
    // region *** topology ***
    TNodeTemplate tomcat = new TNodeTemplate();
    tomcat.setId("tomcat");
    tomcat.setType("{ns}tomcat");
    TNodeTemplate webShop = new TNodeTemplate();
    webShop.setId("webShop");
    webShop.setType("{ns}webShop");
    TNodeTemplate database = new TNodeTemplate();
    database.setId("database");
    database.setType("{ns}database");
    TRelationshipTemplate webShopOnTomcat = new TRelationshipTemplate();
    webShopOnTomcat.setSourceNodeTemplate(webShop);
    webShopOnTomcat.setTargetNodeTemplate(tomcat);
    webShopOnTomcat.setType("{ns}hostedOn");
    TRelationshipTemplate webShopToDatabase = new TRelationshipTemplate();
    webShopToDatabase.setTargetNodeTemplate(database);
    webShopToDatabase.setSourceNodeTemplate(webShop);
    webShopToDatabase.setType("{ns}connectsTo");
    TTopologyTemplate topologyTemplate = new TTopologyTemplate.Builder().addNodeTemplate(tomcat).addNodeTemplate(webShop).addNodeTemplate(database).addRelationshipTemplate(webShopOnTomcat).addRelationshipTemplate(webShopToDatabase).build();
    // endregion
    // region *** refinement model ***
    TNodeTemplate mySqlConnectorTest = new TNodeTemplate();
    mySqlConnectorTest.setId("sqlConnectorTest");
    mySqlConnectorTest.setType("{ns}sqlConnectorTest");
    TTopologyTemplate refinementTopology = new TTopologyTemplate.Builder().addNodeTemplate(mySqlConnectorTest).build();
    OTRelationMapping testHostedOn = new OTRelationMapping(new OTRelationMapping.Builder().setDirection(OTRelationDirection.OUTGOING).setRelationType(QName.valueOf("{ns}hostedOn")).setRefinementElement(mySqlConnectorTest).setDetectorElement(tomcat));
    OTRelationMapping testConnectsTo = new OTRelationMapping(new OTRelationMapping.Builder().setDirection(OTRelationDirection.OUTGOING).setRelationType(QName.valueOf("{ns}connectsTo")).setRefinementElement(mySqlConnectorTest).setDetectorElement(database));
    OTRelationMapping testIngoingRelationTest = new OTRelationMapping(new OTRelationMapping.Builder().setDirection(OTRelationDirection.INGOING).setRelationType(QName.valueOf("{ns}ingoingTest")).setRefinementElement(mySqlConnectorTest).setDetectorElement(webShop));
    List<OTRelationMapping> relationMappings = new ArrayList<>();
    relationMappings.add(testHostedOn);
    relationMappings.add(testConnectsTo);
    relationMappings.add(testIngoingRelationTest);
    OTTestRefinementModel testRefinementModel = new OTTestRefinementModel(new OTTestRefinementModel.Builder().setTestFragment(refinementTopology).setDetector(topologyTemplate).setRelationMappings(relationMappings));
    // endregion
    ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topologyTemplate);
    ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(testRefinementModel.getDetector());
    ToscaIsomorphismMatcher matcher = new ToscaIsomorphismMatcher();
    Iterator<GraphMapping<ToscaNode, ToscaEdge>> mappings = matcher.findMatches(detectorGraph, topologyGraph, new ToscaTypeMatcher());
    GraphMapping<ToscaNode, ToscaEdge> mapping = mappings.next();
    RefinementCandidate refinementCandidate = new RefinementCandidate(testRefinementModel, mapping, detectorGraph, 1);
    TestRefinement testRefinement = new TestRefinement();
    testRefinement.applyRefinement(refinementCandidate, topologyTemplate);
    // region *** assertions ***
    assertEquals(4, topologyTemplate.getNodeTemplates().size());
    assertEquals(5, topologyTemplate.getRelationshipTemplates().size());
    TRelationshipTemplate mimicTestHostedOnTomcat = topologyTemplate.getRelationshipTemplate("mimicTest-hostedOn");
    assertNotNull(mimicTestHostedOnTomcat);
    assertEquals("tomcat", mimicTestHostedOnTomcat.getTargetElement().getRef().getId());
    assertEquals("sqlConnectorTest", mimicTestHostedOnTomcat.getSourceElement().getRef().getId());
    TRelationshipTemplate mimicTestConnectsToDatabase = topologyTemplate.getRelationshipTemplate("mimicTest-connectsTo");
    assertNotNull(mimicTestConnectsToDatabase);
    assertEquals("database", mimicTestConnectsToDatabase.getTargetElement().getRef().getId());
    assertEquals("sqlConnectorTest", mimicTestConnectsToDatabase.getSourceElement().getRef().getId());
    TRelationshipTemplate mimicTestTestIngoingConnection = topologyTemplate.getRelationshipTemplate("mimicTest-ingoingTest");
    assertNotNull(mimicTestTestIngoingConnection);
    assertEquals("webShop", mimicTestTestIngoingConnection.getSourceElement().getRef().getId());
    assertEquals("sqlConnectorTest", mimicTestTestIngoingConnection.getTargetElement().getRef().getId());
// endregion
}
Also used : ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaTypeMatcher(org.eclipse.winery.topologygraph.matching.ToscaTypeMatcher) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.jupiter.api.Test)

Example 12 with OTRelationMapping

use of org.eclipse.winery.model.tosca.extensions.OTRelationMapping in project winery by eclipse.

the class RefinementUtils method addRelationMapping.

public static void addRelationMapping(TNodeTemplate detectorNode, TEntityTemplate refinementNode, QName relationType, OTRelationDirection direction, QName validSourOrTarget, OTTopologyFragmentRefinementModel prm) {
    OTRelationMapping mapping = new OTRelationMapping(new OTRelationMapping.Builder());
    prm.setRelationMappings(addMapping(detectorNode, refinementNode, mapping, prm.getRelationMappings()));
    mapping.setRelationType(relationType);
    mapping.setDirection(direction);
    mapping.setValidSourceOrTarget(validSourOrTarget);
}
Also used : OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping)

Aggregations

OTRelationMapping (org.eclipse.winery.model.tosca.extensions.OTRelationMapping)12 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)10 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)9 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)8 ArrayList (java.util.ArrayList)6 OTAttributeMapping (org.eclipse.winery.model.tosca.extensions.OTAttributeMapping)6 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)6 OTDeploymentArtifactMapping (org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping)5 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)5 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)4 LinkedHashMap (java.util.LinkedHashMap)3 OTBehaviorPatternMapping (org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping)3 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)2 OTPropertyKV (org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV)2 RefinementTopologyTemplateResource (org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.RefinementTopologyTemplateResource)2 ToscaIsomorphismMatcher (org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher)2 ToscaTypeMatcher (org.eclipse.winery.topologygraph.matching.ToscaTypeMatcher)2