Search in sources :

Example 6 with TNodeType

use of org.eclipse.winery.model.tosca.TNodeType in project winery by eclipse.

the class GeneratorTest method testNoParams.

@Test
public void testNoParams() throws Exception {
    TInterface tinterface = new TInterface();
    tinterface.setName("TestNoParams");
    TOperation opIn = new TOperation();
    opIn.setName("OpNoParams");
    tinterface.getOperation().add(opIn);
    TNodeType nodeType = new TNodeType();
    nodeType.setName("test");
    nodeType.setTargetNamespace("http://asd.com");
    Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", WORKING_DIR.toFile());
    Path generateProject = gen.generateProject();
    System.out.println(generateProject);
}
Also used : Path(java.nio.file.Path) TInterface(org.eclipse.winery.model.tosca.TInterface) TOperation(org.eclipse.winery.model.tosca.TOperation) URL(java.net.URL) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Test(org.junit.Test)

Example 7 with TNodeType

use of org.eclipse.winery.model.tosca.TNodeType in project winery by eclipse.

the class TOSCAGraphIsomorphismTest method testTOSCAComplianceRuleChecker.

@Test
public void testTOSCAComplianceRuleChecker() throws IOException, ComplianceCheckingException {
    HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
    TOSCAModelPropertiesBuilder bldr = new TOSCAModelPropertiesBuilder(TEST_TARGET_NAMESPACE, "MyProperties");
    bldr.addProperty("key1", "value1");
    bldr.addProperty("key2", "value2");
    // create NodeTypes A B
    String idNodeTypeA = "idA";
    TNodeType nodeTypeA = TOSCAModelHelper.createTNodeType(idNodeTypeA, TEST_TARGET_NAMESPACE);
    String idNodeTypeB = "idB";
    TNodeType nodeTypeB = TOSCAModelHelper.createTNodeType(idNodeTypeB, TEST_TARGET_NAMESPACE);
    String idNodeTypeC = "idC";
    TNodeType nodeTypeC = TOSCAModelHelper.createTNodeType(idNodeTypeC, TEST_TARGET_NAMESPACE);
    NodeTypeId idA = TOSCAModelHelper.createNodeTypeId(idNodeTypeA);
    NodeTypeId idB = TOSCAModelHelper.createNodeTypeId(idNodeTypeB);
    NodeTypeId idC = TOSCAModelHelper.createNodeTypeId(idNodeTypeC);
    allEntities.put(idA, nodeTypeA);
    allEntities.put(idB, nodeTypeB);
    allEntities.put(idC, nodeTypeC);
    // createRelationshipTypes
    String relTypeIdAString = "adRelA";
    RelationshipTypeId relTypeIdA = new RelationshipTypeId(new QName(TEST_TARGET_NAMESPACE, relTypeIdAString));
    TRelationshipType relTypeA = TOSCAModelHelper.createTRelationshipType(relTypeIdAString, TEST_TARGET_NAMESPACE);
    allEntities.put(relTypeIdA, relTypeA);
    // createNodeTemplates
    TNodeTemplate nodeTemplate1 = TOSCAModelHelper.createTNodeTemplate("01");
    nodeTemplate1.setType(idA.getQName());
    TNodeTemplate nodeTemplate2 = TOSCAModelHelper.createTNodeTemplate("02");
    nodeTemplate2.setType(idB.getQName());
    TNodeTemplate nodeTemplate3 = TOSCAModelHelper.createTNodeTemplate("03");
    nodeTemplate3.setType(idA.getQName());
    nodeTemplate3.setProperties(bldr.build());
    TNodeTemplate nodeTemplate4 = TOSCAModelHelper.createTNodeTemplate("04");
    nodeTemplate4.setType(idB.getQName());
    TNodeTemplate nodeTemplate5 = TOSCAModelHelper.createTNodeTemplate("05");
    nodeTemplate5.setType(idA.getQName());
    TNodeTemplate nodeTemplate6 = TOSCAModelHelper.createTNodeTemplate("06");
    nodeTemplate6.setType(idB.getQName());
    TNodeTemplate nodeTemplate7 = TOSCAModelHelper.createTNodeTemplate("07");
    nodeTemplate7.setType(idA.getQName());
    nodeTemplate7.setProperties(bldr.build());
    TNodeTemplate nodeTemplate8 = TOSCAModelHelper.createTNodeTemplate("08");
    nodeTemplate8.setType(idB.getQName());
    TNodeTemplate nodeTemplate9 = TOSCAModelHelper.createTNodeTemplate("CompletelyUnrelated");
    nodeTemplate9.setType(idC.getQName());
    // create RelationshipTemplates
    TRelationshipTemplate relTemplate1 = TOSCAModelHelper.createTRelationshipTemplate("1");
    relTemplate1.setSourceNodeTemplate(nodeTemplate1);
    relTemplate1.setTargetNodeTemplate(nodeTemplate2);
    relTemplate1.setType(relTypeIdA.getQName());
    TRelationshipTemplate relTemplate2 = TOSCAModelHelper.createTRelationshipTemplate("2");
    relTemplate2.setSourceNodeTemplate(nodeTemplate3);
    relTemplate2.setTargetNodeTemplate(nodeTemplate4);
    relTemplate2.setType(relTypeIdA.getQName());
    TRelationshipTemplate relTemplate3 = TOSCAModelHelper.createTRelationshipTemplate("3");
    relTemplate3.setSourceNodeTemplate(nodeTemplate5);
    relTemplate3.setTargetNodeTemplate(nodeTemplate6);
    relTemplate3.setType(relTypeIdA.getQName());
    TRelationshipTemplate relTemplate4 = TOSCAModelHelper.createTRelationshipTemplate("4");
    relTemplate4.setSourceNodeTemplate(nodeTemplate7);
    relTemplate4.setTargetNodeTemplate(nodeTemplate8);
    relTemplate4.setType(relTypeIdA.getQName());
    // create TopologyTemplates
    List<TNodeTemplate> nodeTemplates = new ArrayList<>();
    List<TRelationshipTemplate> relationshipTemplates = new ArrayList<>();
    // create identifier
    nodeTemplates.add(nodeTemplate1);
    nodeTemplates.add(nodeTemplate2);
    relationshipTemplates.add(relTemplate1);
    TTopologyTemplate identifier = TOSCAModelHelper.createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    identifier.setNodeTemplates(nodeTemplates);
    identifier.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    // create required structure
    nodeTemplates.add(nodeTemplate3);
    nodeTemplates.add(nodeTemplate4);
    relationshipTemplates.add(relTemplate2);
    TTopologyTemplate requiredStructure = TOSCAModelHelper.createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    requiredStructure.setNodeTemplates(nodeTemplates);
    requiredStructure.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    // create topologyToSearchIn
    nodeTemplates.add(nodeTemplate5);
    nodeTemplates.add(nodeTemplate6);
    nodeTemplates.add(nodeTemplate7);
    nodeTemplates.add(nodeTemplate8);
    relationshipTemplates.add(relTemplate3);
    relationshipTemplates.add(relTemplate4);
    TTopologyTemplate topologyTemplateToSearchIn = TOSCAModelHelper.createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    topologyTemplateToSearchIn.setNodeTemplates(nodeTemplates);
    topologyTemplateToSearchIn.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    // create unrelated topology
    nodeTemplates.add(nodeTemplate9);
    TTopologyTemplate unrelatedTopology = TOSCAModelHelper.createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    unrelatedTopology.setNodeTemplates(nodeTemplates);
    unrelatedTopology.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    persist(allEntities);
    // **************** //
    // Test starts here //
    // **************** //
    ComplianceRuleChecker checker;
    // test null topologyTemplateToCheck
    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()));
    checker.setToCheckTemplate(topologyTemplateToSearchIn);
    // test empty rule
    expected = null;
    try {
        checker.checkComplianceRule();
    } catch (ComplianceCheckingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertTrue(StringUtils.equals(ComplianceCheckingException.EMPTY_COMPLIANCE_RULE, expected.getMessage()));
    // test Whitelist
    checker.setRequiredStructureTemplate(requiredStructure);
    expected = null;
    try {
        checker.checkComplianceRule();
    } catch (ComplianceCheckingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertTrue(StringUtils.equals(ComplianceCheckingException.WHITELISTING_NOT_YET_IMPLEMENTED, expected.getMessage()));
    // test blacklist
    checker.setRequiredStructureTemplate(null);
    checker.setIdentifierTemplate(identifier);
    List<GraphMapping> blacklistResult = checker.checkComplianceRule();
    assertEquals(2, blacklistResult.size());
    // test completeRule
    // invalid Rule: identifier and required structure have no mapping
    checker.setIdentifierTemplate(unrelatedTopology);
    checker.setRequiredStructureTemplate(requiredStructure);
    expected = null;
    try {
        checker.checkComplianceRule();
    } catch (ComplianceCheckingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertTrue(StringUtils.equals(ComplianceCheckingException.IDENTIFIER_NOT_IN_REQUIREDSTRUCTURE, expected.getMessage()));
    // valid Rule: identifier in required structure
    // finds one violation
    checker.setIdentifierTemplate(identifier);
    checker.setRequiredStructureTemplate(requiredStructure);
    List<GraphMapping> violatingMappings = checker.checkComplianceRule();
    assertEquals(1, violatingMappings.size());
    // check the mapping.
    // must contain nodesTemplates 5 & 6 and relTemplate3
    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"));
    // finds no violation
    checker.setRequiredStructureTemplate(identifier);
    assertEquals(0, checker.checkComplianceRule().size());
    TComplianceRule rule = new TComplianceRule();
    rule.setName("test");
    rule.setTargetNamespace(TEST_TARGET_NAMESPACE);
    rule.setIdentifier(identifier);
    rule.setRequiredStructure(requiredStructure);
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) TOSCAEdge(org.eclipse.winery.compliance.model.TOSCAEdge) TComplianceRule(org.eclipse.winery.model.tosca.TComplianceRule) TOSCAModelHelper.createTComplianceRule(org.eclipse.winery.compliance.TOSCAModelHelper.createTComplianceRule) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TOSCAModelHelper.createTTopologyTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTTopologyTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TOSCANode(org.eclipse.winery.compliance.model.TOSCANode) TOSCAModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) QName(javax.xml.namespace.QName) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) TOSCAModelHelper.createTNodeType(org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeType) TNodeType(org.eclipse.winery.model.tosca.TNodeType) ComplianceCheckingException(org.eclipse.winery.compliance.checking.ComplianceCheckingException) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TOSCAModelHelper.createNodeTypeId(org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.Test)

