diff options
Diffstat (limited to 'vid-app-common/src/test')
9 files changed, 334 insertions, 241 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java index 5c37bb1ee..777729c03 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java @@ -56,7 +56,6 @@ import java.net.URI; import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Map; -import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.stream.Stream; @@ -756,51 +755,6 @@ public class AaiClientTest { }; } - @Test - public void testGetLatestVersionByInvariantId() throws IOException { - - ModelVersions modelVersions = JACKSON_OBJECT_MAPPER.readValue("" + - "{\n" + - " \"results\": [\n" + - " {\n" + - " \"model\": {\n" + - " \"model-invariant-id\": \"f6342be5-d66b-4d03-a1aa-c82c3094c4ea\",\n" + - " \"model-type\": \"service\",\n" + - " \"resource-version\": \"1534274421300\"\n" + - " }\n" + - " },\n" + - " {\n" + - " \"model-ver\": {\n" + - " \"model-version-id\": \"a92f899d-a3ec-465b-baed-1663b0a5aee1\",\n" + - " \"model-name\": \"NCM_VLAN_SVC_ym161f\",\n" + - " \"model-version\": \"bbb\",\n" + - " \"distribution-status\": \"DISTRIBUTION_COMPLETE_OK\",\n" + - " \"model-description\": \"Network Collection service for vLAN tagging\",\n" + - " \"resource-version\": \"1534788756086\"\n" + - " }\n" + - " },\n" + - " {\n" + - " \"model-ver\": {\n" + - " \"model-version-id\": \"d2fda667-e92e-4cfa-9620-5da5de01a319\",\n" + - " \"model-name\": \"NCM_VLAN_SVC_ym161f\",\n" + - " \"model-version\": \"aaa\",\n" + - " \"distribution-status\": \"DISTRIBUTION_COMPLETE_OK\",\n" + - " \"model-description\": \"Network Collection service for vLAN tagging\",\n" + - " \"resource-version\": \"1534444087221\"\n" + - " }\n" + - " }]}", ModelVersions.class); - - - final AaiClient aaiClient = new AaiClient(null, null, null); - - assertThat(aaiClient.toModelVerStream(modelVersions).collect(toList()), - containsInAnyOrder( - hasProperty("modelVersionId", is("a92f899d-a3ec-465b-baed-1663b0a5aee1")), - hasProperty("modelVersionId", is("d2fda667-e92e-4cfa-9620-5da5de01a319")) - )); - - } - @DataProvider public static Object[][] versionsDataProvider() { return new Object[][] { @@ -984,5 +938,4 @@ public class AaiClientTest { )); } - } diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java index b51bbdc31..f9a374948 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java @@ -21,6 +21,8 @@ package org.onap.vid.controller; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; @@ -45,8 +47,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.onap.vid.aai.AaiResponse; +import org.onap.vid.aai.AaiResponseTranslator; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk; @@ -94,7 +98,7 @@ public class AaiControllerTest { @Before public void setUp() { aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper, - featureManager); + featureManager); mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build(); } @@ -108,12 +112,12 @@ public class AaiControllerTest { given(aaiService.getAicZoneForPnf(globalCustomerId, serviceType, serviceId)).willReturn(aaiResponse); mockMvc.perform( - get("/aai_get_aic_zone_for_pnf/{globalCustomerId}/{serviceType}/{serviceId}", globalCustomerId, serviceType, - serviceId) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody))); + get("/aai_get_aic_zone_for_pnf/{globalCustomerId}/{serviceType}/{serviceId}", globalCustomerId, serviceType, + serviceId) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody))); } @Test @@ -124,10 +128,10 @@ public class AaiControllerTest { given(aaiService.getInstanceGroupsByVnfInstanceId(vnfInstanceId)).willReturn(aaiResponse); mockMvc.perform(get("/aai_get_instance_groups_by_vnf_instance_id/{vnfInstanceId}", vnfInstanceId) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody))); + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody))); } @Test @@ -140,17 +144,17 @@ public class AaiControllerTest { given(response.getStatus()).willReturn(HttpStatus.OK.value()); given(aaiRestInterface.RestGet(eq("VidAaiController"), anyString(), eq(Unchecked.toURI( - "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:" - + serviceInstanceId)), - eq(false)).getResponse()).willReturn(response); + "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:" + + serviceInstanceId)), + eq(false)).getResponse()).willReturn(response); mockMvc - .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId, - serviceInstanceType) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(expectedResponseBody)); + .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId, + serviceInstanceType) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponseBody)); } @Test @@ -163,17 +167,17 @@ public class AaiControllerTest { given(response.getStatus()).willReturn(HttpStatus.OK.value()); given(aaiRestInterface.RestGet(eq("VidAaiController"), anyString(), eq(Unchecked.toURI( - "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:" - + serviceInstanceId)), - eq(false)).getResponse()).willReturn(response); + "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:" + + serviceInstanceId)), + eq(false)).getResponse()).willReturn(response); mockMvc - .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId, - serviceInstanceType) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(expectedResponseBody)); + .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId, + serviceInstanceType) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponseBody)); } @Test @@ -186,21 +190,21 @@ public class AaiControllerTest { given(response.getStatus()).willReturn(HttpStatus.OK.value()); given(aaiRestInterface.RestGet( - eq("VidAaiController"), - anyString(), - eq(Unchecked.toURI( - "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" - + serviceSubscriptionId + "?depth=0")), - eq(false)).getResponse()).willReturn(response); + eq("VidAaiController"), + anyString(), + eq(Unchecked.toURI( + "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + + serviceSubscriptionId + "?depth=0")), + eq(false)).getResponse()).willReturn(response); mockMvc - .perform( - get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId, - serviceSubscriptionId) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(expectedResponseBody)); + .perform( + get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId, + serviceSubscriptionId) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponseBody)); } @Test @@ -209,21 +213,21 @@ public class AaiControllerTest { String serviceSubscriptionId = "testServiceSubscriptionId"; String expectedResponseBody = "Failed to fetch data from A&AI, check server logs for details."; given(aaiRestInterface.RestGet( - eq("VidAaiController"), - anyString(), - eq(Unchecked.toURI( - "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" - + serviceSubscriptionId + "?depth=0")), - eq(false)).getResponse()).willReturn(null); + eq("VidAaiController"), + anyString(), + eq(Unchecked.toURI( + "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + + serviceSubscriptionId + "?depth=0")), + eq(false)).getResponse()).willReturn(null); mockMvc - .perform( - get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId, - serviceSubscriptionId) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(content().string(expectedResponseBody)); + .perform( + get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId, + serviceSubscriptionId) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(content().string(expectedResponseBody)); } @Test @@ -231,18 +235,18 @@ public class AaiControllerTest { PortMirroringConfigDataOk okConfigData = new PortMirroringConfigDataOk("foo"); PortMirroringConfigDataError errorConfigData = new PortMirroringConfigDataError("bar", "{ baz: qux }"); Map<String, PortMirroringConfigData> expectedJson = ImmutableMap.of( - ID_1, okConfigData, - ID_2, errorConfigData); + ID_1, okConfigData, + ID_2, errorConfigData); given(aaiService.getPortMirroringConfigData(ID_1)).willReturn(okConfigData); given(aaiService.getPortMirroringConfigData(ID_2)).willReturn(errorConfigData); mockMvc - .perform(get("/aai_getPortMirroringConfigsData") - .param("configurationIds", ID_1, ID_2) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(expectedJson))); + .perform(get("/aai_getPortMirroringConfigsData") + .param("configurationIds", ID_1, ID_2) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(expectedJson))); } @Test @@ -250,18 +254,18 @@ public class AaiControllerTest { PortDetailsOk portDetailsOk = new PortDetailsOk("foo", "testInterface", true); PortDetailsError portDetailsError = new PortDetailsError("bar", "{ baz: qux }"); Multimap<String, PortDetails> expectedJson = ImmutableMultimap.of( - ID_1, portDetailsOk, - ID_2, portDetailsError); + ID_1, portDetailsOk, + ID_2, portDetailsError); given(aaiService.getPortMirroringSourcePorts(ID_1)).willReturn(Lists.newArrayList(portDetailsOk)); given(aaiService.getPortMirroringSourcePorts(ID_2)).willReturn(Lists.newArrayList(portDetailsError)); mockMvc - .perform(get("/aai_getPortMirroringSourcePorts") - .param("configurationIds", ID_1, ID_2) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(expectedJson.asMap()))); + .perform(get("/aai_getPortMirroringSourcePorts") + .param("configurationIds", ID_1, ID_2) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(expectedJson.asMap()))); } @Test @@ -275,15 +279,15 @@ public class AaiControllerTest { String expectedResponseBody = "myResponse"; AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, "", HttpStatus.OK.value()); given(aaiService - .getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion)) - .willReturn(aaiResponse); + .getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion)) + .willReturn(aaiResponse); mockMvc - .perform(get(urlTemplate, globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(expectedResponseBody)); + .perform(get(urlTemplate, globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponseBody)); } @Test @@ -292,45 +296,45 @@ public class AaiControllerTest { given(aaiService.getAaiZones()).willReturn(new AaiResponse(aicZones, "", HttpStatus.OK.value())); mockMvc.perform(get("/aai_get_aic_zones") - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(aicZones))); + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(aicZones))); } @Test public void getAicZones_shouldReturnErrorResponse_whenAaiHttpStatusOtherThanOK() throws Exception { String expectedErrorMessage = "Calling AAI Failed"; given(aaiService.getAaiZones()) - .willReturn(new AaiResponse(null, expectedErrorMessage, HttpStatus.INTERNAL_SERVER_ERROR.value())); + .willReturn(new AaiResponse(null, expectedErrorMessage, HttpStatus.INTERNAL_SERVER_ERROR.value())); mockMvc.perform(get("/aai_get_aic_zones") - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(content().string(expectedErrorMessage)); + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(content().string(expectedErrorMessage)); } @Test public void getSpecificPnf_shouldReturnPnfObjectForPnfId() throws Exception { String pnfId = "MyPnfId"; Pnf pnf = Pnf.builder() - .withPnfId(pnfId) - .withPnfName("TestPnf") - .withPnfName2("pnfName2") - .withPnfName2Source("pnfNameSource") - .withEquipModel("model") - .withEquipType("type") - .withEquipVendor("vendor") - .build(); + .withPnfId(pnfId) + .withPnfName("TestPnf") + .withPnfName2("pnfName2") + .withPnfName2Source("pnfNameSource") + .withEquipModel("model") + .withEquipType("type") + .withEquipVendor("vendor") + .build(); AaiResponse<Pnf> aaiResponse = new AaiResponse<>(pnf, "", HttpStatus.OK.value()); given(aaiService.getSpecificPnf(pnfId)).willReturn(aaiResponse); mockMvc.perform(get("/aai_get_pnfs/pnf/{pnf_id}", pnfId) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(pnf))); + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(pnf))); } @Test @@ -340,10 +344,10 @@ public class AaiControllerTest { given(aaiService.getSpecificPnf(pnfId)).willThrow(new RuntimeException(expectedErrorMessage)); mockMvc.perform(get("/aai_get_pnfs/pnf/{pnf_id}", pnfId) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(content().string(expectedErrorMessage)); + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(content().string(expectedErrorMessage)); } public void getPNFInstances_shouldReturnOKResponseFromAAIService() throws Exception { @@ -359,16 +363,16 @@ public class AaiControllerTest { AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, "", HttpStatus.OK.value()); given(aaiService - .getPNFData(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, - equipModel)).willReturn(aaiResponse); + .getPNFData(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, + equipModel)).willReturn(aaiResponse); mockMvc.perform( - get(urlTemplate, globalCustomerId, serviceType, modelVersionId, - modelInvariantId, cloudRegion, equipVendor, equipModel) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(expectedResponseBody)); + get(urlTemplate, globalCustomerId, serviceType, modelVersionId, + modelInvariantId, cloudRegion, equipVendor, equipModel) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponseBody)); } @Test @@ -379,20 +383,20 @@ public class AaiControllerTest { Response response = mock(Response.class); given(response.readEntity(String.class)).willReturn(expectedResponse); given(aaiService - .getVersionByInvariantId(request.versions)).willReturn(response); + .getVersionByInvariantId(request.versions)).willReturn(response); mockMvc.perform( - post("/aai_get_version_by_invariant_id") - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(expectedResponse)); + post("/aai_get_version_by_invariant_id") + .content(objectMapper.writeValueAsString(request)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponse)); } @Test public void getSubscriberDetails_shouldOmitServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsTrue() - throws Exception { + throws Exception { boolean isFeatureActive = true; boolean omitServiceInstances = true; @@ -401,21 +405,21 @@ public class AaiControllerTest { AaiResponse<String> aaiResponse = new AaiResponse<>(okResponseBody, "", HttpStatus.OK.value()); given(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).willReturn(isFeatureActive); given(aaiService.getSubscriberData(eq(subscriberId), isA(RoleValidatorByRoles.class), - eq(isFeatureActive && omitServiceInstances))) - .willReturn(aaiResponse); + eq(isFeatureActive && omitServiceInstances))) + .willReturn(aaiResponse); mockMvc.perform( - get("/aai_sub_details/{subscriberId}", subscriberId) - .param("omitServiceInstances", Boolean.toString(omitServiceInstances)) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody))); + get("/aai_sub_details/{subscriberId}", subscriberId) + .param("omitServiceInstances", Boolean.toString(omitServiceInstances)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody))); } @Test public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsFalse() - throws Exception { + throws Exception { boolean isFeatureActive = true; boolean omitServiceInstances = false; @@ -424,7 +428,7 @@ public class AaiControllerTest { @Test public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsTrue() - throws Exception { + throws Exception { boolean isFeatureActive = false; boolean omitServiceInstances = true; @@ -432,30 +436,52 @@ public class AaiControllerTest { } @Test + public void getPortMirroringConfigData_givenThreeIds_ReturnsThreeResults() { + + final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForA = new AaiResponseTranslator.PortMirroringConfigDataOk("foobar"); + final AaiResponseTranslator.PortMirroringConfigDataError toBeReturnedForB = new AaiResponseTranslator.PortMirroringConfigDataError("foo", "{ baz: qux }"); + final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForC = new AaiResponseTranslator.PortMirroringConfigDataOk("corge"); + + Mockito + .doReturn(toBeReturnedForA) + .doReturn(toBeReturnedForB) + .doReturn(toBeReturnedForC) + .when(aaiService).getPortMirroringConfigData(Mockito.anyString()); + + final Map<String, AaiResponseTranslator.PortMirroringConfigData> result = aaiController.getPortMirroringConfigsData(ImmutableList.of("a", "b", "c")); + + assertThat(result, is(ImmutableMap.of( + "a", toBeReturnedForA, + "b", toBeReturnedForB, + "c", toBeReturnedForC + ))); + } + + @Test public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsFalse() - throws Exception { + throws Exception { boolean isFeatureActive = false; boolean omitServiceInstances = false; getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances); } private void getSubscriberDetails_assertServiceInstancesInclusion(boolean isFeatureActive, - boolean omitServiceInstances) throws Exception { + boolean omitServiceInstances) throws Exception { String subscriberId = "subscriberId"; String okResponseBody = "OK_RESPONSE"; AaiResponse<String> aaiResponse = new AaiResponse<>(okResponseBody, "", HttpStatus.OK.value()); given(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).willReturn(isFeatureActive); given(aaiService.getSubscriberData(eq(subscriberId), isA(RoleValidatorByRoles.class), - eq(isFeatureActive && omitServiceInstances))) - .willReturn(aaiResponse); + eq(isFeatureActive && omitServiceInstances))) + .willReturn(aaiResponse); mockMvc.perform( - get("/aai_sub_details/{subscriberId}", subscriberId) - .param("omitServiceInstances", Boolean.toString(omitServiceInstances)) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody))); + get("/aai_sub_details/{subscriberId}", subscriberId) + .param("omitServiceInstances", Boolean.toString(omitServiceInstances)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody))); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java index f44099569..39638c305 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java @@ -67,6 +67,21 @@ public class PromiseEcompRequestIdFilterTest { buildRequestThenRunThroughFilterAndAssertResultRequestHeaders(incomingRequestHeaders, specificTxId(someTxId)); } + + @Test + public void givenRequestIdHeaderThatIsNotAUUID_headerValueChanged() throws IOException, ServletException { + + final String someTxId = "863850e28544efd94b8afba5f52b3d5"; + + final ImmutableMap<String, String> incomingRequestHeaders = ImmutableMap.of( + anotherHeader, anotherValue, + ECOMP_REQUEST_ID, someTxId + ); + + buildRequestThenRunThroughFilterAndAssertResultRequestHeaders(incomingRequestHeaders, UserUtils::getRequestId); + } + + @Test public void givenMixedCaseRequestIdHeader_headerValueNotChanged() throws IOException, ServletException { diff --git a/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java b/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java index 498708d06..fdc416a3b 100644 --- a/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java @@ -20,9 +20,66 @@ package org.onap.vid.job.impl; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.joining; +import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals; +import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; +import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals; +import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartMatches; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.core.Every.everyItem; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.endsWith; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.vid.job.Job.JobStatus.COMPLETED; +import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_ERRORS; +import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_NO_ACTION; +import static org.onap.vid.job.Job.JobStatus.FAILED; +import static org.onap.vid.job.Job.JobStatus.IN_PROGRESS; +import static org.onap.vid.job.Job.JobStatus.PAUSE; +import static org.onap.vid.job.Job.JobStatus.PENDING; +import static org.onap.vid.job.Job.JobStatus.PENDING_RESOURCE; +import static org.onap.vid.job.Job.JobStatus.RESOURCE_IN_PROGRESS; +import static org.onap.vid.job.Job.JobStatus.STOPPED; +import static org.onap.vid.job.impl.JobSchedulerInitializer.WORKERS_TOPICS; +import static org.onap.vid.model.JobAuditStatus.SourceStatus.VID; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Stack; +import java.util.UUID; +import java.util.function.BiConsumer; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import javax.inject.Inject; +import javax.ws.rs.ProcessingException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.MutableInt; import org.jetbrains.annotations.NotNull; @@ -33,13 +90,24 @@ import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.config.DataSourceConfig; +import org.onap.vid.config.JobCommandsConfigWithMockedMso; +import org.onap.vid.config.MockedAaiClientAndFeatureManagerConfig; import org.onap.vid.job.Job; import org.onap.vid.job.Job.JobStatus; import org.onap.vid.job.JobType; import org.onap.vid.job.JobsBrokerService; import org.onap.vid.job.command.CommandUtils; import org.onap.vid.job.command.InternalState; -import org.onap.vid.model.*; +import org.onap.vid.model.Action; +import org.onap.vid.model.JobAuditStatus; +import org.onap.vid.model.NameCounter; +import org.onap.vid.model.RequestReferencesContainer; +import org.onap.vid.model.Service; +import org.onap.vid.model.ServiceInfo; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.VNF; +import org.onap.vid.model.VfModule; import org.onap.vid.model.serviceInstantiation.BaseResource; import org.onap.vid.model.serviceInstantiation.InstanceGroup; import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; @@ -49,15 +117,12 @@ import org.onap.vid.mso.model.RequestReferences; import org.onap.vid.mso.rest.AsyncRequestStatus; import org.onap.vid.mso.rest.AsyncRequestStatusList; import org.onap.vid.properties.Features; +import org.onap.vid.services.AsyncInstantiationBaseTest; import org.onap.vid.services.AsyncInstantiationBusinessLogic; import org.onap.vid.services.AuditService; import org.onap.vid.services.VersionService; -import org.onap.vid.utils.DaoUtils; -import org.onap.vid.config.DataSourceConfig; -import org.onap.vid.config.JobCommandsConfigWithMockedMso; -import org.onap.vid.config.MockedAaiClientAndFeatureManagerConfig; -import org.onap.vid.services.AsyncInstantiationBaseTest; import org.onap.vid.testUtils.TestUtils; +import org.onap.vid.utils.DaoUtils; import org.springframework.http.HttpMethod; import org.springframework.test.context.ContextConfiguration; import org.testng.annotations.BeforeClass; @@ -66,34 +131,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.togglz.core.manager.FeatureManager; -import javax.inject.Inject; -import javax.ws.rs.ProcessingException; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -import static java.util.stream.Collectors.*; -import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals; -import static net.javacrumbs.jsonunit.JsonMatchers.*; -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.core.Every.everyItem; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.endsWith; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; -import static org.onap.vid.job.Job.JobStatus.*; -import static org.onap.vid.job.impl.JobSchedulerInitializer.WORKERS_TOPICS; -import static org.onap.vid.model.JobAuditStatus.SourceStatus.VID; -import static org.testng.AssertJUnit.*; - //it's more like integration test than UT //But it's very hard to test in API test so I use UT @ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class, JobCommandsConfigWithMockedMso.class}) @@ -1203,12 +1240,18 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes } @Test - public void whenUpgradingAvfModule_thanExpectedReplaceRequestSent() throws IOException { - String instanceId = "5d49c3b1-fc90-4762-8c98-e800170baa55"; //from feRequestResumeMacroService.json + public void whenUpgradingAvfModule_thanExpectedReplaceRequestSent() throws IOException, AsdcCatalogException { + String instanceId = "5d49c3b1-fc90-4762-8c98-e800170baa55"; //from replace_vfmodule_fe_input.json String replaceRequestId = randomUuid(); String userId = "az2016"; + //prepare mocks for newest model + String newestModelUuid = "newest-model-uuid"; + when(commandUtils.getNewestModelUuid(eq("b16a9398-ffa3-4041-b78c-2956b8ad9c7b"))).thenReturn(newestModelUuid); + + when(commandUtils.getServiceModel(eq(newestModelUuid))).thenReturn(generateMockLatestModelForUpgrade()); + //prepare mocks resume request when(restMso.restCall(eq(HttpMethod.POST), eq(RequestReferencesContainer.class), any(), eq("/serviceInstantiation/v7/serviceInstances/e9993045-cc96-4f3f-bf9a-71b2a400a956/vnfs/5c9c2896-1fe6-4055-b7ec-d0a01e5f9bf5/vfModules/5d49c3b1-fc90-4762-8c98-e800170baa55/replace"), eq(Optional.of(userId)))) .thenReturn(createResponse(202, instanceId, replaceRequestId)); @@ -1235,7 +1278,53 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes requestCaptor.getAllValues().forEach(x->assertJsonEquals(expectedJson, x)); } + private ServiceModel generateMockLatestModelForUpgrade() { + ServiceModel expectedNewestModel = new ServiceModel(); + + + VfModule vfm = new VfModule(); + vfm.setModelCustomizationName("newest-model-customization-name-vfm"); + vfm.setCustomizationUuid("newest-model-customization-uuid-vfm"); + vfm.setVersion("newest-model-version-vfm"); + vfm.setUuid("newest-model-uuid-vfm"); + vfm.setName("newest-model-name-vfm"); + vfm.setInvariantUuid("f7a867f2-596b-4f4a-a128-421e825a6190"); + + + Map<String,VfModule> vfms = new HashMap<>(); + vfms.put("074c64d0-7e13-4bcc-8bdb-ea922331102d", vfm); + + + VNF vnf = new VNF(); + vnf.setModelCustomizationName("newest-model-customization-name-vnf"); + vnf.setCustomizationUuid("newest-model-customization-uuid-vnf"); + vnf.setVersion("newest-model-version-vnf"); + vnf.setUuid("newest-model-uuid-vnf"); + vnf.setName("newest-model-name-vnf"); + vnf.setInvariantUuid("23122c9b-dd7f-483f-bf0a-e069303db2f7"); + vnf.setVfModules(vfms); + expectedNewestModel.setVfModules(vfms); + + Map<String,VNF> vnfs = new HashMap<>(); + vnfs.put("96c23a4a-6887-4b2c-9cce-1e4ea35eaade", vnf); + + Service svc = new Service(); + svc.setInvariantUuid("b16a9398-ffa3-4041-b78c-2956b8ad9c7b"); + svc.setUuid("newest-model-uuid-service"); + svc.setVersion("newest-model-version-service"); + svc.setName("newest-model-name-service"); + + expectedNewestModel.setService(svc); + + expectedNewestModel.setVnfs(vnfs); + + return expectedNewestModel; + + + } + private ServiceInstantiation generateReplaceVfModulePayload() throws IOException { return TestUtils.readJsonResourceFileAsObject("/payload_jsons/vfmodule/replace_vfmodule_fe_input.json", ServiceInstantiation.class); } + } diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java index 69458aa86..9cc97116b 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java @@ -183,7 +183,7 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests } protected VfModule createVfModuleForReplace(ModelInfo vfModuleModelInfo, String instanceName, String lcpCloudRegionId, String tenantId) { - return new VfModule( vfModuleModelInfo, instanceName, null, Action.Replace.name(), lcpCloudRegionId, null, tenantId, + return new VfModule( vfModuleModelInfo, instanceName, null, Action.Upgrade.name(), lcpCloudRegionId, null, tenantId, null, null, true, null, null, UUID.randomUUID().toString(), null, null); } diff --git a/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java b/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java index 311eb04cc..bd761f275 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java @@ -603,18 +603,18 @@ public class MsoRequestBuilderTest extends AsyncInstantiationBaseTest { when(featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)).thenReturn(true); when(aaiClient.getCloudOwnerByCloudRegionId("regionOne")).thenReturn("irma-aic"); - ModelInfo vfModuleModelInfo = createVfModuleModelInfo("VfZrdm5bpxmc02092017Vf..CORNELIUS_base..module-0", "1", "eb5de6fb-9ecf-4009-b922-fae3a9ae7d46", - "f7a867f2-596b-4f4a-a128-421e825a6190", "074c64d0-7e13-4bcc-8bdb-ea922331102d",null ); + ModelInfo vfModuleModelInfo = createVfModuleModelInfo("newest-model-name-vfm", "newest-model-version-vfm", "newest-model-uuid-vfm", + "f7a867f2-596b-4f4a-a128-421e825a6190", "newest-model-customization-uuid-vfm","newest-model-customization-name-vfm" ); VfModule vfModuleDetails = createVfModuleForReplace(vfModuleModelInfo, "replace_module", "regionOne", "0422ffb57ba042c0800a29dc85ca70f8"); - ModelInfo serviceModelInfo = createServiceModelInfo("Vf zolson5bpxmc02092017-Service", "1", "bad955c3-29b2-4a27-932e-28e942cc6480", "b16a9398-ffa3-4041-b78c-2956b8ad9c7b", null, null ); + ModelInfo serviceModelInfo = createServiceModelInfo("newest-model-name-service", "newest-model-version-service", "newest-model-uuid-service", "b16a9398-ffa3-4041-b78c-2956b8ad9c7b", null, null ); - ModelInfo vnfModelInfo = createVnfModelInfo("Vf zolson5bpxmc02092017-VF", "1", "d326f424-2312-4dd6-b7fe-364fadbd1ef5", "23122c9b-dd7f-483f-bf0a-e069303db2f7", "96c23a4a-6887-4b2c-9cce-1e4ea35eaade", "Vf zolson5bpxmc02092017-VF 0" ); + ModelInfo vnfModelInfo = createVnfModelInfo("newest-model-name-vnf", "newest-model-version-vnf", "newest-model-uuid-vnf", "23122c9b-dd7f-483f-bf0a-e069303db2f7", "newest-model-customization-uuid-vnf", "newest-model-customization-name-vnf" ); RequestDetailsWrapper<VfModuleInstantiationRequestDetails> result = msoRequestBuilder.generateVfModuleInstantiationRequest(vfModuleDetails, serviceModelInfo, "e9993045-cc96-4f3f-bf9a-71b2a400a956", vnfModelInfo, "5c9c2896-1fe6-4055-b7ec-d0a01e5f9bf5", null,"az2016", "GR_API"); - MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result); + assertThat(result, jsonEquals(expected).when(IGNORING_ARRAY_ORDER)); } }
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/utils/TreeTest.java b/vid-app-common/src/test/java/org/onap/vid/utils/TreeTest.java index eaa9990c2..9b27f6e23 100644 --- a/vid-app-common/src/test/java/org/onap/vid/utils/TreeTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/utils/TreeTest.java @@ -80,4 +80,12 @@ public class TreeTest { assertTrue(subTree.isPathExist("d")); assertFalse(subTree.isPathExist("b","c","d")); } + + @Test + public void getChildrenDepthTest() { + Tree<String> tree = buildTreeForTest(); + assertEquals(3, tree.getChildrenDepth()); + Tree<String> subTree = tree.getSubTree("b"); + assertEquals(2, subTree.getChildrenDepth()); + } } diff --git a/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule.json b/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule.json index c3ab694aa..103985c96 100644 --- a/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule.json +++ b/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule.json @@ -10,9 +10,9 @@ "relatedInstance": { "instanceId": "e9993045-cc96-4f3f-bf9a-71b2a400a956", "modelInfo": { - "modelVersionId": "bad955c3-29b2-4a27-932e-28e942cc6480", - "modelVersion": "1", - "modelName": "Vf zolson5bpxmc02092017-Service", + "modelVersionId": "newest-model-uuid-service", + "modelVersion": "newest-model-version-service", + "modelName": "newest-model-name-service", "modelInvariantId": "b16a9398-ffa3-4041-b78c-2956b8ad9c7b", "modelType": "service" } @@ -21,13 +21,13 @@ "relatedInstance": { "instanceId": "5c9c2896-1fe6-4055-b7ec-d0a01e5f9bf5", "modelInfo": { - "modelName": "Vf zolson5bpxmc02092017-VF", - "modelVersion": "1", + "modelName": "newest-model-name-vnf", + "modelVersion": "newest-model-version-vnf", "modelInvariantId": "23122c9b-dd7f-483f-bf0a-e069303db2f7", "modelType": "vnf", - "modelCustomizationName": "Vf zolson5bpxmc02092017-VF 0", - "modelVersionId": "d326f424-2312-4dd6-b7fe-364fadbd1ef5", - "modelCustomizationId": "96c23a4a-6887-4b2c-9cce-1e4ea35eaade" + "modelCustomizationName": "newest-model-customization-name-vnf", + "modelVersionId": "newest-model-uuid-vnf", + "modelCustomizationId": "newest-model-customization-uuid-vnf" } } }], @@ -36,12 +36,13 @@ "testApi": "GR_API" }, "modelInfo": { - "modelName": "VfZrdm5bpxmc02092017Vf..CORNELIUS_base..module-0", - "modelVersion": "1", + "modelName": "newest-model-name-vfm", + "modelVersion": "newest-model-version-vfm", "modelInvariantId": "f7a867f2-596b-4f4a-a128-421e825a6190", "modelType": "vfModule", - "modelVersionId": "eb5de6fb-9ecf-4009-b922-fae3a9ae7d46", - "modelCustomizationId": "074c64d0-7e13-4bcc-8bdb-ea922331102d" + "modelVersionId": "newest-model-uuid-vfm", + "modelCustomizationId": "newest-model-customization-uuid-vfm", + "modelCustomizationName":"newest-model-customization-name-vfm" }, "cloudConfiguration": { "cloudOwner": "irma-aic", diff --git a/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule_fe_input.json b/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule_fe_input.json index 92ccfe541..8d30fd873 100644 --- a/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule_fe_input.json +++ b/vid-app-common/src/test/resources/payload_jsons/vfmodule/replace_vfmodule_fe_input.json @@ -8,7 +8,7 @@ "VfZrdm5bpxmc02092017Vf..CORNELIUS_base..module-0-?": { "instanceName": "replace_module", "instanceId": "5d49c3b1-fc90-4762-8c98-e800170baa55", - "action": "Replace", + "action": "Upgrade", "orchStatus": "Create", "provStatus": "Prov Status", "inMaint": false, @@ -21,6 +21,7 @@ "modelName": "VfZrdm5bpxmc02092017Vf..CORNELIUS_base..module-0", "modelVersion": "1", "modelCustomizationId": "074c64d0-7e13-4bcc-8bdb-ea922331102d", + "modelCustomizationName" : "VfZrdm5bpxmc02092017Vf..CORNELIUS_base..module-0", "uuid": "eb5de6fb-9ecf-4009-b922-fae3a9ae7d46" }, "uuid": "eb5de6fb-9ecf-4009-b922-fae3a9ae7d46" |