Search in sources :

Example 76 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class SubstitutionTestWithGitBackedRepository method substituteNodeTemplateWithServiceTemplate.

@Test
public void substituteNodeTemplateWithServiceTemplate() throws Exception {
    this.setRevisionTo("origin/plain");
    Substitution substitution = new Substitution();
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId("http://plain.winery.org/pattern-based/servicetemplates", "ServiceTemplateContainingAbstractNodeTemplates_w2-wip1", false);
    ServiceTemplateId substitutedServiceTemplate = substitution.substituteTopologyOfServiceTemplate(serviceTemplateId);
    TServiceTemplate element = repo.getElement(substitutedServiceTemplate);
    assertNotNull(element.getTopologyTemplate());
    assertNotNull(element.getTopologyTemplate().getNodeTemplates());
    assertEquals(8, element.getTopologyTemplate().getNodeTemplates().size());
    assertNotNull(element.getTopologyTemplate().getRelationshipTemplates());
    assertEquals(7, element.getTopologyTemplate().getRelationshipTemplates().size());
    assertEquals("NodeTypeWithThreeReqCapPairsCoveringAllReqCapVariants_w1-wip1", element.getTopologyTemplate().getRelationshipTemplate("con_5").getTargetElement().getRef().getId());
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 77 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class SubstitutionUtilsTestWithGitBackedRepository method containsPatternArguments.

private static Stream<Arguments> containsPatternArguments() {
    ServiceTemplateId st1 = new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithTwoNodeTemplates_w1-wip2", false);
    ServiceTemplateId st2 = new ServiceTemplateId("http://plain.winery.org/pattern-based/servicetemplates", "ServiceTemplateContainingAbstractNodeTemplates_w2-wip1", false);
    ServiceTemplateId st3 = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates", "NodeTemplateAnnotedWithPattern_w1-wip1", false);
    return Stream.of(Arguments.of(st1, false, "expecting no patterns in the topology"), Arguments.of(st2, true, "expecting patterns in the topology"), Arguments.of(st3, true, "expecting patterns as annotation in the topology"));
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId)

Example 78 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class PatternRefinementTestWithGitBackedRepository method refineTopologyWithPatternsAnnotatedAsPolicies.

@Test
void refineTopologyWithPatternsAnnotatedAsPolicies() throws Exception {
    this.setRevisionTo("origin/plain");
    List<RefinementCandidate> myCandidates = new ArrayList<>();
    PatternRefinement refinement = new PatternRefinement((candidates, refinementServiceTemplate, currentTopology) -> {
        myCandidates.addAll(candidates);
        return null;
    });
    ServiceTemplateId serviceTemplateId = refinement.refineServiceTemplate(new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates", "NodeTemplateAnnotedWithPattern_w1-wip2", false));
    assertEquals(1, myCandidates.size());
    assertEquals("PolicyAnnotatedNtWithTwoKvProps_w1-wip1", myCandidates.get(0).getRefinementModel().getName());
}
Also used : RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 79 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class PatternRefinementTestWithGitBackedRepository method refineTopologyWithPatternsAnnotatedAsPoliciesInMultipleInstances.

@Test
void refineTopologyWithPatternsAnnotatedAsPoliciesInMultipleInstances() throws Exception {
    this.setRevisionTo("origin/plain");
    List<RefinementCandidate> myCandidates = new ArrayList<>();
    PatternRefinement refinement = new PatternRefinement((candidates, refinementServiceTemplate, currentTopology) -> {
        myCandidates.addAll(candidates);
        return null;
    });
    // This ST contains two similar sub-graphs where one only defines a policy type whereas the second one defines a specific template as well.
    ServiceTemplateId serviceTemplateId = refinement.refineServiceTemplate(new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates", "NodeTemplateAnnotedWithPattern_w1-wip3", false));
    assertEquals(3, myCandidates.size());
    long countForRefinementModelsWithPolicyTypeOnly = myCandidates.stream().filter(refinementCandidate -> refinementCandidate.getRefinementModel().getName().equals("PolicyAnnotatedNtWithTwoKvProps_w1-wip1")).count();
    assertEquals(2, countForRefinementModelsWithPolicyTypeOnly);
    List<RefinementCandidate> moreSpecificPrm = myCandidates.stream().filter(refinementCandidate -> refinementCandidate.getRefinementModel().getName().equals("PolicyAnnotatedNtWithTwoKvProps_w1-wip2")).collect(Collectors.toList());
    assertEquals(1, moreSpecificPrm.size());
    ArrayList<String> nodeIdsToBeReplaced = moreSpecificPrm.get(0).getNodeIdsToBeReplaced();
    assertEquals(2, nodeIdsToBeReplaced.size());
    assertTrue(nodeIdsToBeReplaced.contains("NodeTypeWithTwoKVProperties_3"));
    assertTrue(nodeIdsToBeReplaced.contains("Infrastructure-As-A-Service_w1_3"));
}
Also used : Test(org.junit.jupiter.api.Test) List(java.util.List) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors(java.util.stream.Collectors) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 80 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class ThreatModelingTestWithGitBackedRepository method testForPresentSVNFinServiceTemplate.

@Test
public void testForPresentSVNFinServiceTemplate() throws Exception {
    this.setRevisionTo("origin/plain");
    ThreatModelingUtils tmu = new ThreatModelingUtils(repository);
    try {
        tmu.setupThreatModelingTypes();
        ThreatCreationApiData newThreat = new ThreatCreationApiData();
        newThreat.setName("MyThreat");
        newThreat.setDescription("My Description");
        newThreat.setStride("Spoofing");
        newThreat.setSeverity("Low");
        tmu.createThreatAndMitigationTemplates(newThreat);
    } catch (Exception e) {
        return;
    }
    TNodeType svnfGroupA = new TNodeType.Builder("MyGroupA").setTargetNamespace(demoNamespace).setAbstract(true).setDerivedFrom(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE)).build();
    TNodeType svnfGroupB = new TNodeType.Builder("MyGroupB").setTargetNamespace(demoNamespace).setAbstract(true).setDerivedFrom(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE)).build();
    TTopologyTemplate emptyTopology = new TTopologyTemplate.Builder().build();
    TPolicy boundaryThreat = new TPolicy.Builder(QName.valueOf(ThreatModelingConstants.MITIGATION_POLICY_ID)).setPolicyRef(new QName(ThreatModelingConstants.THREATMODELING_NAMESPACE, "MITIGATE_MyThreat")).setName("MITIGATE_MyThreat").build();
    TBoundaryDefinitions boundaryDefinitions = new TBoundaryDefinitions.Builder().addPolicy(boundaryThreat).build();
    TServiceTemplate networkServiceA = new TServiceTemplate.Builder("NetworkServiceA", emptyTopology).setTargetNamespace(demoNamespace).setBoundaryDefinitions(boundaryDefinitions).setSubstitutableNodeType(new QName(demoNamespace, "MyGroupA")).build();
    TServiceTemplate networkServiceB = new TServiceTemplate.Builder("NetworkServiceB", emptyTopology).setTargetNamespace(demoNamespace).setBoundaryDefinitions(boundaryDefinitions).setSubstitutableNodeType(new QName(demoNamespace, "MyGroupB")).build();
    TNodeType myNodeType = new TNodeType.Builder("MyNode").setTargetNamespace(demoNamespace).build();
    TPolicy nodeTemplateThreat = new TPolicy.Builder(QName.valueOf(ThreatModelingConstants.THREAT_POLICY_ID)).setPolicyRef(new QName(ThreatModelingConstants.THREATMODELING_NAMESPACE, "MyThreat")).setName("MyThreat").build();
    TNodeTemplate myNodeTemplate = new TNodeTemplate.Builder("myNodeTemplate", new QName(demoNamespace, "MyNode")).addPolicy(nodeTemplateThreat).build();
    TTopologyTemplate myTopology = new TTopologyTemplate.Builder().addNodeTemplate(myNodeTemplate).build();
    TServiceTemplate myService = new TServiceTemplate.Builder("MyService", myTopology).setTargetNamespace(demoNamespace).build();
    repository.setElement(new ServiceTemplateId(demoNamespace, "NetworkServiceA", false), networkServiceA);
    repository.setElement(new ServiceTemplateId(demoNamespace, "NetworkServiceB", false), networkServiceB);
    repository.setElement(new NodeTypeId(demoNamespace, "MyGroupA", false), svnfGroupA);
    repository.setElement(new NodeTypeId(demoNamespace, "MyGroupB", false), svnfGroupB);
    repository.setElement(new NodeTypeId(demoNamespace, "MyNode", false), myNodeType);
    repository.setElement(new ServiceTemplateId(demoNamespace, "MyService", false), myService);
    ThreatModeling tm = new ThreatModeling(new ServiceTemplateId(demoNamespace, "MyService", false), repository);
    ThreatAssessment assessment = tm.getServiceTemplateThreats();
    Threat asessedThreat = assessment.getThreats().get(new QName(ThreatModelingConstants.THREATMODELING_NAMESPACE, "MyThreat"));
    assertEquals("MyThreat", asessedThreat.getTemplateName());
    assertTrue(asessedThreat.getMitigations().contains(new QName(demoNamespace, "MyGroupA")));
    assertTrue(asessedThreat.getMitigations().contains(new QName(demoNamespace, "MyGroupB")));
    assertTrue(assessment.getSVNFs().isEmpty());
}
Also used : QName(javax.xml.namespace.QName) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13