X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=vid-app-common%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fvid%2Fcontroller%2FAaiControllerTest.java;h=51bdec882562274b87aab2b00f2a1ff4cb7fbb94;hb=f09e8d114804e4237e79f27ed492835ecb1b17b0;hp=f9a374948092573eca45b045041d3428e10e844f;hpb=0f2d7dbe3fc557dbdb786901c9ea2bd3b417c973;p=vid.git 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 f9a374948..51bdec882 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 @@ -39,6 +39,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; +import java.util.List; import java.util.Map; import java.util.UUID; import javax.ws.rs.core.Response; @@ -49,6 +50,8 @@ import org.mockito.Answers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.AaiResponseTranslator; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData; @@ -88,7 +91,6 @@ public class AaiControllerTest { private RoleProvider roleProvider; @Mock private SystemPropertiesWrapper systemPropertiesWrapper; - @Mock private FeatureManager featureManager; @@ -98,7 +100,7 @@ public class AaiControllerTest { @Before public void setUp() { aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper, - featureManager); + featureManager); mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build(); } @@ -112,12 +114,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 @@ -128,10 +130,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 @@ -144,17 +146,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 @@ -167,17 +169,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 @@ -190,21 +192,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 @@ -213,21 +215,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 @@ -235,18 +237,18 @@ public class AaiControllerTest { PortMirroringConfigDataOk okConfigData = new PortMirroringConfigDataOk("foo"); PortMirroringConfigDataError errorConfigData = new PortMirroringConfigDataError("bar", "{ baz: qux }"); Map 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 @@ -254,18 +256,18 @@ public class AaiControllerTest { PortDetailsOk portDetailsOk = new PortDetailsOk("foo", "testInterface", true); PortDetailsError portDetailsError = new PortDetailsError("bar", "{ baz: qux }"); Multimap 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 @@ -279,15 +281,15 @@ public class AaiControllerTest { String expectedResponseBody = "myResponse"; AaiResponse 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 @@ -296,45 +298,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 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 @@ -344,10 +346,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 { @@ -363,16 +365,16 @@ public class AaiControllerTest { AaiResponse 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 @@ -383,20 +385,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; @@ -405,21 +407,21 @@ public class AaiControllerTest { AaiResponse 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; @@ -428,7 +430,7 @@ public class AaiControllerTest { @Test public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsTrue() - throws Exception { + throws Exception { boolean isFeatureActive = false; boolean omitServiceInstances = true; @@ -438,50 +440,126 @@ 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"); + 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()); + .doReturn(toBeReturnedForA) + .doReturn(toBeReturnedForB) + .doReturn(toBeReturnedForC) + .when(aaiService).getPortMirroringConfigData(Mockito.anyString()); - final Map result = aaiController.getPortMirroringConfigsData(ImmutableList.of("a", "b", "c")); + final Map result = aaiController + .getPortMirroringConfigsData(ImmutableList.of("a", "b", "c")); assertThat(result, is(ImmutableMap.of( - "a", toBeReturnedForA, - "b", toBeReturnedForB, - "c", toBeReturnedForC + "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 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 getSpecificConfiguration_shouldReturnOkResponse() throws Exception { + String configurationId = "testGlobalCustomerId"; + String expectedResponseBody = "OK_RESPONSE"; + Response response = mock(Response.class); + given(response.readEntity(String.class)).willReturn(expectedResponseBody); + given(response.getStatus()).willReturn(HttpStatus.OK.value()); + + given(aaiRestInterface.RestGet( + eq("VidAaiController"), + anyString(), + eq(Unchecked.toURI("network/configurations/configuration/" + configurationId)), + eq(false)).getResponse()).willReturn(response); + + mockMvc + .perform( + get("/aai_get_configuration/{configuration_id}", configurationId) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponseBody)); + } + + @Test + public void getServiceInstanceAssociatedPnfs_shouldReturnPnfs() throws Exception { + String globalCustomerId = "testCustomerId"; + String serviceType = "testServiceType"; + String serviceInstanceId = "testServiceInstanceId"; + List expectedPnfs = ImmutableList.of("pnf1", "pnf2", "pnf3"); + + given(aaiService.getServiceInstanceAssociatedPnfs(globalCustomerId, serviceType, serviceInstanceId)) + .willReturn(expectedPnfs); + + mockMvc + .perform( + get("/aai_get_service_instance_pnfs/{globalCustomerId}/{serviceType}/{serviceInstanceId}", + globalCustomerId, serviceType, serviceInstanceId) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(expectedPnfs))); + } + + @Test + public void getUserID_shouldReturnOKResponse_withExtractedUserId() throws Exception { + String userPropertyKey = "user"; + String expectedUserLoginId = "testUserLoginId"; + User user = new User(); + user.setLoginId(expectedUserLoginId); + given(systemPropertiesWrapper.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).willReturn(userPropertyKey); + + mockMvc.perform(get("/getuserID") + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .sessionAttr(userPropertyKey, user)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedUserLoginId)); + } + + @Test + public void getTargetProvStatus_shouldReturnProperty() throws Exception { + String expectedResponse = "targetProvStatus"; + given(systemPropertiesWrapper.getProperty("aai.vnf.provstatus")).willReturn(expectedResponse); + + mockMvc.perform(get("/get_system_prop_vnf_prov_status") + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(expectedResponse)); + } + }