use of org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel in project winery by eclipse.
the class PermutationGeneratorTestWithGitBackedRepository method testGeneration.
@Test
void testGeneration() throws Exception {
this.setRevisionTo("origin/plain");
OTPatternRefinementModel refinementModel = generateComplexPrmWithPatternSet();
addAllPermutationMappings(refinementModel);
PatternRefinementModelId id = new PatternRefinementModelId(refinementModel.getTargetNamespace(), refinementModel.getIdFromIdOrNameField(), false);
RepositoryFactory.getRepository().setElement(id, refinementModel);
PermutationGenerator generator = new PermutationGenerator();
Map<String, OTTopologyFragmentRefinementModel> permutations = generator.generatePermutations(refinementModel);
assertEquals(2, permutations.size());
OTTopologyFragmentRefinementModel permutation_1 = permutations.get("ComplexPrmWithPatternSet_permutation-1-w1-wip1");
assertNotNull(permutation_1);
assertEquals(4, permutation_1.getDetector().getNodeTemplates().size());
assertEquals(4, permutation_1.getDetector().getRelationshipTemplates().size());
assertTrue(permutation_1.getDetector().getRelationshipTemplates().removeIf(relation -> "11".equals(relation.getSourceElement().getRef().getId()) && "12".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_1.getDetector().getRelationshipTemplates().removeIf(relation -> "11".equals(relation.getSourceElement().getRef().getId()) && "2".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_1.getDetector().getRelationshipTemplates().removeIf(relation -> "12".equals(relation.getSourceElement().getRef().getId()) && "2".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_1.getDetector().getRelationshipTemplates().removeIf(relation -> "11".equals(relation.getSourceElement().getRef().getId()) && "12".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_1.getDetector().getRelationshipTemplates().removeIf(relation -> "11".equals(relation.getSourceElement().getRef().getId()) && "2".equals(relation.getTargetElement().getRef().getId())));
assertNotNull(permutation_1.getStayMappings());
assertTrue(permutation_1.getStayMappings().removeIf(mapping -> "11".equals(mapping.getDetectorElement().getId()) && "11".equals(mapping.getRefinementElement().getId())));
assertTrue(permutation_1.getStayMappings().removeIf(mapping -> "12".equals(mapping.getDetectorElement().getId()) && "12".equals(mapping.getRefinementElement().getId())));
assertEquals(0, RefinementUtils.getAllMappingsForRefinementNode(permutation_1.getRefinementTopology().getNodeTemplate("11"), permutation_1).size());
assertEquals(0, RefinementUtils.getAllMappingsForRefinementNode(permutation_1.getRefinementTopology().getNodeTemplate("12"), permutation_1).size());
assertEquals(2, RefinementUtils.getAllMappingsForRefinementNode(permutation_1.getRefinementTopology().getNodeTemplate("13"), permutation_1).size());
assertEquals(1, RefinementUtils.getAllMappingsForRefinementNode(permutation_1.getRefinementTopology().getNodeTemplate("14"), permutation_1).size());
assertEquals(3, RefinementUtils.getAllMappingsForRefinementNode(permutation_1.getRefinementTopology().getNodeTemplate("15"), permutation_1).size());
assertEquals(1, RefinementUtils.getAllMappingsForRefinementNode(permutation_1.getRefinementTopology().getNodeTemplate("16"), permutation_1).size());
OTTopologyFragmentRefinementModel permutation_2 = permutations.get("ComplexPrmWithPatternSet_permutation-2-3-w1-wip1");
assertNotNull(permutation_2);
assertEquals(5, permutation_2.getDetector().getNodeTemplates().size());
assertEquals(5, permutation_2.getDetector().getRelationshipTemplates().size());
assertTrue(permutation_2.getDetector().getRelationshipTemplates().removeIf(relation -> "1".equals(relation.getSourceElement().getRef().getId()) && "14".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_2.getDetector().getRelationshipTemplates().removeIf(relation -> "13".equals(relation.getSourceElement().getRef().getId()) && "14".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_2.getDetector().getRelationshipTemplates().removeIf(relation -> "13".equals(relation.getSourceElement().getRef().getId()) && "15".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_2.getDetector().getRelationshipTemplates().removeIf(relation -> "15".equals(relation.getSourceElement().getRef().getId()) && "16".equals(relation.getTargetElement().getRef().getId())));
assertTrue(permutation_2.getDetector().getRelationshipTemplates().removeIf(relation -> "14".equals(relation.getSourceElement().getRef().getId()) && "16".equals(relation.getTargetElement().getRef().getId())));
assertNotNull(permutation_2.getStayMappings());
assertTrue(permutation_2.getStayMappings().removeIf(mapping -> "13".equals(mapping.getDetectorElement().getId()) && "13".equals(mapping.getRefinementElement().getId())));
assertTrue(permutation_2.getStayMappings().removeIf(mapping -> "14".equals(mapping.getDetectorElement().getId()) && "14".equals(mapping.getRefinementElement().getId())));
assertTrue(permutation_2.getStayMappings().removeIf(mapping -> "15".equals(mapping.getDetectorElement().getId()) && "15".equals(mapping.getRefinementElement().getId())));
assertTrue(permutation_2.getStayMappings().removeIf(mapping -> "16".equals(mapping.getDetectorElement().getId()) && "16".equals(mapping.getRefinementElement().getId())));
assertEquals(2, RefinementUtils.getAllMappingsForRefinementNode(permutation_2.getRefinementTopology().getNodeTemplate("11"), permutation_2).size());
assertEquals(2, RefinementUtils.getAllMappingsForRefinementNode(permutation_2.getRefinementTopology().getNodeTemplate("12"), permutation_2).size());
assertEquals(0, RefinementUtils.getAllMappingsForRefinementNode(permutation_2.getRefinementTopology().getNodeTemplate("13"), permutation_2).size());
assertEquals(0, RefinementUtils.getAllMappingsForRefinementNode(permutation_2.getRefinementTopology().getNodeTemplate("14"), permutation_2).size());
assertEquals(0, RefinementUtils.getAllMappingsForRefinementNode(permutation_2.getRefinementTopology().getNodeTemplate("15"), permutation_2).size());
assertEquals(0, RefinementUtils.getAllMappingsForRefinementNode(permutation_2.getRefinementTopology().getNodeTemplate("16"), permutation_2).size());
}
Aggregations