Merge branch 'recursive-orch'
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / ebb / loader / ServiceEBBLoaderTest.java
index a5ecf36..2d41a24 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (c) 2020 Nokia
  * ================================================================================
+ * Modifications Copyright (c) 2021 Orange
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -30,7 +32,11 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mock;
+import org.onap.aai.domain.yang.ComposedResource;
+import org.onap.aai.domain.yang.ComposedResources;
+import org.onap.aai.domain.yang.RelatedToProperty;
 import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
 import org.onap.aai.domain.yang.RelationshipList;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.aaiclient.client.aai.entities.Relationships;
@@ -39,6 +45,7 @@ import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
 import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException;
 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
 import org.onap.so.client.exception.ExceptionBuilder;
@@ -171,10 +178,10 @@ public class ServiceEBBLoaderTest extends BaseTaskTest {
     @Test
     public void foundRelatedTest() {
         List<Resource> resourceList = new ArrayList<>();
-        resourceList.add(new Resource(WorkflowType.PNF, "model customization id", false));
-        resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false));
-        resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false));
-        resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false));
+        resourceList.add(new Resource(WorkflowType.PNF, "model customization id", false, null));
+        resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false, null));
+        resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false, null));
+        resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false, null));
 
         assertTrue(serviceEBBLoader.foundRelated(resourceList));
     }
@@ -182,10 +189,10 @@ public class ServiceEBBLoaderTest extends BaseTaskTest {
     @Test
     public void containsWorkflowTypeTest() {
         List<Resource> resourceList = new ArrayList<>();
-        resourceList.add(new Resource(WorkflowType.PNF, "resource id", false));
-        resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false));
-        resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false));
-        resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false));
+        resourceList.add(new Resource(WorkflowType.PNF, "resource id", false, null));
+        resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false, null));
+        resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false, null));
+        resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false, null));
 
         assertTrue(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.PNF));
         assertTrue(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.VNF));
@@ -204,13 +211,16 @@ public class ServiceEBBLoaderTest extends BaseTaskTest {
         serviceInstanceAAI.setServiceInstanceId(resourceId);
 
         org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = setServiceInstance();
-        setGenericVnf();
+        GenericVnf genericVnf = setGenericVnf();
         setVfModule(true);
         setVolumeGroup();
         setL3Network();
         setCollection();
         setConfiguration();
 
+        org.onap.aai.domain.yang.GenericVnf genericVnfAai = new org.onap.aai.domain.yang.GenericVnf();
+        genericVnfAai.setModelCustomizationId(genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid());
+
         Configuration config = new Configuration();
         config.setConfigurationId("testConfigurationId2");
         serviceInstance.getConfigurations().add(config);
@@ -233,13 +243,18 @@ public class ServiceEBBLoaderTest extends BaseTaskTest {
         aaiConfiguration2.setConfigurationId("testConfigurationId2");
         aaiConfiguration2.setRelationshipList(relationshipList1);
 
+        org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule();
+        aaiVfModule.setIsBaseVfModule(true);
+
         try {
+            doReturn(genericVnfAai).when(mockBbInputSetupUtils).getAAIGenericVnf(genericVnf.getVnfId());
             doReturn(serviceInstanceAAI).when(mockBbInputSetupUtils).getAAIServiceInstanceById(resourceId);
             doReturn(serviceInstance).when(mockBbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
             doReturn(Optional.of(aaiConfiguration1)).when(mockAaiConfigurationResources)
                     .getConfiguration("testConfigurationId");
             doReturn(Optional.of(aaiConfiguration2)).when(mockAaiConfigurationResources)
                     .getConfiguration("testConfigurationId2");
+            doReturn(aaiVfModule).when(mockBbInputSetupUtils).getAAIVfModule(any(), any());
             serviceEBBLoader.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds);
             assertEquals(8, resourceCounter.size());
             assertTrue(resourceCounter.get(2).isBaseVfModule());
@@ -280,7 +295,8 @@ public class ServiceEBBLoaderTest extends BaseTaskTest {
 
         doReturn(aaiLocalNetwork).when(mockBbInputSetupUtils).getAAIL3Network("localNetworkInstanceId");
 
-        serviceEBBLoader.traverseVrfConfiguration(aaiResourceIds, resource, service, relatedVpnBinding,
+        Resource serviceResource = new Resource(WorkflowType.SERVICE, "1", false, null);
+        serviceEBBLoader.traverseVrfConfiguration(aaiResourceIds, resource, serviceResource, service, relatedVpnBinding,
                 relatedLocalNetwork);
         assertEquals(resource.size(), 1);
         assertEquals(aaiResourceIds.size(), 0);
@@ -346,12 +362,66 @@ public class ServiceEBBLoaderTest extends BaseTaskTest {
 
     private List<Resource> prepareListWithResources() {
         List<Resource> resourceList = new ArrayList<>();
-        resourceList.add(new Resource(WorkflowType.SERVICE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false));
-        resourceList.add(new Resource(WorkflowType.VNF, "ab153b6e-c364-44c0-bef6-1f2982117f04", false));
-        resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", false));
-        resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false));
-        resourceList.add(new Resource(WorkflowType.VFMODULE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false));
-        resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false));
+        Resource r1 = new Resource(WorkflowType.SERVICE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false, null);
+        resourceList.add(r1);
+        Resource r2 = new Resource(WorkflowType.VNF, "ab153b6e-c364-44c0-bef6-1f2982117f04", false, r1);
+        resourceList.add(r2);
+        resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", false, r2));
+        resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false, r2));
+        resourceList.add(new Resource(WorkflowType.VFMODULE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false, r2));
+        resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false, r2));
         return resourceList;
     }
