Topology tree: enrich vfModules data from other versions of same model
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / AAIServiceTreeIntegrativeTest.java
index 00a9995..03b5b24 100644 (file)
@@ -37,13 +37,12 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.function.Function;
 import javax.ws.rs.core.Response;
-import org.mockito.InjectMocks;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
 import org.onap.vid.aai.AaiClientInterface;
 import org.onap.vid.aai.ExceptionWithRequestInfo;
 import org.onap.vid.aai.util.AAITreeConverter;
@@ -51,16 +50,19 @@ import org.onap.vid.asdc.AsdcCatalogException;
 import org.onap.vid.asdc.parser.ServiceModelInflator;
 import org.onap.vid.exceptions.GenericUncheckedException;
 import org.onap.vid.model.Action;
+import org.onap.vid.model.ModelUtil;
 import org.onap.vid.model.ServiceModel;
 import org.onap.vid.model.aaiTree.AAITreeNode;
 import org.onap.vid.model.aaiTree.FailureAAITreeNode;
 import org.onap.vid.model.aaiTree.ServiceInstance;
 import org.onap.vid.model.aaiTree.Vnf;
+import org.onap.vid.properties.Features;
 import org.onap.vid.testUtils.TestUtils;
+import org.onap.vid.utils.Logging;
 import org.springframework.http.HttpMethod;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