Example 8 with TNodeType

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

Example 9 with TNodeType

use of org.eclipse.winery.model.tosca.TNodeType 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 10 with TNodeType

use of org.eclipse.winery.model.tosca.TNodeType in project winery by eclipse.

the class GeneratorTest method testInOut.

@Test
public void testInOut() throws Exception {
    TInterface tinterface = new TInterface();
    tinterface.setName("http://www.example.org/interfaces/lifecycle");
    TOperation op1 = new TOperation();
    op1.setName("Op1InOut");
    tinterface.getOperation().add(op1);
    TOperation.InputParameters op1InputParameters = new TOperation.InputParameters();
    TParameter op1ip1 = new TParameter();
    op1ip1.setName("op1ip1");
    op1ip1.setType("xs:string");
    op1InputParameters.getInputParameter().add(op1ip1);
    TParameter op1ip2 = new TParameter();
    op1ip2.setName("op1ip2");
    op1ip2.setType("xs:string");
    op1InputParameters.getInputParameter().add(op1ip2);
    op1.setInputParameters(op1InputParameters);
    TOperation.OutputParameters op1OutputParameters = new TOperation.OutputParameters();
    TParameter op1op1 = new TParameter();
    op1op1.setName("op1op1");
    op1op1.setType("xs:string");
    op1OutputParameters.getOutputParameter().add(op1op1);
    TParameter op1op2 = new TParameter();
    op1op2.setName("op1op2");
    op1op1.setType("xs:string");
    op1OutputParameters.getOutputParameter().add(op1op2);
    op1.setOutputParameters(op1OutputParameters);
    TNodeType nodeType = new TNodeType();
    nodeType.setName("test");
    nodeType.setTargetNamespace("http://asd.com");
    Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", WORKING_DIR.toFile());
    Path generateProject = gen.generateProject();
    System.out.println(generateProject);
}
Also used : Path(java.nio.file.Path) TInterface(org.eclipse.winery.model.tosca.TInterface) TOperation(org.eclipse.winery.model.tosca.TOperation) TParameter(org.eclipse.winery.model.tosca.TParameter) URL(java.net.URL) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Test(org.junit.Test)

Aggregations

TNodeType (org.eclipse.winery.model.tosca.TNodeType)10 Test (org.junit.Test)6 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)4 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)4 TInterface (org.eclipse.winery.model.tosca.TInterface)4 TOperation (org.eclipse.winery.model.tosca.TOperation)4 URL (java.net.URL)3 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 TOSCAModelHelper.createNodeTypeId (org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId)3 TOSCAModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate)3 TOSCAModelHelper.createTNodeType (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeType)3 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)3 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)2 NodeTypeImplementationId (org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId)2 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)2