use of org.eclipse.winery.topologygraph.model.ToscaGraph 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
}
Aggregations