Search in sources :

Example 1 with ServiceTemplateComplianceRuleRuleChecker

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

the class ToscaGraphIsomorphismTest method testServiceTemplateComplianceRuleChecker.

@Test
public void testServiceTemplateComplianceRuleChecker() throws Exception {
    this.setRevisionTo("origin/plain");
    HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
    TServiceTemplate tServiceTemplate = createTServiceTemplate("ServiceTemplateTestId", TEST_TARGET_NAMESPACE);
    ComplianceRuleId crId1 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test1"));
    ComplianceRuleId crId2 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test2"));
    ComplianceRuleId crId3 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test3"));
    // create NodeType
    NodeTypeId nodeTypeIdA = createNodeTypeId("IDA");
    NodeTypeId nodeTypeIdB = createNodeTypeId("IDB");
    NodeTypeId nodeTypeIdC = createNodeTypeId("IDC");
    NodeTypeId nodeTypeIdD = createNodeTypeId("IDD");
    TNodeType nodeTypeA = createTNodeType(nodeTypeIdA);
    allEntities.put(nodeTypeIdA, nodeTypeA);
    TNodeType nodeTypeB = createTNodeType(nodeTypeIdB);
    setDerivedFrom(nodeTypeIdA, nodeTypeB);
    allEntities.put(nodeTypeIdB, nodeTypeB);
    TNodeType nodeTypeC = createTNodeType(nodeTypeIdC);
    setDerivedFrom(nodeTypeIdA, nodeTypeC);
    allEntities.put(nodeTypeIdC, nodeTypeC);
    TNodeType nodeTypeD = createTNodeType(nodeTypeIdD);
    allEntities.put(nodeTypeIdD, nodeTypeD);
    TNodeTemplate ruleOneIdentifier = createTNodeTemplate("R1_I", nodeTypeIdA);
    TNodeTemplate ruleOneRequiredStructure = createTNodeTemplate("R1_RS", nodeTypeIdB);
    TNodeTemplate ruleTwoIdentifier = createTNodeTemplate("R2_I", nodeTypeIdA);
    TNodeTemplate ruleTwoRequiredStructure = createTNodeTemplate("R2_RS", nodeTypeIdC);
    TNodeTemplate ruleThreeIdentifier = createTNodeTemplate("R3_I", nodeTypeIdA);
    TNodeTemplate ruleThreeRequiredStructure = createTNodeTemplate("R3_RS", nodeTypeIdD);
    TNodeTemplate serviceTemplateTopology = createTNodeTemplate("ST", nodeTypeIdB);
    // satisfied
    OTComplianceRule ruleOne = createTComplianceRule(crId1);
    ruleOne.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleOneIdentifier), newArrayList()));
    ruleOne.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleOneRequiredStructure), newArrayList()));
    allEntities.put(crId1, ruleOne);
    // unsatisfied
    OTComplianceRule ruleTwo = createTComplianceRule(crId2);
    ruleTwo.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleTwoIdentifier), newArrayList()));
    ruleTwo.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleTwoRequiredStructure), newArrayList()));
    allEntities.put(crId2, ruleTwo);
    // invalid rule
    OTComplianceRule ruleThree = createTComplianceRule(crId3);
    ruleThree.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleThreeIdentifier), newArrayList()));
    ruleThree.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleThreeRequiredStructure), newArrayList()));
    allEntities.put(crId3, ruleThree);
    tServiceTemplate.setTopologyTemplate(createTTopologyTemplate(Arrays.asList(serviceTemplateTopology), newArrayList()));
    persist(allEntities);
    ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(tServiceTemplate);
    assertEquals(3, checker.getRuleIds(tServiceTemplate).stream().count());
    assertEquals(3, checker.getRuleIds(tServiceTemplate).stream().filter(id -> id.getQName().getLocalPart().matches("test1|test2|test3")).count());
    ServiceTemplateCheckingResult serviceTemplateCheckingResult = checker.checkComplianceRules();
    assertEquals(1, serviceTemplateCheckingResult.getSatisfied().size());
    assertEquals(1, serviceTemplateCheckingResult.getUnsatisfied().size());
    assertEquals(1, serviceTemplateCheckingResult.getException().size());
    JAXBContext jaxbContext = null;
    try {
        jaxbContext = JAXBContext.newInstance(ServiceTemplateCheckingResult.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        StringWriter sw = new StringWriter();
        jaxbMarshaller.marshal(serviceTemplateCheckingResult, sw);
        System.out.println(sw.toString());
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}
Also used : ServiceTemplateCheckingResult(org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult) Marshaller(javax.xml.bind.Marshaller) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) JAXBContext(javax.xml.bind.JAXBContext) ToscaModelHelper.createTNodeType(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType) TNodeType(org.eclipse.winery.model.tosca.TNodeType) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) StringWriter(java.io.StringWriter) ToscaModelHelper.createNodeTypeId(org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ToscaModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceTemplateComplianceRuleRuleChecker

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

the class ServiceTemplateResource method complianceChecking.

@Path("constraintchecking")
@Produces(MediaType.APPLICATION_XML)
@POST
public Response complianceChecking(@Context UriInfo uriInfo) throws JAXBException {
    ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(this.getServiceTemplate());
    ServiceTemplateCheckingResult serviceTemplateCheckingResult = checker.checkComplianceRules();
    return Response.ok().entity(serviceTemplateCheckingResult.toXMLString()).build();
}
Also used : ServiceTemplateCheckingResult(org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) POST(javax.ws.rs.POST)

Example 3 with ServiceTemplateComplianceRuleRuleChecker

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

the class TOSCAGraphIsomorphismTest method testServiceTemplateAndComplianceRuleAssociation.

@Test
public void testServiceTemplateAndComplianceRuleAssociation() throws IOException {
    HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
    String dirABC = "/ABC";
    String dirBCD = "/BCD";
    ServiceTemplateId stId = new ServiceTemplateId(new QName(TEST_TARGET_NAMESPACE + dirABC + dirBCD, "test1"));
    TServiceTemplate tServiceTemplate = createTServiceTemplate("ServiceTemplateTestId", TEST_TARGET_NAMESPACE + dirABC + dirBCD);
    allEntities.put(stId, tServiceTemplate);
    ComplianceRuleId crId1 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test1"));
    ComplianceRuleId crId2 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test2"));
    ComplianceRuleId crId3 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test3"));
    ComplianceRuleId crId4 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirBCD, "test4"));
    TComplianceRule ruleOne = createTComplianceRule(crId1);
    allEntities.put(crId1, ruleOne);
    TComplianceRule ruleTwo = createTComplianceRule(crId2);
    allEntities.put(crId2, ruleTwo);
    TComplianceRule ruleThree = createTComplianceRule(crId3);
    allEntities.put(crId3, ruleThree);
    TComplianceRule ruleFour = createTComplianceRule(crId4);
    allEntities.put(crId4, ruleFour);
    persist(allEntities);
    ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(tServiceTemplate);
    List<ComplianceRuleId> ruleIds = checker.getRuleIds(tServiceTemplate);
    assertTrue(ruleIds.stream().filter(id -> id.equals(crId1)).findFirst().isPresent());
    assertTrue(ruleIds.stream().filter(id -> id.equals(crId2)).findFirst().isPresent());
    assertTrue(ruleIds.stream().filter(id -> id.equals(crId3)).findFirst().isPresent());
    assertFalse(ruleIds.stream().filter(id -> id.equals(crId4)).findFirst().isPresent());
}
Also used : Arrays(java.util.Arrays) GraphMapping(org.jgrapht.GraphMapping) StringUtils(org.apache.commons.lang3.StringUtils) TOSCAModelHelper.createTNodeType(org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TOSCAModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TOSCANode(org.eclipse.winery.compliance.model.TOSCANode) Map(java.util.Map) After(org.junit.After) Path(java.nio.file.Path) FileBasedRepositoryConfiguration(org.eclipse.winery.repository.configuration.FileBasedRepositoryConfiguration) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) TOSCAEdgeFactory(org.eclipse.winery.compliance.model.TOSCAEdgeFactory) ComplianceRuleId(org.eclipse.winery.common.ids.definitions.ComplianceRuleId) ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) TOSCAModelHelper.createNodeTypeId(org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId) TOSCAModelHelper.createTTopologyTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTTopologyTemplate) TNodeType(org.eclipse.winery.model.tosca.TNodeType) JAXBException(javax.xml.bind.JAXBException) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) List(java.util.List) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Assert.assertFalse(org.junit.Assert.assertFalse) TComplianceRule(org.eclipse.winery.model.tosca.TComplianceRule) QName(javax.xml.namespace.QName) FilebasedRepository(org.eclipse.winery.repository.backend.filebased.FilebasedRepository) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) Marshaller(javax.xml.bind.Marshaller) ServiceTemplateCheckingResult(org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TOSCAModelHelper.createTComplianceRule(org.eclipse.winery.compliance.TOSCAModelHelper.createTComplianceRule) ArrayList(java.util.ArrayList) TOSCAEdge(org.eclipse.winery.compliance.model.TOSCAEdge) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TOSCAIsomorphismMatcher(org.eclipse.winery.compliance.matching.TOSCAIsomorphismMatcher) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) StringWriter(java.io.StringWriter) ComplianceCheckingException(org.eclipse.winery.compliance.checking.ComplianceCheckingException) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) TOSCAModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTServiceTemplate) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) TEST_TARGET_NAMESPACE(org.eclipse.winery.compliance.TOSCAModelHelper.TEST_TARGET_NAMESPACE) TOSCAComplianceRuleMatcher(org.eclipse.winery.compliance.matching.TOSCAComplianceRuleMatcher) Paths(java.nio.file.Paths) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TOSCAGraph(org.eclipse.winery.compliance.model.TOSCAGraph) TOSCAModelHelper.setDerivedFrom(org.eclipse.winery.compliance.TOSCAModelHelper.setDerivedFrom) Assert.assertEquals(org.junit.Assert.assertEquals) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ComplianceRuleId(org.eclipse.winery.common.ids.definitions.ComplianceRuleId) TComplianceRule(org.eclipse.winery.model.tosca.TComplianceRule) TOSCAModelHelper.createTComplianceRule(org.eclipse.winery.compliance.TOSCAModelHelper.createTComplianceRule) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TOSCAModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTServiceTemplate) Test(org.junit.Test)

