From bf031e31e6b6bb1567f938190c35040866c2cf4a Mon Sep 17 00:00:00 2001 From: Michal Kabaj Date: Wed, 21 Aug 2019 15:07:05 +0200 Subject: AaiController tests - improved existing testcases by including spring integration - added new testcases Change-Id: I64abbd91b9c9fc7cdc27ca25f90954b29f065096 Issue-ID: VID-478 Signed-off-by: Michal Kabaj --- .../java/org/onap/vid/controller/AaiController.java | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'vid-app-common/src/main') diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java index eee2acc51..2b3ad60ea 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java @@ -77,6 +77,7 @@ public class AaiController extends RestrictedBaseController { private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiController.class); private static final String FROM_APP_ID = "VidAaiController"; + private final ObjectMapper objectMapper = new ObjectMapper(); private AaiService aaiService; private AAIRestInterface aaiRestInterface; @@ -157,7 +158,7 @@ public class AaiController extends RestrictedBaseController { throws IOException { ResponseEntity responseEntity; if (aaiResponseData.getHttpCode() == 200) { - responseEntity = new ResponseEntity<>(new ObjectMapper().writeValueAsString(aaiResponseData.getT()), + responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(aaiResponseData.getT()), HttpStatus.OK); } else { responseEntity = new ResponseEntity<>(aaiResponseData.getErrorMessage(), @@ -225,7 +226,6 @@ public class AaiController extends RestrictedBaseController { @RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getFullSubscriberList(HttpServletRequest request) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); ResponseEntity responseEntity; RoleValidator roleValidator = RoleValidator.by(roleProvider.getUserRoles(request)); SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator); @@ -270,17 +270,14 @@ public class AaiController extends RestrictedBaseController { @RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET) public ResponseEntity getSubscriberDetails(HttpServletRequest request, @PathVariable("subscriberId") String subscriberId, @RequestParam(value="omitServiceInstances", required = false, defaultValue = "false") boolean omitServiceInstances) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - ResponseEntity responseEntity; List roles = roleProvider.getUserRoles(request); RoleValidator roleValidator = RoleValidator.by(roles); - AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator, featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH) && omitServiceInstances); - String httpMessage = subscriberData.getT() != null ? - objectMapper.writeValueAsString(subscriberData.getT()) : - subscriberData.getErrorMessage(); + AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator, + featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH) && omitServiceInstances); + String httpMessage = subscriberData.getT() != null ? objectMapper.writeValueAsString(subscriberData.getT()) : subscriberData.getErrorMessage(); - responseEntity = new ResponseEntity<>(httpMessage, HttpStatus.valueOf(subscriberData.getHttpCode())); - return responseEntity; + return new ResponseEntity<>(httpMessage, + HttpStatus.valueOf(subscriberData.getHttpCode())); } @RequestMapping(value = "/search_service_instances", method = RequestMethod.GET) @@ -289,7 +286,6 @@ public class AaiController extends RestrictedBaseController { @RequestParam(value = "serviceInstanceIdentifier", required = false) String instanceIdentifier, @RequestParam(value = "project", required = false) List projects, @RequestParam(value = "owningEntity", required = false) List owningEntities) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); ResponseEntity responseEntity; List roles = roleProvider.getUserRoles(request); @@ -354,7 +350,6 @@ public class AaiController extends RestrictedBaseController { @RequestMapping(value = "/aai_get_network_collection_details/{serviceInstanceId}", method = RequestMethod.GET) public ResponseEntity getNetworkCollectionDetails( @PathVariable("serviceInstanceId") String serviceInstanceId) throws IOException { - com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); AaiResponse resp = aaiService.getNetworkCollectionDetails(serviceInstanceId); String httpMessage = resp.getT() != null ? @@ -367,7 +362,6 @@ public class AaiController extends RestrictedBaseController { public ResponseEntity getInstanceGroupsByCloudRegion(@PathVariable("cloudOwner") String cloudOwner, @PathVariable("cloudRegionId") String cloudRegionId, @PathVariable("networkFunction") String networkFunction) throws IOException { - com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); AaiResponse resp = aaiService .getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction); @@ -424,7 +418,6 @@ public class AaiController extends RestrictedBaseController { ResponseEntity responseEntity; try { - ObjectMapper objectMapper = new ObjectMapper(); List roles = roleProvider.getUserRoles(request); RoleValidator roleValidator = RoleValidator.by(roles); AaiResponse response = aaiService -- cgit 1.2.3-korg