X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=vid-app-common%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fvid%2Fservices%2FAAIServiceTreeIntegrativeTest.java;h=03b5b24cbfa9999ef6c01013dd4ac25c2f9a0882;hb=3bfa1d957d77f9e40c47e654a629e73bd77fdfcd;hp=8c33e7f64fcc812f6b9f0f87533167f2a4dd47f8;hpb=90cbfcabf6a73c466d3284191f2e2b6a472b41b6;p=vid.git diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java index 8c33e7f64..03b5b24cb 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java @@ -37,8 +37,10 @@ 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.Mock; import org.onap.vid.aai.AaiClientInterface; @@ -48,15 +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.BeforeMethod; import org.testng.annotations.Test; +import org.togglz.core.manager.FeatureManager; public class AAIServiceTreeIntegrativeTest { @@ -75,9 +81,16 @@ public class AAIServiceTreeIntegrativeTest { @Mock ServiceModelInflator serviceModelInflator; + @Mock + FeatureManager featureManager; + + @Mock + Logging logging; + + private AAITreeNodesEnricher aaiTreeNodesEnricher; private AAITreeNodeBuilder aaiTreeNodeBuilder; - private AAITreeConverter aaiTreeConverter = new AAITreeConverter(); + private AAITreeConverter aaiTreeConverter = new AAITreeConverter(new ModelUtil()); private ExecutorService executorService = Executors.newFixedThreadPool(10); @@ -87,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/" + @@ -127,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) { @@ -292,7 +303,17 @@ public class AAIServiceTreeIntegrativeTest { @BeforeMethod public void initMocks() { TestUtils.initMockitoMocks(this); - aaiTreeNodeBuilder = new AAITreeNodeBuilder(aaiClient); + 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); + } + + 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 { @@ -303,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); @@ -331,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 @@ -359,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"); @@ -426,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); }