Example 4 with ServiceTemplateComplianceRuleRuleChecker

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

the class TOSCAGraphIsomorphismTest method testServiceTemplateComplianceRuleChecker.

@Test
public void testServiceTemplateComplianceRuleChecker() throws IOException {
    HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
    TServiceTemplate tServiceTemplate = createTServiceTemplate("ServiceTemplateTestId", TEST_TARGET_NAMESPACE);
    ComplianceRuleId crId1 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test1"));
    ComplianceRuleId crId2 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test2"));
    ComplianceRuleId crId3 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test3"));
    // create NodeType
    NodeTypeId nodeTypeIdA = createNodeTypeId("IDA");
    NodeTypeId nodeTypeIdB = createNodeTypeId("IDB");
    NodeTypeId nodeTypeIdC = createNodeTypeId("IDC");
    NodeTypeId nodeTypeIdD = createNodeTypeId("IDD");
    TNodeType nodeTypeA = createTNodeType(nodeTypeIdA);
    allEntities.put(nodeTypeIdA, nodeTypeA);
    TNodeType nodeTypeB = createTNodeType(nodeTypeIdB);
    setDerivedFrom(nodeTypeIdA, nodeTypeB);
    allEntities.put(nodeTypeIdB, nodeTypeB);
    TNodeType nodeTypeC = createTNodeType(nodeTypeIdC);
    setDerivedFrom(nodeTypeIdA, nodeTypeC);
    allEntities.put(nodeTypeIdC, nodeTypeC);
    TNodeType nodeTypeD = createTNodeType(nodeTypeIdD);
    allEntities.put(nodeTypeIdD, nodeTypeD);
    TNodeTemplate ruleOneIdentifier = createTNodeTemplate("R1_I", nodeTypeIdA);
    TNodeTemplate ruleOneRequiredStructure = createTNodeTemplate("R1_RS", nodeTypeIdB);
    TNodeTemplate ruleTwoIdentifier = createTNodeTemplate("R2_I", nodeTypeIdA);
    TNodeTemplate ruleTwoRequiredStructure = createTNodeTemplate("R2_RS", nodeTypeIdC);
    TNodeTemplate ruleThreeIdentifier = createTNodeTemplate("R3_I", nodeTypeIdA);
    TNodeTemplate ruleThreeRequiredStructure = createTNodeTemplate("R3_RS", nodeTypeIdD);
    TNodeTemplate serviceTemplateTopology = createTNodeTemplate("ST", nodeTypeIdB);
    // satisfied
    TComplianceRule ruleOne = createTComplianceRule(crId1);
    ruleOne.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleOneIdentifier), newArrayList()));
    ruleOne.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleOneRequiredStructure), newArrayList()));
    allEntities.put(crId1, ruleOne);
    // unsatisfied
    TComplianceRule ruleTwo = createTComplianceRule(crId2);
    ruleTwo.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleTwoIdentifier), newArrayList()));
    ruleTwo.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleTwoRequiredStructure), newArrayList()));
    allEntities.put(crId2, ruleTwo);
    // invalid rule
    TComplianceRule ruleThree = createTComplianceRule(crId3);
    ruleThree.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleThreeIdentifier), newArrayList()));
    ruleThree.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleThreeRequiredStructure), newArrayList()));
    allEntities.put(crId3, ruleThree);
    tServiceTemplate.setTopologyTemplate(createTTopologyTemplate(Arrays.asList(serviceTemplateTopology), newArrayList()));
    persist(allEntities);
    ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(tServiceTemplate);
    assertEquals(3, checker.getRuleIds(tServiceTemplate).stream().count());
    assertEquals(3, checker.getRuleIds(tServiceTemplate).stream().filter(id -> id.getQName().getLocalPart().matches("test1|test2|test3")).count());
    ServiceTemplateCheckingResult serviceTemplateCheckingResult = checker.checkComplianceRules();
    assertEquals(1, serviceTemplateCheckingResult.getSatisfied().size());
    assertEquals(1, serviceTemplateCheckingResult.getUnsatisfied().size());
    assertEquals(1, serviceTemplateCheckingResult.getException().size());
    JAXBContext jaxbContext = null;
    try {
        jaxbContext = JAXBContext.newInstance(ServiceTemplateCheckingResult.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        StringWriter sw = new StringWriter();
        jaxbMarshaller.marshal(serviceTemplateCheckingResult, sw);
        System.out.println(sw.toString());
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}
Also used : ServiceTemplateCheckingResult(org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult) Marshaller(javax.xml.bind.Marshaller) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) JAXBContext(javax.xml.bind.JAXBContext) TOSCAModelHelper.createTNodeType(org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeType) TNodeType(org.eclipse.winery.model.tosca.TNodeType) ComplianceRuleId(org.eclipse.winery.common.ids.definitions.ComplianceRuleId) StringWriter(java.io.StringWriter) TComplianceRule(org.eclipse.winery.model.tosca.TComplianceRule) TOSCAModelHelper.createTComplianceRule(org.eclipse.winery.compliance.TOSCAModelHelper.createTComplianceRule) 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) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TOSCAModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTServiceTemplate) Test(org.junit.Test)

