Search in sources :

Example 6 with DefaultRefinementChooser

use of org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser in project winery by eclipse.

the class PatternDetectionTestWithGitBackedRepository method detectPatterns.

@Test
public void detectPatterns() throws Exception {
    this.setRevisionTo("origin/plain");
    ServiceTemplateId testTemplateId = new ServiceTemplateId("http://www.example.org/tosca/servicetemplates", "PatternDetectionTest_w1-wip1", false);
    PatternDetection detection = new PatternDetection(new DefaultRefinementChooser());
    ServiceTemplateId serviceTemplateId = detection.refineServiceTemplate(testTemplateId);
    TTopologyTemplate topology = RepositoryFactory.getRepository().getElement(serviceTemplateId).getTopologyTemplate();
    assertNotNull(topology);
    QName java = QName.valueOf("{http://winery.opentosca.org/test/nodetypes}Java_8-Servelet-w1");
    QName firstPattern = QName.valueOf("{http://plain.winery.opentosca.org/patterns}FirstPattern_w1");
    QName secondPattern = QName.valueOf("{http://plain.winery.opentosca.org/patterns}SecondPattern_w1");
    QName thirdPattern = QName.valueOf("{http://plain.winery.opentosca.org/patterns}ThirdPattern_w1");
    QName secureSql = QName.valueOf("{http://www.example.org/tosca/relationshiptypes}Secure-SQL-Con_w1-wip1");
    QName hostedOn = QName.valueOf("{http://winery.opentosca.org/test/relationshiptypes}hostedOn");
    List<TNodeTemplate> nodeTemplates = topology.getNodeTemplates();
    assertEquals(nodeTemplates.size(), 4);
    Set<QName> nodeTypes = nodeTemplates.stream().map(TNodeTemplate::getType).collect(Collectors.toSet());
    assertEquals(nodeTypes.size(), 4);
    assertTrue(nodeTypes.contains(java));
    assertTrue(nodeTypes.contains(firstPattern));
    assertTrue(nodeTypes.contains(secondPattern));
    assertTrue(nodeTypes.contains(thirdPattern));
    List<TRelationshipTemplate> relationshipTemplates = topology.getRelationshipTemplates();
    assertEquals(relationshipTemplates.size(), 4);
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(secureSql) && rt.getSourceElement().getRef().getType().equals(java) && rt.getTargetElement().getRef().getType().equals(secondPattern)));
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(hostedOn) && rt.getSourceElement().getRef().getType().equals(java) && rt.getTargetElement().getRef().getType().equals(firstPattern)));
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(hostedOn) && rt.getSourceElement().getRef().getType().equals(firstPattern) && rt.getTargetElement().getRef().getType().equals(thirdPattern)));
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(hostedOn) && rt.getSourceElement().getRef().getType().equals(secondPattern) && rt.getTargetElement().getRef().getType().equals(thirdPattern)));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Set(java.util.Set) Collectors(java.util.stream.Collectors) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultRefinementChooser

use of org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser in project winery by eclipse.

the class PatternRefinementTest method testIsApplicable.

// region ********** isApplicable() **********
@ParameterizedTest(name = "{index} => ''{3}''")
@MethodSource("getIsApplicableArguments")
void testIsApplicable(RefinementCandidate refinementCandidate, TTopologyTemplate topologyTemplate, boolean expected, String description) {
    PatternRefinement patternRefinement = new PatternRefinement(new DefaultRefinementChooser());
    assertEquals(expected, patternRefinement.isApplicable(refinementCandidate, topologyTemplate));
}
Also used : DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

DefaultRefinementChooser (org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser)7 Test (org.junit.jupiter.api.Test)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 QName (javax.xml.namespace.QName)4 TPolicy (org.eclipse.winery.model.tosca.TPolicy)4 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 Collections (java.util.Collections)3 Iterator (java.util.Iterator)3 LinkedHashMap (java.util.LinkedHashMap)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)3 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)3 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)3 ToscaIsomorphismMatcher (org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher)3 PatternDetectionUtils (org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils)3 ToscaEdge (org.eclipse.winery.topologygraph.model.ToscaEdge)3