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());
}
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"));
}
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());
}
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"));
}
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());
}
Aggregations