Search in sources :

Example 11 with OTTopologyFragmentRefinementModel

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());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) PermutationHelper.generatePrmWithoutPermutationMaps(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithoutPermutationMaps) PermutationHelper.addAllPermutationMappings(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addAllPermutationMappings) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) PermutationHelper.generateComplexPrmWithPatternSet(org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generateComplexPrmWithPatternSet) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) Map(java.util.Map) 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) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Aggregations

OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)11 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)8 Map (java.util.Map)7 PatternRefinementModelId (org.eclipse.winery.model.ids.extensions.PatternRefinementModelId)7 ArrayList (java.util.ArrayList)6 TopologyFragmentRefinementModelId (org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 QName (javax.xml.namespace.QName)5 HasId (org.eclipse.winery.model.tosca.HasId)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)4 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)4 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)4 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3