Search in sources :

Example 1 with PatternRefinementModelId

use of org.eclipse.winery.model.ids.extensions.PatternRefinementModelId in project winery by eclipse.

the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.

public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
    final TDefinitions definitions = createWrapperDefinitions(id, repository);
    HasIdInIdOrNameField element;
    if (id instanceof RelationshipTypeImplementationId) {
        element = new TRelationshipTypeImplementation();
    } else if (id instanceof NodeTypeImplementationId) {
        element = new TNodeTypeImplementation();
    } else if (id instanceof RequirementTypeId) {
        element = new TRequirementType();
    } else if (id instanceof NodeTypeId) {
        element = new TNodeType();
    } else if (id instanceof RelationshipTypeId) {
        element = new TRelationshipType();
    } else if (id instanceof CapabilityTypeId) {
        element = new TCapabilityType();
    } else if (id instanceof DataTypeId) {
        element = new TDataType();
    } else if (id instanceof ArtifactTypeId) {
        element = new TArtifactType();
    } else if (id instanceof PolicyTypeId) {
        element = new TPolicyType();
    } else if (id instanceof PolicyTemplateId) {
        element = new TPolicyTemplate();
    } else if (id instanceof ServiceTemplateId) {
        element = new TServiceTemplate();
    } else if (id instanceof ArtifactTemplateId) {
        element = new TArtifactTemplate();
    } else if (id instanceof ComplianceRuleId) {
        element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
    } else if (id instanceof PatternRefinementModelId) {
        element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TopologyFragmentRefinementModelId) {
        element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TestRefinementModelId) {
        element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
    } else if (id instanceof InterfaceTypeId) {
        element = new TInterfaceType();
    } else if (id instanceof XSDImportId) {
        // TImport has no id; thus directly generating it without setting an id
        TImport tImport = new TImport();
        definitions.setElement(tImport);
        return definitions;
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
    copyIdToFields(element, id);
    definitions.setElement((TExtensibleElements) element);
    return definitions;
}
Also used : OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TDataType(org.eclipse.winery.model.tosca.TDataType) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 2 with PatternRefinementModelId

use of org.eclipse.winery.model.ids.extensions.PatternRefinementModelId in project winery by eclipse.

the class PermutationGeneratorTestWithGitBackedRepository method simplePrmTest.

