Search in sources :

Example 1 with TOSCAComplianceRuleMatcher

use of org.eclipse.winery.compliance.matching.TOSCAComplianceRuleMatcher in project winery by eclipse.

the class ComplianceRuleChecker method findMatches.

public List<GraphMapping> findMatches(TOSCAGraph queryGraph, TOSCAGraph searchInGraph) {
    TOSCAIsomorphismMatcher matcher = new TOSCAIsomorphismMatcher();
    Iterator<GraphMapping<TOSCANode, TOSCAEdge>> iterator = matcher.findMatches(queryGraph, searchInGraph, new TOSCAComplianceRuleMatcher());
    return convertToList(iterator);
}
Also used : TOSCAIsomorphismMatcher(org.eclipse.winery.compliance.matching.TOSCAIsomorphismMatcher) TOSCAComplianceRuleMatcher(org.eclipse.winery.compliance.matching.TOSCAComplianceRuleMatcher) GraphMapping(org.jgrapht.GraphMapping)

Example 2 with TOSCAComplianceRuleMatcher

use of org.eclipse.winery.compliance.matching.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 = TOSCAModelHelper.createNodeTypeId("AbstractA");
    allEntities.put(nodeTypeIdAbstractA, TOSCAModelHelper.createTNodeType(nodeTypeIdAbstractA));
    NodeTypeId nodeTypeIdAbstractB = TOSCAModelHelper.createNodeTypeId("AbstractB");
    allEntities.put(nodeTypeIdAbstractB, TOSCAModelHelper.createTNodeType(nodeTypeIdAbstractB));
    NodeTypeId nodeTypeIdActualA = TOSCAModelHelper.createNodeTypeId("ActualA");
    TNodeType actualA = TOSCAModelHelper.createTNodeType(nodeTypeIdActualA);
    TOSCAModelHelper.setDerivedFrom(nodeTypeIdAbstractA, actualA);
    allEntities.put(nodeTypeIdActualA, actualA);
    NodeTypeId nodeTypeIdActualB = TOSCAModelHelper.createNodeTypeId("ActualB");
    TNodeType actualB = TOSCAModelHelper.createTNodeType(nodeTypeIdActualB);
    TOSCAModelHelper.setDerivedFrom(nodeTypeIdAbstractB, actualB);
    allEntities.put(nodeTypeIdActualB, actualB);
    NodeTypeId nodeTypeIdActualB2 = TOSCAModelHelper.createNodeTypeId("ActualB2");
    TNodeType actualB2 = TOSCAModelHelper.createTNodeType(nodeTypeIdActualB2);
    TOSCAModelHelper.setDerivedFrom(nodeTypeIdAbstractB, actualB2);
    allEntities.put(nodeTypeIdActualB2, actualB2);
    persist(allEntities);
    TNodeTemplate nodeTemplate1 = TOSCAModelHelper.createTNodeTemplate("01", nodeTypeIdAbstractA);
    TNodeTemplate nodeTemplate2 = TOSCAModelHelper.createTNodeTemplate("02", nodeTypeIdAbstractB);
    TNodeTemplate nodeTemplate3 = TOSCAModelHelper.createTNodeTemplate("03", nodeTypeIdActualA);
    TNodeTemplate nodeTemplate4 = TOSCAModelHelper.createTNodeTemplate("04", nodeTypeIdActualB);
    TNodeTemplate nodeTemplate5 = TOSCAModelHelper.createTNodeTemplate("05", nodeTypeIdActualB);
    TNodeTemplate nodeTemplate6 = TOSCAModelHelper.createTNodeTemplate("06", nodeTypeIdActualB2);
    TOSCAComplianceRuleMatcher matcher = new TOSCAComplianceRuleMatcher();
    // same type
    assertTrue(matcher.isTEntityTypesCompatible(TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate1), TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate1)));
    // "01" is supertype of "03" -> match
    assertTrue(matcher.isTEntityTypesCompatible(TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate1), TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate3)));
    // "03" is subtype of "01" -> match
    assertTrue(matcher.isTEntityTypesCompatible(TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate3), TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate1)));
    // different types
    assertFalse(matcher.isTEntityTypesCompatible(TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate4), TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate3)));
    // different types
    assertFalse(matcher.isTEntityTypesCompatible(TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate3), TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate2)));
    // same type
    assertTrue(matcher.isTEntityTypesCompatible(TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate5), TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate4)));
    // different types derived from same type
    assertFalse(matcher.isTEntityTypesCompatible(TOSCAModelHelper.createTOSCANodeOnlyTypes(nodeTemplate5), TOSCAModelHelper.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(TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrLeft), TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrRight)));
    bldrRight.addProperty("A", "SomeOtherThing");
    assertFalse(matcher.isPropertiesCompatible(TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrLeft), TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrRight)));
    // testRegex
    bldrLeft.addProperty("A", ".*");
    assertTrue(matcher.isPropertiesCompatible(TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrLeft), TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrRight)));
    // test by property set
    // left subset of right
    bldrLeft.addProperty("B", ".*");
    bldrRight.addProperty("B", ".*");
    bldrRight.addProperty("C", ".*");
    assertTrue(matcher.isPropertiesCompatible(TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrLeft), TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrRight)));
    // other way round
    assertFalse(matcher.isPropertiesCompatible(TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrRight), TOSCAModelHelper.createTOSCANodeOnlyProperties(bldrLeft)));
// String repositoryURI = "http://localhost:8080/winery";
// 
// boolean USE_PROXY = false;
// 
// IWineryRepositoryClient client = new WineryRepositoryClient(USE_PROXY);
// 
// client.addRepository(repositoryURI);
// 
// TTopologyTemplate testTemplate = client.getTopologyTemplate(new QName( "http://opentosca.org/compliancerules","TestTemplate"));
// 
// TNodeTemplate.Policies leftPolicies;
// TPolicy policy;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.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.common.ids.definitions.NodeTypeId) TOSCAModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TOSCAComplianceRuleMatcher(org.eclipse.winery.compliance.matching.TOSCAComplianceRuleMatcher) TOSCAModelHelper.createTNodeType(org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeType) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Test(org.junit.Test)

Aggregations

TOSCAComplianceRuleMatcher (org.eclipse.winery.compliance.matching.TOSCAComplianceRuleMatcher)2 HashMap (java.util.HashMap)1 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)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 TOSCAIsomorphismMatcher (org.eclipse.winery.compliance.matching.TOSCAIsomorphismMatcher)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 GraphMapping (org.jgrapht.GraphMapping)1 Test (org.junit.Test)1