+ public void setUp() {
+ aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper,
+ featureManager);
+ when(roleProvider.getUserRolesValidator(any())).thenReturn(roleValidator);
+ mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build();
+ }
+
+ @Test
+ public void getAicZoneForPnf_shouldReturnOKResponse() throws Exception {
+ String globalCustomerId = "testCustomerId";
+ String serviceType = "testServiceType";
+ String serviceId = "testServiceId";
+ String expectedResponseBody = "OK_RESPONSE";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, null, HttpStatus.OK.value());
+ 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)));
+ }
+
+ @Test
+ public void getInstanceGroupsByVnfInstanceId_shouldReturnOKResponse() throws Exception {
+ String vnfInstanceId = "testVndInstanceId";
+ String expectedResponseBody = "OK_RESPONSE";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, null, HttpStatus.OK.value());
+ 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)));
+ }
+
+ @Test
+ public void doGetServiceInstance_shouldFetchServiceInstance_byServiceInstanceId() throws Exception {
+ String serviceInstanceId = "testServiceInstanceId";
+ String serviceInstanceType = "Service Instance Id";
+ 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(
+ "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));
+ }
+
+ @Test
+ public void doGetServiceInstance_shouldFetchServiceInstance_byServiceInstanceName() throws Exception {
+ String serviceInstanceId = "testServiceInstanceId";
+ String serviceInstanceType = "testServiceInstanceType";
+ 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(
+ "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));
+ }
+
+ @Test
+ public void doGetServices_shouldReturnOkResponse() throws Exception {
+ String globalCustomerId = "testGlobalCustomerId";
+ String serviceSubscriptionId = "testServiceSubscriptionId";
+ 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(
+ "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));
+ }
+
+ @Test
+ public void doGetServices_shouldReturnInternalServerError_forEmptyResponse() throws Exception {
+ String globalCustomerId = "testGlobalCustomerId";
+ 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);
+
+ 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));
+ }
+
+ @Test
+ public void getPortMirroringConfigData_givenIds_shouldReturnConfigDataMappedById() throws Exception {
+ PortMirroringConfigDataOk okConfigData = new PortMirroringConfigDataOk("foo");
+ PortMirroringConfigDataError errorConfigData = new PortMirroringConfigDataError("bar", "{ baz: qux }");
+ Map<String, PortMirroringConfigData> expectedJson = ImmutableMap.of(
+ 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)));
+ }
+
+ @Test
+ public void getPortMirroringSourcePorts_givenIds_shouldReturnPortDetailsMappedById() throws Exception {
+ 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);
+ 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())));
+ }
+
+ @Test
+ public void getNodeTemplateInstances_givenParams_shouldReturnCorrectResponse() throws Exception {
+ String globalCustomerId = "testCustomerId";
+ String serviceType = "testServiceType";
+ String modelVersionId = UUID.nameUUIDFromBytes("modelVersionId".getBytes()).toString();
+ String modelInvariantId = UUID.nameUUIDFromBytes("modelInvariantId".getBytes()).toString();
+ String cloudRegion = "testRegion";
+ String urlTemplate = "/aai_get_vnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}";
+ String expectedResponseBody = "myResponse";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, "", HttpStatus.OK.value());
+ given(aaiService
+ .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));
+ }
+
+ @Test
+ public void getAicZones_shouldReturnAaiZones_whenAaiHttpStatusIsOK() throws Exception {
+ AicZones aicZones = new AicZones(ImmutableList.of(new Zone("TEST_ZONE_ID", "TEST_ZONE_NAME")));
+ 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)));
+ }
+
+ @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()));
+
+ mockMvc.perform(get("/aai_get_aic_zones")
+ .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();
+ 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)));
+ }
+
+ @Test
+ public void getSpecificPnf_shouldHandleAAIServiceException() throws Exception {
+ String pnfId = "MyPnfId";
+ String expectedErrorMessage = "AAI Service Error";
+ 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));
+ }
+
+ public void getPNFInstances_shouldReturnOKResponseFromAAIService() throws Exception {
+ String globalCustomerId = "testCustomerId";
+ String serviceType = "testServiceType";
+ String modelVersionId = UUID.nameUUIDFromBytes("modelVersionId".getBytes()).toString();
+ String modelInvariantId = UUID.nameUUIDFromBytes("modelInvariantId".getBytes()).toString();
+ String cloudRegion = "testRegion";
+ String equipVendor = "testVendor";
+ String equipModel = "model123";
+ String urlTemplate = "/aai_get_pnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}/{equipVendor}/{equipModel}";
+ String expectedResponseBody = "myResponse";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, "", HttpStatus.OK.value());
+
+ given(aaiService
+ .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));
+ }
+
+ @Test
+ public void getVersionByInvariantId_shouldReturnOKResponse() throws Exception {
+ String expectedResponse = "OKResponse";
+ VersionByInvariantIdsRequest request = new VersionByInvariantIdsRequest();
+ request.versions = ImmutableList.of("ver1", "ver2");
+ Response response = mock(Response.class);
+ given(response.readEntity(String.class)).willReturn(expectedResponse);
+ given(aaiService
+ .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));
+ }
+
+ @Test
+ public void getSubscriberDetails_shouldOmitServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsTrue()
+ throws Exception {
+ boolean isFeatureActive = true;
+ boolean omitServiceInstances = true;
+
+ 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(RoleValidator.class),
+ 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)));
+ }
+
+ @Test
+ public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsFalse()
+ throws Exception {
+ boolean isFeatureActive = true;
+ boolean omitServiceInstances = false;
+
+ getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);
+ }
+
+ @Test
+ public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsTrue()
+ throws Exception {
+ boolean isFeatureActive = false;
+ boolean omitServiceInstances = true;
+
+ getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);