test_class.file: org.eclipse.winery.model.adaptation/src/test/java/org/eclipse/winery/model/adaptation/problemsolving/algorithms/IpSecAlgorithmTest.java
test_class.identifier: IpSecAlgorithmTest
test_class.superclass: extends TestWithGitBackedRepository
test_case.body: @Test
      public void applySolutionTest() throws Exception {
          this.setRevisionTo("a23f1c89c77fcde4de9fe7822532dc04e31731a0");
          IpSecAlgorithm ipSecAlgorithm = new IpSecAlgorithm();
  
          TTopologyTemplate topologyTemplate = RepositoryFactory.getRepository().getElement(
              new ServiceTemplateId(QName.valueOf("{http://plain.winery.opentosca.org/servicetemplates}ServiceTemplateWithIpSecProblem_w1-wip1"))
          ).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://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_1").getType());
          assertEquals(QName.valueOf("{http://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_2").getType());
          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());
      }
test_case.class_method_signature: IpSecAlgorithmTest.applySolutionTest()
test_case.full_signature: @Test public void applySolutionTest()
test_case.identifier: applySolutionTest
test_case.invocations: setRevisionTo getTopologyTemplate getElement getRepository valueOf add add setFindings applySolution assertEquals size getNodeTemplates assertEquals valueOf getType getNodeTemplate assertEquals valueOf getType getNodeTemplate assertEquals size getRelationshipTemplates getRelationshipTemplate assertNotNull assertEquals getId getRef getSourceElement assertEquals getId getRef getTargetElement getRelationshipTemplate assertNotNull assertEquals getId getRef getSourceElement assertEquals getId getRef getTargetElement
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void applySolutionTest()
focal_class.file: org.eclipse.winery.model.adaptation/src/main/java/org/eclipse/winery/model/adaptation/problemsolving/algorithms/IpSecAlgorithm.java
focal_class.identifier: IpSecAlgorithm
focal_class.interfaces: implements SolutionStrategy
focal_class.class_method_signature: IpSecAlgorithm.applySolution(TTopologyTemplate topology, SolutionInputData inputData)
focal_class.full_signature: @Override public boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData)
focal_class.identifier: applySolution
focal_class.modifiers: @Override public
focal_class.parameters: (TTopologyTemplate topology, SolutionInputData inputData)
focal_class.return: boolean
focal_class.signature: boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData)
focal_class.class_method_signature: IpSecAlgorithm.getVmHost(TTopologyTemplate topology, String nodeTemplateId)
focal_class.full_signature: private TNodeTemplate getVmHost(TTopologyTemplate topology, String nodeTemplateId)
focal_class.identifier: getVmHost
focal_class.modifiers: private
focal_class.parameters: (TTopologyTemplate topology, String nodeTemplateId)
focal_class.return: TNodeTemplate
focal_class.signature: TNodeTemplate getVmHost(TTopologyTemplate topology, String nodeTemplateId)
focal_method.body: @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);
  
              // simply use the first element
              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;
              }
          }
  
          // forward connection
          ModelUtilities.createRelationshipTemplateAndAddToTopology(elements[1], elements[0],
              ToscaBaseTypes.connectsToRelationshipType, "securely_connectsTo", topology);
          // backward connection
          ModelUtilities.createRelationshipTemplateAndAddToTopology(elements[0], elements[1],
              ToscaBaseTypes.connectsToRelationshipType, "securely_connectsTo", topology);
  
          return true;
      }
focal_method.class_method_signature: IpSecAlgorithm.applySolution(TTopologyTemplate topology, SolutionInputData inputData)
focal_method.full_signature: @Override public boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData)
focal_method.identifier: applySolution
focal_method.invocations: getRepository getNamespaceManager getQNameToElementMapping get getFindings getVmHost getComponentId isNull getNodeTemplate getComponentId getChildrenOf getType findFirst filter stream entrySet isSecureCollection getNamespaceURI getKey isPresent updateNodeTemplate getId getKey get getValue get createRelationshipTemplateAndAddToTopology createRelationshipTemplateAndAddToTopology
focal_method.modifiers: @Override public
focal_method.parameters: (TTopologyTemplate topology, SolutionInputData inputData)
focal_method.return: boolean
focal_method.signature: boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData)