Search in sources :

Example 6 with ComplianceRuleChecker

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

the class ComplianceRuleCheckerTests method validRule_identifierInRequired_findsOne.

@Test
public void validRule_identifierInRequired_findsOne() throws Exception {
    ComplianceRuleChecker checker = new ComplianceRuleChecker(null, null, null);
    checker.setToCheckTemplate(topologyTemplateToSearchIn);
    checker.setIdentifierTemplate(identifier);
    checker.setRequiredStructureTemplate(requiredStructure);
    List<GraphMapping> violatingMappings = checker.checkComplianceRule();
    assertEquals(1, violatingMappings.size());
    ToscaNode identifierNode1 = checker.getIdentifierGraph().getNode("01");
    ToscaNode identifierNode2 = checker.getIdentifierGraph().getNode("02");
    ToscaEdge identifierEdge = checker.getIdentifierGraph().getEdge(identifierNode1, identifierNode2);
    GraphMapping violatingMapping = violatingMappings.stream().findFirst().get();
    assertNotNull(violatingMapping);
    Map<ToscaNode, ToscaNode> resultMap = checker.getSubGraphMappingAsMap(violatingMapping, checker.getIdentifierGraph());
    assertTrue(resultMap.get(identifierNode1).getId().matches("05"));
    assertTrue(resultMap.get(identifierNode2).getId().matches("06"));
    assertTrue(((ToscaEdge) violatingMapping.getEdgeCorrespondence(identifierEdge, false)).getId().matches("3"));
}
Also used : ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.jupiter.api.Test)

Example 7 with ComplianceRuleChecker

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

the class ComplianceRuleCheckerTests method blacklist.

@Test
public void blacklist() throws Exception {
    ComplianceRuleChecker checker = new ComplianceRuleChecker(null, null, null);
    checker.setToCheckTemplate(topologyTemplateToSearchIn);
    checker.setRequiredStructureTemplate(null);
    checker.setIdentifierTemplate(identifier);
    List<GraphMapping> blacklistResult = checker.checkComplianceRule();
    assertEquals(2, blacklistResult.size());
}
Also used : ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.jupiter.api.Test)

Example 8 with ComplianceRuleChecker

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

the class ComplianceRuleCheckerTests method nullTemplateToCheck.

@Test
public void nullTemplateToCheck() {
    ComplianceRuleChecker checker = new ComplianceRuleChecker(null, null, null);
    ComplianceCheckingException expected = null;
    try {
        checker.checkComplianceRule();
    } catch (ComplianceCheckingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertTrue(StringUtils.equals(ComplianceCheckingException.NO_TEMPLATE_TO_CHECK, expected.getMessage()));
}
Also used : ComplianceCheckingException(org.eclipse.winery.compliance.checking.ComplianceCheckingException) ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) Test(org.junit.jupiter.api.Test)

Example 9 with ComplianceRuleChecker

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

the class ComplianceRuleCheckerTests method completeRule_noMapping.

@Test
public void completeRule_noMapping() {
    ComplianceRuleChecker checker = new ComplianceRuleChecker(null, null, null);
    checker.setToCheckTemplate(topologyTemplateToSearchIn);
    // test completeRule
    // invalid Rule: identifier and required structure have no mapping
    checker.setIdentifierTemplate(unrelatedTopology);
    checker.setRequiredStructureTemplate(requiredStructure);
    ComplianceCheckingException expected = null;
    try {
        checker.checkComplianceRule();
    } catch (ComplianceCheckingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertTrue(StringUtils.equals(ComplianceCheckingException.IDENTIFIER_NOT_IN_REQUIREDSTRUCTURE, expected.getMessage()));
}
Also used : ComplianceCheckingException(org.eclipse.winery.compliance.checking.ComplianceCheckingException) ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) Test(org.junit.jupiter.api.Test)

Example 10 with ComplianceRuleChecker

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

the class ComplianceRuleCheckerTests method completeRule.

@Test
public void completeRule() {
    ComplianceRuleChecker checker = new ComplianceRuleChecker(null, null, null);
    checker.setToCheckTemplate(topologyTemplateToSearchIn);
    checker.setIdentifierTemplate(unrelatedTopology);
    checker.setRequiredStructureTemplate(requiredStructure);
    ComplianceCheckingException expected = null;
    try {
        checker.checkComplianceRule();
    } catch (ComplianceCheckingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertTrue(StringUtils.equals(ComplianceCheckingException.IDENTIFIER_NOT_IN_REQUIREDSTRUCTURE, expected.getMessage()));
}
Also used : ComplianceCheckingException(org.eclipse.winery.compliance.checking.ComplianceCheckingException) ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) Test(org.junit.jupiter.api.Test)

Aggregations

ComplianceRuleChecker (org.eclipse.winery.compliance.checking.ComplianceRuleChecker)10 Test (org.junit.jupiter.api.Test)8 ComplianceCheckingException (org.eclipse.winery.compliance.checking.ComplianceCheckingException)6 GraphMapping (org.jgrapht.GraphMapping)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)1 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)1 TOSCAModelHelper.createNodeTypeId (org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId)1 TOSCAModelHelper.createTComplianceRule (org.eclipse.winery.compliance.TOSCAModelHelper.createTComplianceRule)1 TOSCAModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate)1 TOSCAModelHelper.createTNodeType (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeType)1 TOSCAModelHelper.createTTopologyTemplate (org.eclipse.winery.compliance.TOSCAModelHelper.createTTopologyTemplate)1 TOSCAEdge (org.eclipse.winery.compliance.model.TOSCAEdge)1 TOSCANode (org.eclipse.winery.compliance.model.TOSCANode)1 TComplianceRule (org.eclipse.winery.model.tosca.TComplianceRule)1 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)1