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);
}
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;
}
Aggregations