+import org.togglz.core.manager.FeatureManager;
 
 public class AAIServiceTreeIntegrativeTest {
 
@@ -79,11 +81,16 @@ public class AAIServiceTreeIntegrativeTest {
     @Mock
     ServiceModelInflator serviceModelInflator;
 
-    @InjectMocks
+    @Mock
+    FeatureManager featureManager;
+
+    @Mock
+    Logging logging;
+
+    private AAITreeNodesEnricher aaiTreeNodesEnricher;
     private AAITreeNodeBuilder aaiTreeNodeBuilder;
 
-    @InjectMocks
-    private AAITreeConverter aaiTreeConverter;
+    private AAITreeConverter aaiTreeConverter = new AAITreeConverter(new ModelUtil());
 
     private ExecutorService executorService = Executors.newFixedThreadPool(10);
 
@@ -93,7 +100,6 @@ public class AAIServiceTreeIntegrativeTest {
     private String serviceType = "vWINIFRED";
     private String serviceInstanceId = "62888f15-6d24-4f7b-92a7-c3f35beeb215";
 
-    //TODO Amichai: if in the future it is neede, add here the SUFFIX to the URL: "?format=simple"
     private String serviceInstanceRequestUri = "business/customers/customer/" +
             globalCustomerID +
             "/service-subscriptions/service-subscription/" +
@@ -133,7 +139,6 @@ public class AAIServiceTreeIntegrativeTest {
             "\"relationship-key\": \"owning-entity.owning-entity-id\"," +
             "\"relationship-value\": \"43b8a85a-0421-4265-9069-117dd6526b8a\"}]}]}}";
 
-    //TODO Amichai: if in the future it is neede, add here the SUFFIX to the URL: "?format=simple"
     private static String genericVnfRequestUri = "/aai/v12/network/generic-vnfs/generic-vnf/59bde732-9b84-46bd-a59a-3c45fee0538b";
 
     private String genericVnfResponseString(boolean isDuplicatedKeysInTenantRelation) {
@@ -295,17 +300,20 @@ public class AAIServiceTreeIntegrativeTest {
             "\"property-key\": \"model-ver.model-name\"," +
             "\"property-value\": \"service-instance\"}]}]}}]}}]}}]}";
 
-    @BeforeClass
+    @BeforeMethod
     public void initMocks() {
-        MockitoAnnotations.initMocks(this);
+        TestUtils.initMockitoMocks(this);
+        reboundLoggingWithMdcMock();
+        aaiTreeNodeBuilder = new AAITreeNodeBuilder(aaiClient, logging);
+        aaiTreeNodesEnricher = new AAITreeNodesEnricher(aaiClient, null, featureManager, serviceModelInflator);
+
+        when(featureManager.isActive(Features.FLAG_EXP_TOPOLOGY_TREE_VFMODULE_NAMES_FROM_OTHER_TOSCA_VERSIONS))
+            .thenReturn(true);
     }
 
-    @BeforeMethod
-    public void resetMocks() {
-        Mockito.reset(aaiClient);
-        Mockito.reset(aaiGetVersionByInvariantIdResponse);
-        Mockito.reset(sdcService);
-        Mockito.reset(serviceModelInflator);
+    private void reboundLoggingWithMdcMock() {
+        when(logging.withMDC(any(), any(Callable.class))).thenAnswer(invocation -> invocation.getArgument(1));
+        when(logging.withMDC(any(), any(Function.class))).thenAnswer(invocation -> invocation.getArgument(1));
     }
 
     public void getServiceInstanceTreeAndAssert(boolean isDuplicatedKeysInTenantRelation) throws IOException, AsdcCatalogException {
@@ -316,12 +324,12 @@ public class AAIServiceTreeIntegrativeTest {
 
         when(aaiGetVersionByInvariantIdResponse.readEntity(String.class)).thenReturn(getVersionByInvariantIdResponseString);
 
-        when(sdcService.getService(any())).thenReturn(mock(ServiceModel.class));
+        when(sdcService.getServiceModelOrThrow(any())).thenReturn(mock(ServiceModel.class));
         when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(ImmutableMap.of(
                  "11c6dc3e-cd6a-41b3-a50e-b5a10f7157d0", new ServiceModelInflator.Names("vnf-model-customization-name", "vnf-key-in-model")
         ));
 
-        ServiceInstance root = new AAIServiceTree(aaiClient, aaiTreeNodeBuilder, aaiTreeConverter, sdcService, serviceModelInflator, executorService)
+        ServiceInstance root = new AAIServiceTree(aaiTreeNodeBuilder, aaiTreeNodesEnricher, aaiTreeConverter, sdcService, executorService)
                 .getServiceInstanceTopology(globalCustomerID, serviceType, serviceInstanceId);
 
         assertServiceNode(root, 1);
@@ -344,11 +352,7 @@ public class AAIServiceTreeIntegrativeTest {
     }
 
     private void mockAaiGetCall(String aaiPath, String jsonFilePath) {
-        try {
-            when(aaiClient.typedAaiRest(URI.create(aaiPath), JsonNode.class, null, HttpMethod.GET, false)).thenReturn(TestUtils.readJsonResourceFileAsObject(jsonFilePath, JsonNode.class));
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        when(aaiClient.typedAaiRest(URI.create(aaiPath), JsonNode.class, null, HttpMethod.GET, false)).thenReturn(TestUtils.readJsonResourceFileAsObject(jsonFilePath, JsonNode.class));
     }
 
     @Test
@@ -372,10 +376,11 @@ public class AAIServiceTreeIntegrativeTest {
         when(aaiGetVersionByInvariantIdResponse.readEntity(String.class)).
                 thenReturn(TestUtils.readFileAsString("/getTopology/serviceWithCR/service-design-and-creation.json"));
 
-        when(sdcService.getService(any())).thenReturn(
+        when(sdcService.getServiceModelOrThrow(any())).thenReturn(
                 TestUtils.readJsonResourceFileAsObject("/getTopology/serviceWithCR/serviceWithCRModel.json", ServiceModel.class));
 
-        ServiceInstance serviceInstance = new AAIServiceTree(aaiClient, aaiTreeNodeBuilder, aaiTreeConverter, sdcService, new ServiceModelInflator(), executorService)
+        ServiceInstance serviceInstance = new AAIServiceTree(aaiTreeNodeBuilder,
+            new AAITreeNodesEnricher(aaiClient, null, featureManager, new ServiceModelInflator()), aaiTreeConverter, sdcService, executorService)
                 .getServiceInstanceTopology("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", "Emanuel", "a565e6ad-75d1-4493-98f1-33234b5c17e2");
 
         String expected = TestUtils.readFileAsString("/getTopology/serviceWithCR/getTopologyWithCR.json");
@@ -439,10 +444,10 @@ public class AAIServiceTreeIntegrativeTest {
 
         when(aaiGetVersionByInvariantIdResponse.readEntity(String.class)).thenReturn(getVersionByInvariantIdResponseString);
 
-        when(sdcService.getService(any())).thenReturn(mock(ServiceModel.class));
+        when(sdcService.getServiceModelOrThrow(any())).thenReturn(mock(ServiceModel.class));
         when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(ImmutableMap.of());
 
-        new AAIServiceTree(aaiClient, aaiTreeNodeBuilder, aaiTreeConverter, sdcService, serviceModelInflator, executorService)
+        new AAIServiceTree(aaiTreeNodeBuilder, aaiTreeNodesEnricher, aaiTreeConverter, sdcService, executorService)
                 .getServiceInstanceTopology(globalCustomerID, serviceType, serviceInstanceId);
     }