@Test
void simplePrmTest() throws Exception {
    this.setRevisionTo("origin/plain");
    OTPatternRefinementModel refinementModel = generatePrmWithoutPermutationMaps();
    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(6, permutations.size());
    OTTopologyFragmentRefinementModel permutation_1 = permutations.get("SimplePrm_permutation-1-w1-wip1");
    assertNotNull(permutation_1);
    assertEquals(4, permutation_1.getDetector().getNodeTemplates().size());
    assertEquals(4, permutation_1.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_2 = permutations.get("SimplePrm_permutation-2-w1-wip1");
    assertNotNull(permutation_2);
    assertEquals(3, permutation_2.getDetector().getNodeTemplates().size());
    assertEquals(2, permutation_2.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_3 = permutations.get("SimplePrm_permutation-3-w1-wip1");
    assertNotNull(permutation_3);
    assertEquals(4, permutation_3.getDetector().getNodeTemplates().size());
    assertEquals(3, permutation_3.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_1_2 = permutations.get("SimplePrm_permutation-1-2-w1-wip1");
    assertNotNull(permutation_1_2);
    assertEquals(4, permutation_1_2.getDetector().getNodeTemplates().size());
    assertEquals(4, permutation_1_2.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_1_3 = permutations.get("SimplePrm_permutation-1-3-w1-wip1");
    assertNotNull(permutation_1_3);
    assertEquals(5, permutation_1_3.getDetector().getNodeTemplates().size());
    assertEquals(5, permutation_1_3.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_2_3 = permutations.get("SimplePrm_permutation-2-3-w1-wip1");
    assertNotNull(permutation_2_3);
    assertEquals(4, permutation_2_3.getDetector().getNodeTemplates().size());
    assertEquals(3, permutation_2_3.getDetector().getRelationshipTemplates().size());
}
Also used : 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)

Example 3 with PatternRefinementModelId

use of org.eclipse.winery.model.ids.extensions.PatternRefinementModelId in project winery by eclipse.

the class PermutationGenerator method generatePermutations.

public Map<String, OTTopologyFragmentRefinementModel> generatePermutations(OTTopologyFragmentRefinementModel refinementModel) {
    Map<String, OTTopologyFragmentRefinementModel> permutations = new HashMap<>();
    IRepository repository = RepositoryFactory.getRepository();
    if (!checkMutability(refinementModel)) {
        throw new RuntimeException("The refinement model cannot be permuted!");
    }
    QName refinementModelQName = new QName(refinementModel.getTargetNamespace(), refinementModel.getName());
    DefinitionsChildId refinementModelId = new TopologyFragmentRefinementModelId(refinementModelQName);
    if (refinementModel instanceof OTPatternRefinementModel) {
        refinementModelId = new PatternRefinementModelId(refinementModelQName);
    }
    for (OTStringList options : refinementModel.getPermutationOptions()) {
        String permutationName = VersionSupport.getNewComponentVersionId(refinementModelId, "permutation-" + String.join("-", options.getValues()).replaceAll("_", "-"));
        QName permutationQName = new QName(refinementModel.getTargetNamespace(), permutationName);
        DefinitionsChildId permutationModelId = new TopologyFragmentRefinementModelId(permutationQName);
        if (refinementModel instanceof OTPatternRefinementModel) {
            permutationModelId = new PatternRefinementModelId(permutationQName);
        }
        try {
            // To ensure that the permutationMaps are duplicated correctly, save the permutation first
            repository.setElement(refinementModelId, refinementModel);
            repository.setElement(permutationModelId, refinementModel);
        } catch (IOException e) {
            logger.error("Error while creating permutation!", e);
            break;
        }
        OTTopologyFragmentRefinementModel permutation = repository.getElement(permutationModelId);
        permutation.setName(permutationName);
        permutations.put(permutationName, permutation);
        Map<String, String> alreadyAdded = new HashMap<>();
        for (String option : options.getValues()) {
            permutation.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getDetectorElement().getId().equals(option)).map(OTPrmMapping::getRefinementElement).filter(refinementElement -> refinementElement instanceof TNodeTemplate).map(refinementElement -> (TNodeTemplate) refinementElement).forEach(refinementElement -> {
                TNodeTemplate addedDetectorElement = alreadyAdded.containsKey(refinementElement.getId()) ? permutation.getDetector().getNodeTemplate(alreadyAdded.get(refinementElement.getId())) : addNodeFromRefinementStructureToDetector(refinementElement, permutation, alreadyAdded);
                // region outgoing relations of the currently permuted refinementElement
                ModelUtilities.getOutgoingRelationshipTemplates(permutation.getRefinementStructure(), refinementElement).forEach(relation -> {
                    // Using the permutation maps defined in the original model as we remove them in the permutation
                    refinementModel.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getRefinementElement().getId().equals(relation.getTargetElement().getRef().getId())).filter(permutationMap -> permutationMap.getDetectorElement() instanceof TNodeTemplate).forEach(permutationMap -> {
                        // to be mutated, add it the component and create the relation.
                        if (permutationMap.getDetectorElement().getId().equals(option) || options.getValues().contains(permutationMap.getDetectorElement().getId())) {
                            String alreadyAddedElement = alreadyAdded.get(relation.getTargetElement().getRef().getId());
                            TNodeTemplate target = alreadyAddedElement == null ? addNodeFromRefinementStructureToDetector((TNodeTemplate) relation.getTargetElement().getRef(), permutation, alreadyAdded) : permutation.getDetector().getNodeTemplate(alreadyAddedElement);
                            ModelUtilities.createRelationshipTemplateAndAddToTopology(addedDetectorElement, target, relation.getType(), permutation.getDetector());
                        } else if (!options.getValues().contains(permutationMap.getDetectorElement().getId())) {
                            // Else if the target is part of the detector, add the relation between the
                            // added element and the detector element.
                            // No need to check instance of again, as we filter them in line 383.
                            TNodeTemplate target = (TNodeTemplate) permutationMap.getDetectorElement();
                            ModelUtilities.createRelationshipTemplateAndAddToTopology(addedDetectorElement, target, relation.getType(), permutation.getDetector());
                        }
                    });
                });
                // region handle ingoing relations in the detector
                for (TRelationshipTemplate relation : permutation.getDetector().getRelationshipTemplates()) {
                    if (relation.getTargetElement().getRef().getId().equals(option)) {
                        Optional<OTPermutationMapping> relationTarget = permutation.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getDetectorElement().getId().equals(relation.getId())).filter(permutationMap -> permutationMap.getRefinementElement().getId().equals(refinementElement.getId())).findFirst();
                        long refinementEquivalents = permutation.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getDetectorElement().getId().equals(option)).map(OTPrmMapping::getRefinementElement).distinct().count();
                        if (relationTarget.isPresent() || refinementEquivalents == 1) {
                            ModelUtilities.createRelationshipTemplateAndAddToTopology((TNodeTemplate) relation.getSourceElement().getRef(), addedDetectorElement, relation.getType(), permutation.getDetector());
                        }
                    }
                }
            // endregion
            });
            // region remove permuted
            if (permutation.getAttributeMappings() != null) {
                permutation.getRelationMappings().removeIf(map -> map.getDetectorElement().getId().equals(option));
            }
            if (permutation.getAttributeMappings() != null) {
                permutation.getAttributeMappings().removeIf(map -> map.getDetectorElement().getId().equals(option));
            }
            if (permutation.getDeploymentArtifactMappings() != null) {
                permutation.getDeploymentArtifactMappings().removeIf(map -> map.getDetectorElement().getId().equals(option));
            }
            permutation.getPermutationMappings().removeIf(permMap -> permMap.getDetectorElement().getId().equals(option) || permMap.getDetectorElement() instanceof TRelationshipTemplate && (((TRelationshipTemplate) permMap.getDetectorElement()).getSourceElement().getRef().getId().equals(option) || ((TRelationshipTemplate) permMap.getDetectorElement()).getTargetElement().getRef().getId().equals(option)));
            permutation.getDetector().getNodeTemplateOrRelationshipTemplate().removeIf(template -> template instanceof TRelationshipTemplate && (((TRelationshipTemplate) template).getSourceElement().getRef().getId().equals(option) || ((TRelationshipTemplate) template).getTargetElement().getRef().getId().equals(option)) || template.getId().equals(option));
        // endregion
        }
        try {
            RepositoryFactory.getRepository().setElement(permutationModelId, permutation);
        } catch (IOException e) {
            logger.error("Error while saving permutation!", e);
            break;
        }
    }
    return permutations;
}
Also used : Arrays(java.util.Arrays) RefinementUtils.getAllContentMappingsForRefinementNodeWithoutDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getAllContentMappingsForRefinementNodeWithoutDetectorNode) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) RefinementUtils.isStayPlaceholder(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.isStayPlaceholder) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) RefinementUtils.addMutabilityMapping(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.addMutabilityMapping) RefinementUtils.getAllMappingsForDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getAllMappingsForDetectorNode) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Map(java.util.Map) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) RefinementUtils.noMappingExistsForRefinementNodeExeptForGivenDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.noMappingExistsForRefinementNodeExeptForGivenDetectorNode) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) RefinementUtils.getStayAndPermutationMappings(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getStayAndPermutationMappings) RefinementUtils.isStayingRefinementElement(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.isStayingRefinementElement) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) RefinementUtils.permutabilityMappingExistsForDetectorElement(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.permutabilityMappingExistsForDetectorElement) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) HasId(org.eclipse.winery.model.tosca.HasId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) RefinementUtils.permutabilityMappingExistsForRefinementNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.permutabilityMappingExistsForRefinementNode) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) Sets(org.eclipse.collections.impl.factory.Sets) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) HashMap(java.util.HashMap) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) IOException(java.io.IOException) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Example 4 with PatternRefinementModelId

