Search in sources :

Example 6 with OTComplianceRule

use of org.eclipse.winery.model.tosca.extensions.OTComplianceRule 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

OTComplianceRule (org.eclipse.winery.model.tosca.extensions.OTComplianceRule)6 ComplianceRuleId (org.eclipse.winery.model.ids.extensions.ComplianceRuleId)5 QName (javax.xml.namespace.QName)4 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)4 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 TNodeType (org.eclipse.winery.model.tosca.TNodeType)3 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)3 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBException (javax.xml.bind.JAXBException)2 Marshaller (javax.xml.bind.Marshaller)2 ToscaModelHelper.createNodeTypeId (org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId)2 ToscaModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate)2 ToscaModelHelper.createTNodeType (org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType)2 ToscaModelHelper.createTServiceTemplate (org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate)2 ServiceTemplateCheckingResult (org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult)2 ServiceTemplateComplianceRuleRuleChecker (org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker)2 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)2