+
+    @Test
+    public void traverseServiceInstanceChildServiceTest() {
+        List<Resource> resourceList = new ArrayList<>();
+        Resource parentResource = new Resource(WorkflowType.SERVICE, "parentId", false, null);
+        String resourceId = "siP";
+        ServiceInstance serviceInstanceAAI = new ServiceInstance();
+        serviceInstanceAAI.setServiceInstanceId(resourceId);
+
+        RelationshipData relationshipData = new RelationshipData();
+        relationshipData.setRelationshipKey("service-instance.service-instance-id");
+        relationshipData.setRelationshipValue("80ced9d5-666e-406b-88f0-a05d31328b70");
+        RelatedToProperty relatedToProperty = new RelatedToProperty();
+        relatedToProperty.setPropertyKey("service-instance.service-instance-name");
+        relatedToProperty.setPropertyValue("child_euler_002");
+
+        RelationshipData relationshipData1 = new RelationshipData();
+        relationshipData1.setRelationshipKey("service-instance.service-instance-id");
+        relationshipData1.setRelationshipValue("fa5640af-c827-4372-baae-7f1c50fdb5ed");
+        RelatedToProperty relatedToProperty1 = new RelatedToProperty();
+        relatedToProperty1.setPropertyKey("service-instance.service-instance-name");
+        relatedToProperty.setPropertyValue("child_euler_001");
+
+
+        Relationship relationship = new Relationship();
+        Relationship relationship1 = new Relationship();
+        relationship.setRelatedTo("service-instance");
+        relationship1.setRelatedTo("service-instance");
+        relationship.getRelationshipData().add(relationshipData);
+        relationship.getRelatedToProperty().add(relatedToProperty);
+        relationship1.getRelationshipData().add(relationshipData1);
+        relationship1.getRelatedToProperty().add(relatedToProperty1);
+
+        RelationshipList relationshipList = new RelationshipList();
+        RelationshipList relationshipList1 = new RelationshipList();
+        relationshipList.getRelationship().add(relationship);
+        relationshipList1.getRelationship().add(relationship1);
+
+        ComposedResource composedResource = new ComposedResource();
+        composedResource.setRelationshipList(relationshipList);
+        ComposedResource composedResource1 = new ComposedResource();
+        composedResource1.setRelationshipList(relationshipList);
+
+        ComposedResources composedResources = new ComposedResources();
+        composedResources.getComposedResource().add(composedResource);
+        composedResources.getComposedResource().add(composedResource1);
+
+        serviceInstanceAAI.setComposedResources(composedResources);
+
+        serviceEBBLoader.traverseServiceInstanceChildService(resourceList, parentResource, serviceInstanceAAI);
+        assertEquals(2, resourceList.size());
+    }
 }