Splitting { public boolean checkValidTopology(TTopologyTemplate topologyTemplate) { Map<TNodeTemplate, Set<TNodeTemplate>> transitiveAndDirectSuccessors = computeTransitiveClosure(topologyTemplate); for (TNodeTemplate node : getNodeTemplatesWithoutIncomingHostedOnRelationships(topologyTemplate)) { if (!ModelUtilities.getTargetLabel(node).isPresent()) { return false; } } for (TNodeTemplate node : transitiveAndDirectSuccessors.keySet()) { if (!transitiveAndDirectSuccessors.get(node).isEmpty()) { for (TNodeTemplate successor : transitiveAndDirectSuccessors.get(node)) { if (ModelUtilities.getTargetLabel(successor).isPresent() && ModelUtilities.getTargetLabel(node).isPresent() && !ModelUtilities.getTargetLabel(node).get().equalsIgnoreCase(ModelUtilities.getTargetLabel(successor).get())) { return false; } } } } return true; }  ServiceTemplateId splitTopologyOfServiceTemplate(ServiceTemplateId id); ServiceTemplateId matchTopologyOfServiceTemplate(ServiceTemplateId id); ServiceTemplateId composeServiceTemplates(String composedSolutionServiceTemplateID, List<ServiceTemplateId> serviceTemplateIds); void resolveTopologyTemplate(ServiceTemplateId serviceTemplateId); boolean checkValidTopology(TTopologyTemplate topologyTemplate); TTopologyTemplate split(TTopologyTemplate topologyTemplate); Map<String, List<TTopologyTemplate>> getHostingInjectionOptions(TTopologyTemplate topologyTemplate); Map<String, List<TTopologyTemplate>> getHostingMatchingOptionsWithDefaultLabeling(TTopologyTemplate topologyTemplate); TTopologyTemplate hostMatchingWithDefaultHostSelection(TTopologyTemplate topologyTemplate); TTopologyTemplate connectionMatchingWithDefaultConnectorSelection(TTopologyTemplate topologyTemplate); TTopologyTemplate injectNodeTemplates(TTopologyTemplate topologyTemplate, Map<String, TTopologyTemplate> injectNodes, InjectRemoval removal); Map<String, List<TTopologyTemplate>> getConnectionInjectionOptions(TTopologyTemplate topologyTemplate); TTopologyTemplate injectConnectionNodeTemplates(TTopologyTemplate topologyTemplate, Map<String, TTopologyTemplate> selectedConnectionFragments); Map<TNodeTemplate, Set<TNodeTemplate>> computeTransitiveClosure(TTopologyTemplate topologyTemplate); Map<TRequirement, String> getOpenRequirementsAndMatchingBasisCapabilityTypeNames(TTopologyTemplate topologyTemplate); List<TRequirement> getOpenRequirements(TTopologyTemplate topologyTemplate); TRelationshipType getBasisRelationshipType(QName relationshipTypeQName);  }
@Test public void testcheckValidationTopologyForAValidTopology() throws Exception { TNodeTemplate nt1 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1")) .findAny() .get(); ModelUtilities.setTargetLabel(nt1, "1"); TNodeTemplate nt2 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1_3")) .findAny() .get(); ModelUtilities.setTargetLabel(nt2, "1"); TNodeTemplate nt3 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1_2")) .findAny() .get(); ModelUtilities.setTargetLabel(nt3, "1"); assertEquals(true, splitting.checkValidTopology(topologyTemplate)); }
@Test public void testcheckValidationTopologyForAInValidTopology() throws Exception { TNodeTemplate nt1 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1")) .findAny() .get(); ModelUtilities.setTargetLabel(nt1, "1"); TNodeTemplate nt2 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1_4")) .findAny() .get(); ModelUtilities.setTargetLabel(nt2, "2"); TNodeTemplate nt3 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1_2")) .findAny() .get(); ModelUtilities.setTargetLabel(nt3, "1"); assertEquals(false, splitting.checkValidTopology(topologyTemplate)); }
@Test public void testcheckValidationTopologyForAValidTopologyWithSuccessorHasEmptyTargetLabel() throws Exception { TNodeTemplate nt1 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1")) .findAny() .get(); ModelUtilities.setTargetLabel(nt1, "1"); TNodeTemplate nt3 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1_2")) .findAny() .get(); ModelUtilities.setTargetLabel(nt3, "2"); assertEquals(true, splitting.checkValidTopology(topologyTemplate)); }
@Test public void testcheckValidationTopologyForAInValidTopologyWithFirstNodesHasEmptyTargetLabel() throws Exception { TNodeTemplate nt3 = topologyTemplate.getNodeTemplateOrRelationshipTemplate() .stream() .filter(x -> x instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .filter(nt -> nt.getId().equals("NT1_2")) .findAny() .get(); ModelUtilities.setTargetLabel(nt3, "2"); assertEquals(false, splitting.checkValidTopology(topologyTemplate)); }