Search in sources :

Example 1 with ToscaComplianceRuleMatcher

use of org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher in project winery by eclipse.

the class ToscaGraphIsomorphismTest method testTOSCAComplianceRuleMatcher.

@Test
public void testTOSCAComplianceRuleMatcher() throws IOException {
    // TNodeTemplateMatching
    // by TNodeType
    HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
    NodeTypeId nodeTypeIdAbstractA = createNodeTypeId("AbstractA");
    allEntities.put(nodeTypeIdAbstractA, createTNodeType(nodeTypeIdAbstractA));
    NodeTypeId nodeTypeIdAbstractB = createNodeTypeId("AbstractB");
    allEntities.put(nodeTypeIdAbstractB, createTNodeType(nodeTypeIdAbstractB));
    NodeTypeId nodeTypeIdActualA = createNodeTypeId("ActualA");
    TNodeType actualA = createTNodeType(nodeTypeIdActualA);
    setDerivedFrom(nodeTypeIdAbstractA, actualA);
    allEntities.put(nodeTypeIdActualA, actualA);
    NodeTypeId nodeTypeIdActualB = createNodeTypeId("ActualB");
    TNodeType actualB = createTNodeType(nodeTypeIdActualB);
    setDerivedFrom(nodeTypeIdAbstractB, actualB);
    allEntities.put(nodeTypeIdActualB, actualB);
    NodeTypeId nodeTypeIdActualB2 = createNodeTypeId("ActualB2");
    TNodeType actualB2 = createTNodeType(nodeTypeIdActualB2);
    setDerivedFrom(nodeTypeIdAbstractB, actualB2);
    allEntities.put(nodeTypeIdActualB2, actualB2);
    persist(allEntities);
    TNodeTemplate nodeTemplate1 = createTNodeTemplate("01", nodeTypeIdAbstractA);
    TNodeTemplate nodeTemplate2 = createTNodeTemplate("02", nodeTypeIdAbstractB);
    TNodeTemplate nodeTemplate3 = createTNodeTemplate("03", nodeTypeIdActualA);
    TNodeTemplate nodeTemplate4 = createTNodeTemplate("04", nodeTypeIdActualB);
    TNodeTemplate nodeTemplate5 = createTNodeTemplate("05", nodeTypeIdActualB);
    TNodeTemplate nodeTemplate6 = createTNodeTemplate("06", nodeTypeIdActualB2);
    ToscaComplianceRuleMatcher matcher = new ToscaComplianceRuleMatcher();
    // same type
    assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate1), createTOSCANodeOnlyTypes(nodeTemplate1)));
    // "01" is supertype of "03" -> match
    assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate1), createTOSCANodeOnlyTypes(nodeTemplate3)));
    // "03" is subtype of "01" -> match
    assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate3), createTOSCANodeOnlyTypes(nodeTemplate1)));
    // different types
    assertFalse(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate4), createTOSCANodeOnlyTypes(nodeTemplate3)));
    // different types
    assertFalse(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate3), createTOSCANodeOnlyTypes(nodeTemplate2)));
    // same type
    assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate5), createTOSCANodeOnlyTypes(nodeTemplate4)));
    // different types derived from same type
    assertFalse(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate5), createTOSCANodeOnlyTypes(nodeTemplate6)));
    // by TEntityTemplate.Properties
    ToscaModelPropertiesBuilder bldrLeft = new ToscaModelPropertiesBuilder(TEST_TARGET_NAMESPACE, "TestProperties");
    ToscaModelPropertiesBuilder bldrRight = new ToscaModelPropertiesBuilder(TEST_TARGET_NAMESPACE, "TestProperties");
    // test by values
    // test simple matching
    bldrLeft.addProperty("A", "Something");
    bldrRight.addProperty("A", "Something");
    assertTrue(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
    bldrRight.addProperty("A", "SomeOtherThing");
    assertFalse(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
    // testRegex
    bldrLeft.addProperty("A", ".*");
    assertTrue(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
    // test by property set
    // left subset of right
    bldrLeft.addProperty("B", ".*");
    bldrRight.addProperty("B", ".*");
    bldrRight.addProperty("C", ".*");
    assertTrue(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
    // other way round
    assertFalse(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrRight), createTOSCANodeOnlyProperties(bldrLeft)));
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ToscaModelHelper.createNodeTypeId(org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) ToscaComplianceRuleMatcher(org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate) ToscaModelHelper.createTNodeType(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)1 ToscaModelHelper.createNodeTypeId (org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId)1 ToscaModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate)1 ToscaModelHelper.createTNodeType (org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType)1 ToscaComplianceRuleMatcher (org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TNodeType (org.eclipse.winery.model.tosca.TNodeType)1 Test (org.junit.jupiter.api.Test)1