use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class PermutationGeneratorTest method checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping2.
@Test
void checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping2() {
OTPatternRefinementModel refinementModel = generatePrmWithComplexRelationMaps2();
PermutationGenerator permutationGenerator = new PermutationGenerator();
assertTrue(permutationGenerator.checkMutability(refinementModel));
List<OTPermutationMapping> mappings = refinementModel.getPermutationMappings();
assertEquals(6, mappings.size());
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("11")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("12")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("13")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("2") && permutationMap.getRefinementElement().getId().equals("14")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("2") && permutationMap.getRefinementElement().getId().equals("15")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("con-1--2") && permutationMap.getRefinementElement().getId().equals("14")));
}
use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class PermutationGeneratorTest method checkSimplePrmMutability.
@Test
void checkSimplePrmMutability() {
OTPatternRefinementModel refinementModel = generatePrmWithoutPermutationMaps();
PermutationGenerator permutationGenerator = new PermutationGenerator();
assertTrue(permutationGenerator.checkMutability(refinementModel));
assertEquals(6, refinementModel.getPermutationOptions().size());
assertEquals(7, refinementModel.getPermutationMappings().size());
}
use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class BehaviorPatternDetectionTest method addCompatibleBehaviorPatterns.
@Test
public void addCompatibleBehaviorPatterns() {
List<TPolicy> behaviorPatterns = new ArrayList<>();
behaviorPatterns.add(new TPolicy(new TPolicy.Builder(QName.valueOf("{patternNs}oneProp")).setName("oneProp")));
TNodeTemplate detectorElement = new TNodeTemplate(new TNodeTemplate.Builder("detectorElement", QName.valueOf("{ns}patternType")).setPolicies(behaviorPatterns).setX("1").setY("1"));
TNodeTemplate refinementElement = new TNodeTemplate(new TNodeTemplate.Builder("refinementElement", QName.valueOf("{ns}concreteType")).setX("1").setY("1"));
LinkedHashMap<String, String> refinementProps = new LinkedHashMap<>();
refinementProps.put("oneProp", "true");
ModelUtilities.setPropertiesKV(refinementElement, refinementProps);
List<TPolicy> stayingPolicies = new ArrayList<>();
stayingPolicies.add(new TPolicy(new TPolicy.Builder(QName.valueOf("{ns}normalPolicy")).setName("normalPolicy")));
TNodeTemplate stayingElement = new TNodeTemplate(new TNodeTemplate.Builder("stayingElement", QName.valueOf("{ns}concreteType")).setPolicies(stayingPolicies).setX("1").setY("1"));
LinkedHashMap<String, String> stayingProps = new LinkedHashMap<>();
stayingProps.put("oneProp", "false");
ModelUtilities.setPropertiesKV(stayingElement, stayingProps);
List<OTStayMapping> stayMappings = Collections.singletonList(new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement)));
List<OTBehaviorPatternMapping> behaviorPatternMappings = Collections.singletonList(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap0").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("oneProp").setProperty(new OTPropertyKV("oneProp", "true"))));
TTopologyTemplate detector = new TTopologyTemplate();
detector.addNodeTemplate(detectorElement);
TTopologyTemplate refinementStructure = new TTopologyTemplate();
refinementStructure.addNodeTemplate(refinementElement);
OTPatternRefinementModel prm = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinementStructure).setStayMappings(stayMappings).setBehaviorPatternMappings(behaviorPatternMappings));
// needs to be swapped manually as only PRMs retrieved from repo are swapped automatically
PatternDetectionUtils.swapDetectorWithRefinement(prm);
TTopologyTemplate topology = new TTopologyTemplate();
topology.addNodeTemplate(stayingElement);
ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topology);
ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(prm.getDetector());
IToscaMatcher matcher = new ToscaBehaviorPatternMatcher(prm, namespaceManager());
ToscaIsomorphismMatcher isomorphismMatcher = new ToscaIsomorphismMatcher();
Iterator<GraphMapping<ToscaNode, ToscaEdge>> matches = isomorphismMatcher.findMatches(detectorGraph, topologyGraph, matcher);
RefinementCandidate refinementCandidate = new RefinementCandidate(prm, matches.next(), detectorGraph, 1);
// 'normalPolicy' is not removed because not behavior pattern, 'oneProp' not present behavior pattern mapping doesn't match
BehaviorPatternDetection behaviorPatternDetection = new BehaviorPatternDetection(new DefaultRefinementChooser());
behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
assertEquals(topology.getNodeTemplates().get(0).getId(), "stayingElement");
List<TPolicy> policies = topology.getNodeTemplates().get(0).getPolicies();
assertEquals(policies.size(), 1);
assertEquals(policies.get(0).getName(), "normalPolicy");
// 'normalPolicy' is not removed because not behavior pattern, 'oneProp' present behavior pattern mapping matches
stayingProps.put("oneProp", "true");
topology.getNodeTemplateOrRelationshipTemplate().clear();
topology.addNodeTemplate(stayingElement);
behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
assertEquals(topology.getNodeTemplates().get(0).getId(), "stayingElement");
policies = topology.getNodeTemplates().get(0).getPolicies();
assertEquals(policies.size(), 2);
assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("normalPolicy")));
assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("oneProp")));
}
use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class ComponentPatternDetection method adaptPrm.
private RefinementCandidate adaptPrm(RefinementCandidate candidate) {
OTPatternRefinementModel prm = (OTPatternRefinementModel) candidate.getRefinementModel();
OTPatternRefinementModel adaptedPrm = PatternDetectionUtils.clone(prm);
componentPatternCandidates.get(prm).forEach(componentPatternCandidate -> addRelationMappings(componentPatternCandidate, adaptedPrm));
removeNotApplicable(adaptedPrm);
return new RefinementCandidate(adaptedPrm, candidate.getGraphMapping(), candidate.getDetectorGraph(), candidate.getId());
}
use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class BehaviorPatternDetection method applyRefinement.
@Override
public Map<String, String> applyRefinement(RefinementCandidate refinement, TTopologyTemplate topology) {
Map<String, String> idMapping = super.applyRefinement(refinement, topology);
OTPatternRefinementModel prm = (OTPatternRefinementModel) refinement.getRefinementModel();
prm.getRefinementStructure().getNodeTemplateOrRelationshipTemplate().forEach(refinementElement -> {
String newId = idMapping.get(refinementElement.getId());
boolean isStayingElement = newId == null;
if (isStayingElement) {
addCompatibleBehaviorPatterns(refinementElement, refinement);
} else {
TEntityTemplate addedElement = topology.getNodeTemplateOrRelationshipTemplate(newId);
removeIncompatibleBehaviorPatterns(refinementElement, addedElement, refinement);
}
});
return idMapping;
}
Aggregations