Example 5 with ServiceTemplateComplianceRuleRuleChecker

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

the class ToscaGraphIsomorphismTest method testServiceTemplateAndComplianceRuleAssociation.

@Test
public void testServiceTemplateAndComplianceRuleAssociation() throws IOException {
    HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
    String dirABC = "/ABC";
    String dirBCD = "/BCD";
    ServiceTemplateId stId = new ServiceTemplateId(new QName(TEST_TARGET_NAMESPACE + dirABC + dirBCD, "test1"));
    TServiceTemplate tServiceTemplate = createTServiceTemplate("ServiceTemplateTestId", TEST_TARGET_NAMESPACE + dirABC + dirBCD);
    allEntities.put(stId, tServiceTemplate);
    ComplianceRuleId crId1 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test1"));
    ComplianceRuleId crId2 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test2"));
    ComplianceRuleId crId3 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test3"));
    ComplianceRuleId crId4 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirBCD, "test4"));
    OTComplianceRule ruleOne = createTComplianceRule(crId1);
    allEntities.put(crId1, ruleOne);
    OTComplianceRule ruleTwo = createTComplianceRule(crId2);
    allEntities.put(crId2, ruleTwo);
    OTComplianceRule ruleThree = createTComplianceRule(crId3);
    allEntities.put(crId3, ruleThree);
    OTComplianceRule ruleFour = createTComplianceRule(crId4);
    allEntities.put(crId4, ruleFour);
    persist(allEntities);
    ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(tServiceTemplate);
    List<ComplianceRuleId> ruleIds = checker.getRuleIds(tServiceTemplate);
    assertTrue(ruleIds.stream().anyMatch(id -> id.equals(crId1)));
    assertTrue(ruleIds.stream().anyMatch(id -> id.equals(crId2)));
    assertTrue(ruleIds.stream().anyMatch(id -> id.equals(crId3)));
    assertFalse(ruleIds.stream().anyMatch(id -> id.equals(crId4)));
}
Also used : Arrays(java.util.Arrays) ToscaModelHelper.createTNodeType(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType) ToscaModelHelper.createTOSCANode(org.eclipse.winery.compliance.ToscaModelHelper.createTOSCANode) Marshaller(javax.xml.bind.Marshaller) GraphMapping(org.jgrapht.GraphMapping) ServiceTemplateCheckingResult(org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) HashMap(java.util.HashMap) ToscaModelHelper.createTTopologyTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTTopologyTemplate) ToscaModelHelper.setDerivedFrom(org.eclipse.winery.compliance.ToscaModelHelper.setDerivedFrom) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) ToscaComplianceRuleMatcher(org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ToscaModelHelper.createTOSCANodeOnlyTypes(org.eclipse.winery.compliance.ToscaModelHelper.createTOSCANodeOnlyTypes) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ToscaModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate) ToscaModelHelper.addEdge(org.eclipse.winery.compliance.ToscaModelHelper.addEdge) JAXBContext(javax.xml.bind.JAXBContext) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) ToscaModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate) Iterator(java.util.Iterator) StringWriter(java.io.StringWriter) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType) JAXBException(javax.xml.bind.JAXBException) ToscaModelHelper.createTOSCANodeOnlyProperties(org.eclipse.winery.compliance.ToscaModelHelper.createTOSCANodeOnlyProperties) Test(org.junit.jupiter.api.Test) ToscaModelHelper.createTComplianceRule(org.eclipse.winery.compliance.ToscaModelHelper.createTComplianceRule) List(java.util.List) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) ToscaModelHelper.createNodeTypeId(org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) QName(javax.xml.namespace.QName) TEST_TARGET_NAMESPACE(org.eclipse.winery.compliance.ToscaModelHelper.TEST_TARGET_NAMESPACE) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ToscaModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceTemplateCheckingResult (org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult)5 ServiceTemplateComplianceRuleRuleChecker (org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker)5 StringWriter (java.io.StringWriter)4 HashMap (java.util.HashMap)4 JAXBContext (javax.xml.bind.JAXBContext)4 JAXBException (javax.xml.bind.JAXBException)4 Marshaller (javax.xml.bind.Marshaller)4 QName (javax.xml.namespace.QName)4 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4 TNodeType (org.eclipse.winery.model.tosca.TNodeType)4 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 ComplianceRuleId (org.eclipse.winery.common.ids.definitions.ComplianceRuleId)2 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)2