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());
}
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")));
}
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()));
}
}
});
}
Aggregations