IpSecAlgorithm implements SolutionStrategy { @Override public boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData) { IRepository repository = RepositoryFactory.getRepository(); NamespaceManager namespaceManager = repository.getNamespaceManager(); Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class); TNodeTemplate[] elements = new TNodeTemplate[2]; for (int index = 0; index < 2; index++) { ComponentFinding componentFinding = inputData.getFindings().get(index); elements[index] = getVmHost(topology, componentFinding.getComponentId()); if (Objects.isNull(elements[index])) { elements[index] = topology.getNodeTemplate(componentFinding.getComponentId()); } Map<QName, TNodeType> children = ModelUtilities.getChildrenOf(elements[index].getType(), nodeTypes); Optional<Map.Entry<QName, TNodeType>> firstSecure = children.entrySet() .stream() .filter( entry -> namespaceManager.isSecureCollection(entry.getKey().getNamespaceURI()) ).findFirst(); if (firstSecure.isPresent()) { ModelUtilities.updateNodeTemplate( topology, elements[index].getId(), firstSecure.get().getKey(), firstSecure.get().getValue() ); } else { return false; } } ModelUtilities.createRelationshipTemplateAndAddToTopology(elements[1], elements[0], ToscaBaseTypes.connectsToRelationshipType, "securely_connectsTo", topology); ModelUtilities.createRelationshipTemplateAndAddToTopology(elements[0], elements[1], ToscaBaseTypes.connectsToRelationshipType, "securely_connectsTo", topology); return true; }  @Override boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData);  }
@Test public void applySolutionTest() throws Exception { this.setRevisionTo("a23f1c89c77fcde4de9fe7822532dc04e31731a0"); IpSecAlgorithm ipSecAlgorithm = new IpSecAlgorithm(); TTopologyTemplate topologyTemplate = RepositoryFactory.getRepository().getElement( new ServiceTemplateId(QName.valueOf("{http: ).getTopologyTemplate(); ArrayList<ComponentFinding> componentFindings = new ArrayList<>(); componentFindings.add(new ComponentFinding(null, "NodeTypeWithImplementation_1.0-w1-wip1")); componentFindings.add(new ComponentFinding(null, "NodeTypeWithXmlElementProperty")); SolutionInputData inputData = new SolutionInputData(); inputData.setFindings(componentFindings); ipSecAlgorithm.applySolution(topologyTemplate, inputData); assertEquals(4, topologyTemplate.getNodeTemplates().size()); assertEquals(QName.valueOf("{http: assertEquals(QName.valueOf("{http: assertEquals(5, topologyTemplate.getRelationshipTemplates().size()); TRelationshipTemplate forward = topologyTemplate.getRelationshipTemplate("replaceableNode_2-securely_connectsTo-replaceableNode_1"); assertNotNull(forward); assertEquals("replaceableNode_2", forward.getSourceElement().getRef().getId()); assertEquals("replaceableNode_1", forward.getTargetElement().getRef().getId()); TRelationshipTemplate backward = topologyTemplate.getRelationshipTemplate("replaceableNode_1-securely_connectsTo-replaceableNode_2"); assertNotNull(backward); assertEquals("replaceableNode_1", backward.getSourceElement().getRef().getId()); assertEquals("replaceableNode_2", backward.getTargetElement().getRef().getId()); }