diff options
author | Ittay Stern <ittay.stern@att.com> | 2019-09-12 14:11:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-09-12 14:11:27 +0000 |
commit | ecd0453d3ca7c54d32af7b033f8098e25ca4392b (patch) | |
tree | 0ca21081953862dc813fe57b2452c028d080dcb6 /vid-app-common/src | |
parent | 76a44c4f838747b01ef819d2d673b5f680780f3f (diff) | |
parent | c4814252e8ef58dde843824d1c4d57ea708a961e (diff) |
Merge "Reduce vnf data response from A&AI in change management flows"
Diffstat (limited to 'vid-app-common/src')
9 files changed, 482 insertions, 109 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java index c43779df1..c82f5485e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java @@ -27,10 +27,15 @@ import static java.util.stream.Collectors.toMap; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import java.io.IOException; +import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLEncoder; @@ -44,10 +49,12 @@ import javax.inject.Inject; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.http.HttpStatus; import org.apache.http.client.utils.URIBuilder; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -281,6 +288,36 @@ public class AaiClient implements AaiClientInterface { .collect(toMap(SimpleResult::getNodeType, SimpleResult::getProperties)); } + @Override + public AaiResponse getVnfsByParamsForChangeManagement(String subscriberId, String serviceType, @Nullable String nfRole, + @Nullable String cloudRegion) { + String payloadAsString = ""; + ResponseWithRequestInfo response; + ImmutableMap<String, Serializable> payload = getMapForAAIQueryByParams(subscriberId, serviceType, + nfRole, cloudRegion); + try { + payloadAsString = JACKSON_OBJECT_MAPPER.writeValueAsString(payload); + } catch (JsonProcessingException e) { + logger.error(e.getMessage()); + ExceptionUtils.rethrow(e); + } + response = doAaiPut(QUERY_FORMAT_SIMPLE, payloadAsString, false, false); + AaiResponseWithRequestInfo aaiResponse = processAaiResponse(response, JsonNode.class, false); + verifyAaiResponseValidityOrThrowExc(aaiResponse, aaiResponse.getAaiResponse().getHttpCode()); + return aaiResponse.getAaiResponse(); + } + + private ImmutableMap<String, Serializable> getMapForAAIQueryByParams(String subscriberId, + String serviceType, @Nullable String nfRole, @Nullable String cloudRegion) { + String nfRoleParam = nfRole != null ? "?nfRole=" + nfRole : ""; + String query = "query/vnfs-fromServiceInstance-filter" + nfRoleParam; + return ImmutableMap.of( + "start", ImmutableList + .of("/business/customers/customer/" + subscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances"), + "query", query + ); + } + private boolean isResourceExistByStatusCode(ResponseWithRequestInfo responseWithRequestInfo) { // 200 - is found // 404 - resource not found @@ -315,19 +352,20 @@ public class AaiClient implements AaiClientInterface { } final AaiResponseWithRequestInfo<T> aaiResponse = processAaiResponse(responseWithRequestInfo, clz, VidObjectMapperType.FASTERXML, true); + verifyAaiResponseValidityOrThrowExc(aaiResponse, responseWithRequestInfo.getResponse().getStatus()); + return aaiResponse.getAaiResponse().getT(); + } + private void verifyAaiResponseValidityOrThrowExc(AaiResponseWithRequestInfo aaiResponse, int httpCode) { if (aaiResponse.getAaiResponse().getHttpCode() > 399 || aaiResponse.getAaiResponse().getT() == null) { throw new ExceptionWithRequestInfo(aaiResponse.getHttpMethod(), - aaiResponse.getRequestedUrl(), - aaiResponse.getRawData(), - responseWithRequestInfo.getResponse().getStatus(), - new InvalidAAIResponseException(aaiResponse.getAaiResponse())); + aaiResponse.getRequestedUrl(), + aaiResponse.getRawData(), + httpCode, + new InvalidAAIResponseException(aaiResponse.getAaiResponse())); } - - return aaiResponse.getAaiResponse().getT(); } - private String getUrlFromLIst(String url, String paramKey, List<String> params){ int i = 0; for(String param: params){ diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java index 1350461b0..8c3c66d17 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java @@ -21,6 +21,10 @@ package org.onap.vid.aai; import com.fasterxml.jackson.databind.JsonNode; +import java.net.URI; +import java.util.List; +import java.util.Map; +import javax.ws.rs.core.Response; import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; import org.onap.vid.aai.model.AaiGetPnfs.Pnf; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; @@ -32,11 +36,6 @@ import org.onap.vid.model.SubscriberList; import org.onap.vid.services.ProbeInterface; import org.springframework.http.HttpMethod; -import javax.ws.rs.core.Response; -import java.net.URI; -import java.util.List; -import java.util.Map; - /** * Created by Oren on 7/4/17. */ @@ -103,4 +102,6 @@ public interface AaiClientInterface extends ProbeInterface { void resetCache(String cacheName); Map<String, Properties> getCloudRegionAndTenantByVnfId(String vnfId); + + AaiResponse getVnfsByParamsForChangeManagement(String subscriberId, String serviceType, String nfRole, String cloudRegion); } diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java index e0d211c24..d1f7a97b5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java @@ -20,7 +20,9 @@ package org.onap.vid.controller; +import java.util.List; import java.util.stream.Collectors; +import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.onap.vid.aai.AaiClientInterface; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; @@ -29,15 +31,20 @@ import org.onap.vid.aai.model.Permissions; import org.onap.vid.model.aaiTree.Network; import org.onap.vid.model.aaiTree.RelatedVnf; import org.onap.vid.model.aaiTree.VpnBinding; +import org.onap.vid.properties.Features; import org.onap.vid.roles.RoleProvider; import org.onap.vid.services.AaiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.togglz.core.manager.FeatureManager; /** * Controller to handle a&ai new requests. @@ -49,12 +56,14 @@ public class AaiController2 extends VidRestrictedBaseController { private final AaiService aaiService; private final RoleProvider roleProvider; private final AaiClientInterface aaiClient; + private final FeatureManager featureManager; @Autowired - public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient) { + public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient, FeatureManager featureManager) { this.aaiService = aaiService; this.roleProvider = roleProvider; this.aaiClient = aaiClient; + this.featureManager = featureManager; } @RequestMapping(value = "/aai_get_homing_by_vfmodule/{vnfInstanceId}/{vfModuleId}", method = RequestMethod.GET) @@ -123,4 +132,16 @@ public class AaiController2 extends VidRestrictedBaseController { public ModelVer getNewestModelVersionByInvariant(@PathVariable("invariantId") String invariantId) { return aaiService.getNewestModelVersionByInvariantId(invariantId); } + + @GetMapping(value = "/get_vnf_data_by_globalid_and_service_type/{globalCustomerId}/{serviceType}") + public Object getVnfDataByGlobalIdAndServiceType( + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType, + @RequestParam(name="nfRole", required = false) String nfRole, + @RequestParam(name="cloudRegion", required = false) String cloudRegion) { + if (featureManager.isActive(Features.FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG)){ + return aaiClient.getVnfsByParamsForChangeManagement(globalCustomerId, serviceType, nfRole, cloudRegion).getT(); + } + return aaiService.getVNFData(globalCustomerId, serviceType).getT(); + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java index 394fc9cd4..9abf68bca 100644 --- a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java +++ b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java @@ -74,6 +74,7 @@ public enum Features implements Feature { FLAG_PNP_INSTANTIATION, FLAG_HANDLE_SO_WORKFLOWS, FLAG_CREATE_ERROR_REPORTS, + FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG, FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT, FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH, ; diff --git a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties index 70eaae964..8438172e3 100644 --- a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties +++ b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties @@ -32,4 +32,5 @@ FLAG_1810_AAI_LOCAL_CACHE = true FLAG_1902_NEW_VIEW_EDIT= false FLAG_EXP_USE_DEFAULT_HOST_NAME_VERIFIER = false FLAG_1902_VNF_GROUPING = true -FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH=false
\ No newline at end of file +FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH=false +FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG = false 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 7c08e942a..9629e4634 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 @@ -137,6 +137,23 @@ public class AaiClientTest { }; } + @Test + public void testAaiPutCustomQueryByParams() { + String globalCustomerId = "globalCustomerId1-360-as988q"; + String serviceType = "TEST1-360"; + String nfRole = "test360"; + String queryFormat = "query?format=simple"; + final ResponseWithRequestInfo mockedResponseWithRequestInfo = mockedResponseWithRequestInfo(Response.Status.OK, + TestUtils.readFileAsString("/payload_jsons/changeManagement/get_vnf_data_by_globalid_and_service_type_reduced_response.json"), + "query?format=simple&Mock=True", + HttpMethod.PUT); + when(aaiClientMock.getVnfsByParamsForChangeManagement(anyString(), anyString(),anyString(), nullable(String.class))).thenCallRealMethod(); + when(aaiClientMock.doAaiPut(eq(queryFormat), anyString(), anyBoolean(), anyBoolean())).thenReturn(mockedResponseWithRequestInfo); + AaiResponse response = aaiClientMock.getVnfsByParamsForChangeManagement(globalCustomerId, serviceType, nfRole, null); + verify(aaiClientMock).doAaiPut(anyString(), anyString(),anyBoolean(),anyBoolean()); + response.toString(); + } + @Test(dataProvider = "logicalLinkData") public void getLogicalLink_Link_Is_Empty(String link, String expectedUrl) { @@ -518,7 +535,7 @@ public class AaiClientTest { } @Test(expectedExceptions = GenericUncheckedException.class, expectedExceptionsMessageRegExp = "A&AI has no homing data associated to vfModule 'vfModuleId' of vnf 'vnfInstanceId'") - public void getVfMoudule_Homing_Arguments_Are_Valid_But_Not_Exists() { + public void getVfModule_Homing_Arguments_Are_Valid_But_Not_Exists() { when(aaiClientMock.getHomingDataByVfModule(any(String.class), any(String.class))).thenCallRealMethod(); Response generalEmptyResponse = mock(Response.class); @@ -536,7 +553,7 @@ public class AaiClientTest { } @Test(dataProvider = "invalidDataId", expectedExceptions = GenericUncheckedException.class, expectedExceptionsMessageRegExp = "Failed to retrieve homing data associated to vfModule from A&AI, VNF InstanceId or VF Module Id is missing.") - public void getVfMoudule_Homing_Arguments_Are_Empty_Or_Null(String data) { + public void getVfModule_Homing_Arguments_Are_Empty_Or_Null(String data) { when(aaiClientMock.getHomingDataByVfModule(any(), any())).thenCallRealMethod(); aaiClientMock.getHomingDataByVfModule(data, data); } 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..3e38ba883 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 @@ -88,7 +88,6 @@ public class AaiControllerTest { private RoleProvider roleProvider; @Mock private SystemPropertiesWrapper systemPropertiesWrapper; - @Mock private FeatureManager featureManager; @@ -98,7 +97,7 @@ public class AaiControllerTest { @Before public void setUp() { aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper, - featureManager); + featureManager); mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build(); } @@ -112,12 +111,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 +127,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 +143,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 +166,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 +189,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 +212,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 +234,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 @@ -254,18 +253,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 @@ -279,15 +278,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 @@ -306,7 +305,7 @@ public class AaiControllerTest { 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) @@ -363,8 +362,8 @@ 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, @@ -383,7 +382,7 @@ 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") @@ -396,7 +395,7 @@ public class AaiControllerTest { @Test public void getSubscriberDetails_shouldOmitServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsTrue() - throws Exception { + throws Exception { boolean isFeatureActive = true; boolean omitServiceInstances = true; @@ -405,8 +404,8 @@ 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) @@ -419,7 +418,7 @@ public class AaiControllerTest { @Test public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsFalse() - throws Exception { + throws Exception { boolean isFeatureActive = true; boolean omitServiceInstances = false; @@ -428,7 +427,7 @@ public class AaiControllerTest { @Test public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsTrue() - throws Exception { + throws Exception { boolean isFeatureActive = false; boolean omitServiceInstances = true; diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java index 36af92c0c..ac3da50ab 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java @@ -55,7 +55,7 @@ public class ServicePermissionsTest { when(roleProvider.getUserRolesValidator(any())).thenReturn(roleValidator); when(roleValidator.isServicePermitted(subscriberId, serviceType)).thenReturn(expected); - AaiController2 aaiController2 = new AaiController2(null, roleProvider, null); + AaiController2 aaiController2 = new AaiController2(null, roleProvider, null, null); Permissions permissions = aaiController2.servicePermissions(unimportantRequest(), subscriberId, serviceType); assertThat(permissions, is(new Permissions(expected))); diff --git a/vid-app-common/src/test/resources/payload_jsons/changeManagement/get_vnf_data_by_globalid_and_service_type_reduced_response.json b/vid-app-common/src/test/resources/payload_jsons/changeManagement/get_vnf_data_by_globalid_and_service_type_reduced_response.json new file mode 100644 index 000000000..d9a120a49 --- /dev/null +++ b/vid-app-common/src/test/resources/payload_jsons/changeManagement/get_vnf_data_by_globalid_and_service_type_reduced_response.json @@ -0,0 +1,295 @@ +{ + "results": [ + { + "service-instance": { + "service-instance-id": "serviceInstanceID1-369-as988q", + "service-instance-name": "EUd8Test", + "service-type": "xBoJHJbWTest", + "service-role": "sc7OWTest", + "environment-context": "O7OVp5Test", + "workload-context": "VmnxNeJIgWq7HTest", + "model-invariant-id": "modelInvariantValue2-369 -as988q", + "model-version-id": "modelVersionKey2-369-as988q", + "widget-model-id": "HT7KA2FoRKH3cTest", + "widget-model-version": "CsGp5Test", + "bandwidth-total": "1Yijkk1Test", + "vhn-portal-url": "40PzTest", + "service-instance-location-id": "zcAaHJTAt5Hj8Test", + "resource-version": "1563820653329", + "selflink": "mZP2EVvwwHnlTest", + "orchestration-status": "6QvhzNgLudLBTest", + "relationship-list": { + "relationship": [ + { + "related-to": "generic-vnf", + "relationship-label": "org.onap.relationships.inventory.ComposedOf", + "related-link": "/aai/v17/network/generic-vnfs/generic-vnf/test-gvnf2-369-as988q", + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "test-gvnf2-369-as988q" + } + ], + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "test-name2-gvnf-369" + } + ] + }, + { + "related-to": "generic-vnf", + "relationship-label": "org.onap.relationships.inventory.ComposedOf", + "related-link": "/aai/v17/network/generic-vnfs/generic-vnf/test-gvnf1-369-as988q", + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "test-gvnf1-369-as988q" + } + ], + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "test-name-gvnf-369" + } + ] + } + ] + } + } + }, + { + "model-ver": { + "model-version-id": "modelVersionKey2-369-as988q", + "model-name": "vnfc8", + "model-version": "1.1", + "resource-version": "1563820653007" + } + }, + { + "model": { + "model-invariant-id": "modelInvariantValue2-369-as988q", + "model-type": "widget3", + "resource-version": "1563820652703", + "model-vers": { + "model-ver": [ + { + "model-version-id": "modelVersionKey2-369-as988q", + "model-name": "vnfc8", + "model-version": "1.1", + "resource-version": "1563820653007" + } + ] + } + } + }, + { + "generic-vnf": { + "vnf-id": "test-gvnf2-369-as988q", + "vnf-name": "test-name2-gvnf-369", + "vnf-type": "SW", + "service-id": "d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4", + "equipment-role": "UCPE", + "orchestration-status": "created", + "ipv4-oam-address": "12.80.1.18", + "nm-lan-v6-address": "2001:1890:e00e:fffe::33c4", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1563820654611", + "model-invariant-id": "modelInvariantValue-369-as988q", + "model-version-id": "modelVersionKey-369-as988q", + "nf-role": "test360", + "relationship-list": { + "relationship": [ + { + "related-to": "service-instance", + "relationship-label": "org.onap.relationships.inventory.ComposedOf", + "related-link": "/aai/v17/business/customers/customer/globalCustomerId1-369-as988q/service-subscriptions/service-subscription/TEST1-369/service-instances/service-instance/serviceInstanceID1-369-as988q", + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "globalCustomerId1-369-as988q" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "TEST1-369" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "serviceInstanceID1-369-as988q" + } + ], + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "EUd8Test" + } + ] + } + ] + } + } + }, + { + "model-ver": { + "model-version-id": "modelVersionKey-369-as988q", + "model-name": "vnfc8", + "model-version": "1.1", + "resource-version": "1563820652380" + } + }, + { + "model": { + "model-invariant-id": "modelInvariantValue-369-as988q", + "model-type": "service", + "resource-version": "1563820652072", + "model-vers": { + "model-ver": [ + { + "model-version-id": "modelVersionKey-369-as988q", + "model-name": "vnfc8", + "model-version": "1.1", + "resource-version": "1563820652380" + } + ] + } + } + }, + { + "generic-vnf": { + "vnf-id": "test-gvnf1-369-as988q", + "vnf-name": "test-name-gvnf-369", + "vnf-type": "SW", + "service-id": "d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4", + "equipment-role": "UCPE", + "orchestration-status": "created", + "ipv4-oam-address": "12.80.1.18", + "nm-lan-v6-address": "2001:1890:e00e:fffe::33c4", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1563820654296", + "model-invariant-id": "modelInvariantValue-369-as988q", + "model-version-id": "modelVersionKey-369-as988q", + "nf-role": "test360", + "relationship-list": { + "relationship": [ + { + "related-to": "service-instance", + "relationship-label": "org.onap.relationships.inventory.ComposedOf", + "related-link": "/aai/v17/business/customers/customer/globalCustomerId1-369-as988q/service-subscriptions/service-subscription/TEST1-369/service-instances/service-instance/serviceInstanceID1-369-as988q", + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "globalCustomerId1-369-as988q" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "TEST1-369" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "serviceInstanceID1-369-as988q" + } + ], + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "EUd8Test" + } + ] + }, + { + "related-to": "vserver", + "relationship-label": "tosca.relationships.HostedOn", + "related-link": "/aai/v17/cloud-infrastructure/cloud-regions/cloud-region/cloudOwnerKeyValue1-369-as988q/cloudRegionIdKeyValue1-369-as988q/tenants/tenant/tenantID1-369-as988q/vservers/vserver/vserver1-369-test-as988q", + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "cloudOwnerKeyValue1-369-as988q" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "cloudRegionIdKeyValue1-369-as988q" + }, + { + "relationship-key": "tenant.tenant-id", + "relationship-value": "tenantID1-369-as988q" + }, + { + "relationship-key": "vserver.vserver-id", + "relationship-value": "vserver1-369-test-as988q" + } + ], + "related-to-property": [ + { + "property-key": "vserver.vserver-name", + "property-value": "vserver-name11-369-as988q" + } + ] + } + ] + } + } + }, + { + "tenant": { + "tenant-id": "tenantID1-369-as988q", + "tenant-name": "tenant-name1-369-as988q", + "resource-version": "1563820651384", + "vservers": { + "vserver": [ + { + "vserver-id": "vserver1-369-test-as988q", + "vserver-name": "vserver-name11-369-as988q", + "vserver-name2": "vserver-name22-360-as988q", + "prov-status": "ACTIVE", + "vserver-selflink": "TRINITY vserverLink", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1563820654917", + "relationship-list": { + "relationship": [ + { + "related-to": "generic-vnf", + "relationship-label": "tosca.relationships.HostedOn", + "related-link": "/aai/v17/network/generic-vnfs/generic-vnf/test-gvnf1-369-as988q", + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "test-gvnf1-369-as988q" + } + ], + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "test-name-gvnf-369" + } + ] + } + ] + } + } + ] + } + } + }, + { + "cloud-region": { + "cloud-owner": "cloudOwnerKeyValue1-369-as988q", + "cloud-region-id": "cloudRegionIdKeyValue1-369-as988q", + "resource-version": "1563820651058", + "orchestration-disabled": false, + "in-maint": false, + "tenants": { + "tenant": [ + { + "tenant-id": "tenantID1-369-as988q", + "tenant-name": "tenant-name1-369-as988q", + "resource-version": "1563820651384" + } + ] + } + } + } + ] +}
\ No newline at end of file |