Search in sources :

Example 31 with OTPatternRefinementModel

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

the class PermutationGeneratorTest method checkPrmWithStayingMutability.

@Test
void checkPrmWithStayingMutability() {
    OTPatternRefinementModel refinementModel = generatePrmWithStayMapping();
    PermutationGenerator permutationGenerator = new PermutationGenerator();
    assertTrue(permutationGenerator.checkMutability(refinementModel));
    assertEquals(2, refinementModel.getPermutationOptions().size());
    assertEquals(5, refinementModel.getPermutationMappings().size());
}
Also used : OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 32 with OTPatternRefinementModel

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

the class PermutationGeneratorTest method checkMutabilityOfPrmWithTwoPatternsHostedOnOne.

@Test
void checkMutabilityOfPrmWithTwoPatternsHostedOnOne() {
    OTPatternRefinementModel refinementModel = generatePrmWithTwoPatternsHostedOnAThird();
    PermutationGenerator permutationGenerator = new PermutationGenerator();
    assertTrue(permutationGenerator.checkMutability(refinementModel));
    List<OTPermutationMapping> permutationMappings = refinementModel.getPermutationMappings();
    assertEquals(7, permutationMappings.size());
    assertTrue(permutationMappings.removeIf(mapping -> mapping.getDetectorElement().getId().equals("1") && mapping.getRefinementElement().getId().equals("11")));
    assertTrue(permutationMappings.removeIf(mapping -> mapping.getDetectorElement().getId().equals("3") && mapping.getRefinementElement().getId().equals("12")));
    assertTrue(permutationMappings.removeIf(mapping -> mapping.getDetectorElement().getId().equals("2") && mapping.getRefinementElement().getId().equals("13")));
    assertTrue(permutationMappings.removeIf(mapping -> mapping.getDetectorElement().getId().equals("2") && mapping.getRefinementElement().getId().equals("14")));
    assertTrue(permutationMappings.removeIf(mapping -> mapping.getDetectorElement().getId().equals("con-1--3") && mapping.getRefinementElement().getId().equals("12")));
    assertTrue(permutationMappings.removeIf(mapping -> mapping.getDetectorElement().getId().equals("con-1--2") && mapping.getRefinementElement().getId().equals("13")));
    assertTrue(permutationMappings.removeIf(mapping -> mapping.getDetectorElement().getId().equals("con-3--2") && mapping.getRefinementElement().getId().equals("13")));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) PermutationHelper.generatePrmWithoutPermutationMaps(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithoutPermutationMaps) PermutationHelper.addSomePermutationMappings(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addSomePermutationMappings) PermutationHelper.generatePrmWithComplexRelationMaps2(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithComplexRelationMaps2) PermutationHelper.addAllPermutationMappings(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addAllPermutationMappings) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test) List(java.util.List) PermutationHelper.generateComplexPrmWithPatternSet(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generateComplexPrmWithPatternSet) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PermutationHelper.generatePrmWithComplexRelationMaps(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithComplexRelationMaps) PermutationHelper.generatePrmWithStayMapping(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithStayMapping) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) Test(org.junit.jupiter.api.Test)

Example 33 with OTPatternRefinementModel

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

the class BehaviorPatternDetection method removeIncompatibleBehaviorPatterns.

private void removeIncompatibleBehaviorPatterns(TEntityTemplate refinementElement, TEntityTemplate addedElement, RefinementCandidate refinement) {
    OTPatternRefinementModel prm = (OTPatternRefinementModel) refinement.getRefinementModel();
    List<TPolicy> addedElementPolicies = ((HasPolicies) addedElement).getPolicies();
    prm.getBehaviorPatternMappings().stream().filter(bpm -> bpm.getRefinementElement().getId().equals(refinementElement.getId())).forEach(bpm -> {
        ToscaEntity detectorElement = refinement.getDetectorGraph().getVertexOrEdge(bpm.getDetectorElement().getId()).get();
        TEntityTemplate candidateElement = getEntityCorrespondence(detectorElement, refinement.getGraphMapping());
        if (ModelUtilities.hasKvProperties(detectorElement.getTemplate()) && ModelUtilities.hasKvProperties(candidateElement)) {
            String detectorValue = ModelUtilities.getPropertiesKV(detectorElement.getTemplate()).get(bpm.getProperty().getKey());
            String candidateValue = ModelUtilities.getPropertiesKV(candidateElement).get(bpm.getProperty().getKey());
            boolean propsNotCompatible = (detectorValue != null && !detectorValue.isEmpty()) && !detectorValue.equalsIgnoreCase(candidateValue) && (!detectorValue.equals("*") || (candidateValue == null || candidateValue.isEmpty()));
            if (propsNotCompatible) {
                TPolicy behaviorPattern = ((HasPolicies) refinementElement).getPolicies().stream().filter(policy -> bpm.getBehaviorPattern().equals(policy.getName())).findFirst().get();
                addedElementPolicies.removeIf(policy -> policy.getPolicyType().equals(behaviorPattern.getPolicyType()));
            }
        }
    });
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) TopologyFragmentRefinement(org.eclipse.winery.model.adaptation.substitution.refinement.topologyrefinement.TopologyFragmentRefinement) RefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) List(java.util.List) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) Map(java.util.Map) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) PatternDetectionUtils.getEntityCorrespondence(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils.getEntityCorrespondence) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Aggregations

OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)33 Test (org.junit.jupiter.api.Test)23 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)16 ArrayList (java.util.ArrayList)14 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)14 List (java.util.List)12 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)12 OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)10 QName (javax.xml.namespace.QName)8 PatternRefinementModelId (org.eclipse.winery.model.ids.extensions.PatternRefinementModelId)8 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)8 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8 Arrays (java.util.Arrays)7 LinkedHashMap (java.util.LinkedHashMap)7 PermutationHelper.addAllPermutationMappings (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addAllPermutationMappings)7 PermutationHelper.generateComplexPrmWithPatternSet (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generateComplexPrmWithPatternSet)7 PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird)7