Search in sources :

Example 1 with OTRefinementModel

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

the class PatternDetectionUtilsTest method toPdrms.

@Test
public void toPdrms() {
    List<OTRefinementModel> refinementModels = new ArrayList<>();
    refinementModels.add(new OTTestRefinementModel());
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    refinementModels.add(new OTTopologyFragmentRefinementModel());
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    OTPatternRefinementModel prm = new OTPatternRefinementModel();
    refinementModels.add(prm);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    prm.setIsPdrm(true);
    refinementModels.add(prm);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 1);
    prm.setIsPdrm(false);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
}
Also used : OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArrayList(java.util.ArrayList) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 2 with OTRefinementModel

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

the class ToscaComponentPatternMatcherTest method componentPatternsCompatible.

@Test
public void componentPatternsCompatible() {
    // prm1 doesn't match the candidate but implements the same Component Pattern 'patternType1'
    TNodeTemplate detector1 = new TNodeTemplate(new TNodeTemplate.Builder("detector1", new QName("patternType1")));
    TNodeTemplate refinement1 = new TNodeTemplate(new TNodeTemplate.Builder("refinement1", new QName("concreteType1")));
    ToscaNode refinement1Node = new ToscaNode();
    refinement1Node.setNodeTemplate(refinement1);
    List<OTPermutationMapping> permutationMappings1 = new ArrayList<>();
    permutationMappings1.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(detector1).setRefinementElement(refinement1)));
    OTPatternRefinementModel prm1 = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(detector1))).setRefinementStructure(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(refinement1))).setPermutationMappings(permutationMappings1));
    // needs to be swapped manually as only prms retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm1);
    // prm2 matches the candidate and also implements the Component Pattern 'patternType1'
    TNodeTemplate detector2 = new TNodeTemplate(new TNodeTemplate.Builder("detector2", new QName("patternType1")));
    TNodeTemplate refinement2 = new TNodeTemplate(new TNodeTemplate.Builder("refinement2", new QName("concreteType2")));
    ToscaNode refinement2Node = new ToscaNode();
    refinement2Node.setNodeTemplate(refinement2);
    List<OTPermutationMapping> permutationMappings2 = new ArrayList<>();
    permutationMappings2.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(detector2).setRefinementElement(refinement2)));
    OTPatternRefinementModel prm2 = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(detector2))).setRefinementStructure(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(refinement2))).setPermutationMappings(permutationMappings2));
    // needs to be swapped manually as only prms retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm2);
    List<OTRefinementModel> prms = new ArrayList<>();
    prms.add(prm1);
    ToscaComponentPatternMatcher matcher = new ToscaComponentPatternMatcher(prm1, null, prms, new HashMap<>());
    ToscaNode candidate = new ToscaNode();
    candidate.setNodeTemplate(new TNodeTemplate(new TNodeTemplate.Builder("nt1", new QName("concreteType2"))));
    // only prm1 available -> doesn't match
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prms.add(prm2);
    // now prm2 can also be used -> matches
    assertTrue(matcher.isCompatible(refinement1Node, candidate));
    prms.clear();
    prms.add(prm2);
    matcher = new ToscaComponentPatternMatcher(prm2, null, prms, new HashMap<>());
    // prm2 used directly -> also matches
    assertTrue(matcher.isCompatible(refinement2Node, candidate));
    prms.add(prm1);
    // still matches
    assertTrue(matcher.isCompatible(refinement2Node, candidate));
    matcher = new ToscaComponentPatternMatcher(prm1, null, prms, new HashMap<>());
    OTPermutationMapping oneTooMany = new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(new TNodeTemplate(new TNodeTemplate.Builder("tmp1", new QName("tmp1")))).setRefinementElement(refinement1));
    permutationMappings1.add((OTPermutationMapping) PatternDetectionUtils.swapDetectorWithRefinement(oneTooMany));
    // detector is associated with multiple Component patterns -> not one-to-one
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    oneTooMany.setDetectorElement(detector1);
    oneTooMany.setRefinementElement(new TNodeTemplate(new TNodeTemplate.Builder("tmp2", new QName("tmp2"))));
    PatternDetectionUtils.swapDetectorWithRefinement(oneTooMany);
    // refinement element is associated with multiple Component patterns -> not one-to-one
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    permutationMappings1.remove(oneTooMany);
    // after removal, it's one-to-one again
    assertTrue(matcher.isCompatible(refinement1Node, candidate));
    // empty or null
    prm2.getPermutationMappings().clear();
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prm1.getPermutationMappings().clear();
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prm2.setPermutationMappings(null);
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prm1.setPermutationMappings(null);
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)2 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)2 OTRefinementModel (org.eclipse.winery.model.tosca.extensions.OTRefinementModel)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)1 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)1 OTTestRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel)1 OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)1 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)1