Search in sources :

Example 1 with OTTestRefinementModel

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

use of org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel in project winery by eclipse.

the class PatternDetectionUtilsTest method toPdrms.

@Test
public void toPdrms() {
    List<OTRefinementModel> refinementModels = new ArrayList<>();
    refinementModels.add(new OTTestRefinementModel());
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    refinementModels.add(new OTTopologyFragmentRefinementModel());
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    OTPatternRefinementModel prm = new OTPatternRefinementModel();
    refinementModels.add(prm);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    prm.setIsPdrm(true);
    refinementModels.add(prm);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 1);
    prm.setIsPdrm(false);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
}
Also used : OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArrayList(java.util.ArrayList) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 3 with OTTestRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel in project winery by eclipse.

the class TestRefinementTest method applyRefinementTest.

@Test
public void applyRefinementTest() {
    // region *** topology ***
    TNodeTemplate tomcat = new TNodeTemplate();
    tomcat.setId("tomcat");
    tomcat.setType("{ns}tomcat");
    TNodeTemplate webShop = new TNodeTemplate();
    webShop.setId("webShop");
    webShop.setType("{ns}webShop");
    TNodeTemplate database = new TNodeTemplate();
    database.setId("database");
    database.setType("{ns}database");
    TRelationshipTemplate webShopOnTomcat = new TRelationshipTemplate();
    webShopOnTomcat.setSourceNodeTemplate(webShop);
    webShopOnTomcat.setTargetNodeTemplate(tomcat);
    webShopOnTomcat.setType("{ns}hostedOn");
    TRelationshipTemplate webShopToDatabase = new TRelationshipTemplate();
    webShopToDatabase.setTargetNodeTemplate(database);
    webShopToDatabase.setSourceNodeTemplate(webShop);
    webShopToDatabase.setType("{ns}connectsTo");
    TTopologyTemplate topologyTemplate = new TTopologyTemplate.Builder().addNodeTemplate(tomcat).addNodeTemplate(webShop).addNodeTemplate(database).addRelationshipTemplate(webShopOnTomcat).addRelationshipTemplate(webShopToDatabase).build();
    // endregion
    // region *** refinement model ***
    TNodeTemplate mySqlConnectorTest = new TNodeTemplate();
    mySqlConnectorTest.setId("sqlConnectorTest");
    mySqlConnectorTest.setType("{ns}sqlConnectorTest");
    TTopologyTemplate refinementTopology = new TTopologyTemplate.Builder().addNodeTemplate(mySqlConnectorTest).build();
    OTRelationMapping testHostedOn = new OTRelationMapping(new OTRelationMapping.Builder().setDirection(OTRelationDirection.OUTGOING).setRelationType(QName.valueOf("{ns}hostedOn")).setRefinementElement(mySqlConnectorTest).setDetectorElement(tomcat));
    OTRelationMapping testConnectsTo = new OTRelationMapping(new OTRelationMapping.Builder().setDirection(OTRelationDirection.OUTGOING).setRelationType(QName.valueOf("{ns}connectsTo")).setRefinementElement(mySqlConnectorTest).setDetectorElement(database));
    OTRelationMapping testIngoingRelationTest = new OTRelationMapping(new OTRelationMapping.Builder().setDirection(OTRelationDirection.INGOING).setRelationType(QName.valueOf("{ns}ingoingTest")).setRefinementElement(mySqlConnectorTest).setDetectorElement(webShop));
    List<OTRelationMapping> relationMappings = new ArrayList<>();
    relationMappings.add(testHostedOn);
    relationMappings.add(testConnectsTo);
    relationMappings.add(testIngoingRelationTest);
    OTTestRefinementModel testRefinementModel = new OTTestRefinementModel(new OTTestRefinementModel.Builder().setTestFragment(refinementTopology).setDetector(topologyTemplate).setRelationMappings(relationMappings));
    // endregion
    ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topologyTemplate);
    ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(testRefinementModel.getDetector());
    ToscaIsomorphismMatcher matcher = new ToscaIsomorphismMatcher();
    Iterator<GraphMapping<ToscaNode, ToscaEdge>> mappings = matcher.findMatches(detectorGraph, topologyGraph, new ToscaTypeMatcher());
    GraphMapping<ToscaNode, ToscaEdge> mapping = mappings.next();
    RefinementCandidate refinementCandidate = new RefinementCandidate(testRefinementModel, mapping, detectorGraph, 1);
    TestRefinement testRefinement = new TestRefinement();
    testRefinement.applyRefinement(refinementCandidate, topologyTemplate);
    // region *** assertions ***
    assertEquals(4, topologyTemplate.getNodeTemplates().size());
    assertEquals(5, topologyTemplate.getRelationshipTemplates().size());
    TRelationshipTemplate mimicTestHostedOnTomcat = topologyTemplate.getRelationshipTemplate("mimicTest-hostedOn");
    assertNotNull(mimicTestHostedOnTomcat);
    assertEquals("tomcat", mimicTestHostedOnTomcat.getTargetElement().getRef().getId());
    assertEquals("sqlConnectorTest", mimicTestHostedOnTomcat.getSourceElement().getRef().getId());
    TRelationshipTemplate mimicTestConnectsToDatabase = topologyTemplate.getRelationshipTemplate("mimicTest-connectsTo");
    assertNotNull(mimicTestConnectsToDatabase);
    assertEquals("database", mimicTestConnectsToDatabase.getTargetElement().getRef().getId());
    assertEquals("sqlConnectorTest", mimicTestConnectsToDatabase.getSourceElement().getRef().getId());
    TRelationshipTemplate mimicTestTestIngoingConnection = topologyTemplate.getRelationshipTemplate("mimicTest-ingoingTest");
    assertNotNull(mimicTestTestIngoingConnection);
    assertEquals("webShop", mimicTestTestIngoingConnection.getSourceElement().getRef().getId());
    assertEquals("sqlConnectorTest", mimicTestTestIngoingConnection.getTargetElement().getRef().getId());
// endregion
}
Also used : ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaTypeMatcher(org.eclipse.winery.topologygraph.matching.ToscaTypeMatcher) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.jupiter.api.Test)

Aggregations

OTTestRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel)3 ArrayList (java.util.ArrayList)2 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)2 OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)2 RefinementCandidate (org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate)1 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)1 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)1 DataTypeId (org.eclipse.winery.model.ids.definitions.DataTypeId)1 InterfaceTypeId (org.eclipse.winery.model.ids.definitions.InterfaceTypeId)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)1 PolicyTemplateId (org.eclipse.winery.model.ids.definitions.PolicyTemplateId)1 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)1 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)1 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)1 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)1 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)1 XSDImportId (org.eclipse.winery.model.ids.definitions.imports.XSDImportId)1 ComplianceRuleId (org.eclipse.winery.model.ids.extensions.ComplianceRuleId)1