use of org.eclipse.winery.model.ids.extensions.PatternRefinementModelId in project winery by eclipse.

the class PermutationGeneratorTestWithGitBackedRepository method prmWithTwoHostedOnOneTest.

@Test
void prmWithTwoHostedOnOneTest() throws Exception {
    this.setRevisionTo("origin/plain");
    OTPatternRefinementModel refinementModel = generatePrmWithTwoPatternsHostedOnAThird();
    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(6, permutations.size());
    OTTopologyFragmentRefinementModel permutation_1 = permutations.get("PrmWithComplexRelationMappings_permutation-1-w1-wip1");
    assertNotNull(permutation_1);
    assertEquals(3, permutation_1.getDetector().getNodeTemplates().size());
    assertEquals(3, permutation_1.getDetector().getRelationshipTemplates().size());
    assertTrue(permutation_1.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("11") && relation.getTargetElement().getRef().getId().equals("2")));
    assertTrue(permutation_1.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("11") && relation.getTargetElement().getRef().getId().equals("3")));
    OTTopologyFragmentRefinementModel permutation_2 = permutations.get("PrmWithComplexRelationMappings_permutation-2-w1-wip1");
    assertNotNull(permutation_2);
    assertEquals(4, permutation_2.getDetector().getNodeTemplates().size());
    assertEquals(4, permutation_2.getDetector().getRelationshipTemplates().size());
    assertTrue(permutation_2.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("1") && relation.getTargetElement().getRef().getId().equals("13")));
    assertTrue(permutation_2.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("3") && relation.getTargetElement().getRef().getId().equals("13")));
    OTTopologyFragmentRefinementModel permutation_3 = permutations.get("PrmWithComplexRelationMappings_permutation-3-w1-wip1");
    assertNotNull(permutation_3);
    assertEquals(3, permutation_3.getDetector().getNodeTemplates().size());
    assertEquals(3, permutation_3.getDetector().getRelationshipTemplates().size());
    assertTrue(permutation_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("12") && relation.getTargetElement().getRef().getId().equals("2")));
    assertTrue(permutation_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("1") && relation.getTargetElement().getRef().getId().equals("12")));
    OTTopologyFragmentRefinementModel permutation_1_2 = permutations.get("PrmWithComplexRelationMappings_permutation-1-2-w1-wip1");
    assertNotNull(permutation_1_2);
    assertEquals(4, permutation_1_2.getDetector().getNodeTemplates().size());
    assertEquals(4, permutation_1_2.getDetector().getRelationshipTemplates().size());
    assertTrue(permutation_1_2.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("11") && relation.getTargetElement().getRef().getId().equals("13")));
    assertTrue(permutation_1_2.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("11") && relation.getTargetElement().getRef().getId().equals("3")));
    assertTrue(permutation_1_2.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("3") && relation.getTargetElement().getRef().getId().equals("13")));
    OTTopologyFragmentRefinementModel permutation_1_3 = permutations.get("PrmWithComplexRelationMappings_permutation-1-3-w1-wip1");
    assertNotNull(permutation_1_3);
    assertEquals(3, permutation_1_3.getDetector().getNodeTemplates().size());
    assertEquals(3, permutation_1_3.getDetector().getRelationshipTemplates().size());
    assertTrue(permutation_1_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("11") && relation.getTargetElement().getRef().getId().equals("2")));
    assertTrue(permutation_1_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("11") && relation.getTargetElement().getRef().getId().equals("12")));
    assertTrue(permutation_1_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("12") && relation.getTargetElement().getRef().getId().equals("2")));
    OTTopologyFragmentRefinementModel permutation_2_3 = permutations.get("PrmWithComplexRelationMappings_permutation-2-3-w1-wip1");
    assertNotNull(permutation_2_3);
    assertEquals(4, permutation_2_3.getDetector().getNodeTemplates().size());
    assertEquals(4, permutation_2_3.getDetector().getRelationshipTemplates().size());
    assertTrue(permutation_2_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("1") && relation.getTargetElement().getRef().getId().equals("12")));
    assertTrue(permutation_2_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("1") && relation.getTargetElement().getRef().getId().equals("13")));
    assertTrue(permutation_2_3.getDetector().getRelationshipTemplates().removeIf(relation -> relation.getSourceElement().getRef().getId().equals("12") && relation.getTargetElement().getRef().getId().equals("13")));
}
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)

Example 5 with PatternRefinementModelId

use of org.eclipse.winery.model.ids.extensions.PatternRefinementModelId 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

PatternRefinementModelId (org.eclipse.winery.model.ids.extensions.PatternRefinementModelId)5 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)5 OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)5 Map (java.util.Map)3 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)3 Test (org.junit.jupiter.api.Test)3 PermutationHelper.addAllPermutationMappings (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addAllPermutationMappings)2 PermutationHelper.generateComplexPrmWithPatternSet (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generateComplexPrmWithPatternSet)2 PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird)2 PermutationHelper.generatePrmWithoutPermutationMaps (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithoutPermutationMaps)2 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)2 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)2 TopologyFragmentRefinementModelId (org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId)2 TestWithGitBackedRepository (org.eclipse.winery.repository.TestWithGitBackedRepository)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1