@Test public void testgetAwsNotificationDetails() throws Exception { List<Map<String, Object>> notiList = new ArrayList<>(); PageFilterRequest pageFilterRequest = new PageFilterRequest(); pageFilterRequest.setFrom(1); pageFilterRequest.setSize(1); pageFilterRequest.setSearchText("pacman"); pageFilterRequest.setFilter(null); pageFilterRequest.getFilter(); pageFilterRequest.getFrom(); pageFilterRequest.getSize(); pageFilterRequest.getSearchText(); when(service.getNotificationDetails(anyString(), anyObject(), anyString())).thenReturn(notiList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj0 = controller.getAwsNotificationDetails(pageFilterRequest, "a1"); assertTrue(responseObj0.getStatusCode() == HttpStatus.OK); Map<String, Object> notiMap1 = new HashMap<>(); notiMap1.put("name", "x"); notiMap1.put("value", "y"); notiList.add(notiMap1); Map<String, Object> notiMap2 = new HashMap<>(); notiMap2.put("name", "p"); notiMap2.put("value", "q"); notiList.add(notiMap2); Map<String, Object> notiMap3 = new HashMap<>(); notiMap3.put("name", "a"); notiMap3.put("value", "b"); notiList.add(notiMap3); when(service.getNotificationDetails(anyString(), anyObject(), anyString())).thenReturn(notiList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj1 = controller.getAwsNotificationDetails(pageFilterRequest, "a1"); assertTrue(responseObj1.getStatusCode() == HttpStatus.OK); ResponseEntity<Object> responseObj2 = controller.getAwsNotificationDetails(pageFilterRequest, ""); assertTrue(responseObj2.getStatusCode() == HttpStatus.EXPECTATION_FAILED); pageFilterRequest.setFrom(-1); ResponseEntity<Object> responseObj3 = controller.getAwsNotificationDetails(pageFilterRequest, "a1"); assertTrue(responseObj3.getStatusCode() == HttpStatus.EXPECTATION_FAILED); pageFilterRequest.setFrom(18); ResponseEntity<Object> responseObj4 = controller.getAwsNotificationDetails(pageFilterRequest, "a1"); assertTrue(responseObj4.getStatusCode() == HttpStatus.EXPECTATION_FAILED); pageFilterRequest.setFrom(1); pageFilterRequest.setSize(8); ResponseEntity<Object> responseObj5 = controller.getAwsNotificationDetails(pageFilterRequest, "a1"); assertTrue(responseObj5.getStatusCode() == HttpStatus.OK); pageFilterRequest.setFrom(1); pageFilterRequest.setSize(-1); ResponseEntity<Object> responseObj6 = controller.getAwsNotificationDetails(pageFilterRequest, "a1"); assertTrue(responseObj6.getStatusCode() == HttpStatus.OK); }
@RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST) public ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request, @PathVariable(name = "resourceId", required = true) String instanceId) { Map<String, Object> response = new HashMap<>(); if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } int from = request.getFrom(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } int size = request.getSize(); Map<String, String> filter = request.getFilter(); List<Map<String, Object>> detailInfo = new ArrayList<>(); try { detailInfo = assetService.getNotificationDetails(instanceId, filter, request.getSearchText()); response.put("response", detailInfo); if (detailInfo.isEmpty()) { throw new NoDataFoundException("No data found"); } if (from >= detailInfo.size()) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_EXCEEDS)); } int endIndex = 0; if ((from + size) > detailInfo.size()) { endIndex = detailInfo.size(); } else { endIndex = from + size; } if (endIndex == 0) { endIndex = detailInfo.size(); } List<Map<String, Object>> subDetailList = detailInfo.subList(from, endIndex); return ResponseUtils.buildSucessResponse(subDetailList); } catch (Exception e) { LOGGER.error("Error in getAwsNotificationDetails ",e); List<Map<String, Object>> subDetailList = new ArrayList<>(); return ResponseUtils.buildSucessResponse(subDetailList); } }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST) public ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request, @PathVariable(name = "resourceId", required = true) String instanceId) { Map<String, Object> response = new HashMap<>(); if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } int from = request.getFrom(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } int size = request.getSize(); Map<String, String> filter = request.getFilter(); List<Map<String, Object>> detailInfo = new ArrayList<>(); try { detailInfo = assetService.getNotificationDetails(instanceId, filter, request.getSearchText()); response.put("response", detailInfo); if (detailInfo.isEmpty()) { throw new NoDataFoundException("No data found"); } if (from >= detailInfo.size()) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_EXCEEDS)); } int endIndex = 0; if ((from + size) > detailInfo.size()) { endIndex = detailInfo.size(); } else { endIndex = from + size; } if (endIndex == 0) { endIndex = detailInfo.size(); } List<Map<String, Object>> subDetailList = detailInfo.subList(from, endIndex); return ResponseUtils.buildSucessResponse(subDetailList); } catch (Exception e) { LOGGER.error("Error in getAwsNotificationDetails ",e); List<Map<String, Object>> subDetailList = new ArrayList<>(); return ResponseUtils.buildSucessResponse(subDetailList); } } }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST) public ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request, @PathVariable(name = "resourceId", required = true) String instanceId) { Map<String, Object> response = new HashMap<>(); if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } int from = request.getFrom(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } int size = request.getSize(); Map<String, String> filter = request.getFilter(); List<Map<String, Object>> detailInfo = new ArrayList<>(); try { detailInfo = assetService.getNotificationDetails(instanceId, filter, request.getSearchText()); response.put("response", detailInfo); if (detailInfo.isEmpty()) { throw new NoDataFoundException("No data found"); } if (from >= detailInfo.size()) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_EXCEEDS)); } int endIndex = 0; if ((from + size) > detailInfo.size()) { endIndex = detailInfo.size(); } else { endIndex = from + size; } if (endIndex == 0) { endIndex = detailInfo.size(); } List<Map<String, Object>> subDetailList = detailInfo.subList(from, endIndex); return ResponseUtils.buildSucessResponse(subDetailList); } catch (Exception e) { LOGGER.error("Error in getAwsNotificationDetails ",e); List<Map<String, Object>> subDetailList = new ArrayList<>(); return ResponseUtils.buildSucessResponse(subDetailList); } }  }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST) public ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request, @PathVariable(name = "resourceId", required = true) String instanceId) { Map<String, Object> response = new HashMap<>(); if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } int from = request.getFrom(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } int size = request.getSize(); Map<String, String> filter = request.getFilter(); List<Map<String, Object>> detailInfo = new ArrayList<>(); try { detailInfo = assetService.getNotificationDetails(instanceId, filter, request.getSearchText()); response.put("response", detailInfo); if (detailInfo.isEmpty()) { throw new NoDataFoundException("No data found"); } if (from >= detailInfo.size()) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_EXCEEDS)); } int endIndex = 0; if ((from + size) > detailInfo.size()) { endIndex = detailInfo.size(); } else { endIndex = from + size; } if (endIndex == 0) { endIndex = detailInfo.size(); } List<Map<String, Object>> subDetailList = detailInfo.subList(from, endIndex); return ResponseUtils.buildSucessResponse(subDetailList); } catch (Exception e) { LOGGER.error("Error in getAwsNotificationDetails ",e); List<Map<String, Object>> subDetailList = new ArrayList<>(); return ResponseUtils.buildSucessResponse(subDetailList); } }  @GetMapping(value = "/v1/{assetGroup}/ec2/{resourceId}/cpu-utilization") ResponseEntity<Object> getCPUUtilizationByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/disk-utilization", method = RequestMethod.GET) ResponseEntity<Object> getDiskUtilizationByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/installed-softwares", method = RequestMethod.GET) ResponseEntity<Object> getInstalledSoftwareDetailsByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId,
            @RequestParam(name = "from", required = false) Integer from,
            @RequestParam(name = "size", required = false) Integer size,
            @RequestParam(name = "searchtext", required = false) String searchText); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/open-ports", method = RequestMethod.GET) ResponseEntity<Object> getOpenPortsByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId,
            @RequestParam(name = "from", required = false) Integer from,
            @RequestParam(name = "size", required = false) Integer size,
            @RequestParam(name = "searchtext", required = false) String searchText); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/summary", method = RequestMethod.GET) ResponseEntity<Object> getAwsNotificationSummary(
            @PathVariable(name = "resourceId", required = true) String instanceId); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST) ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request,
            @PathVariable(name = "resourceId", required = true) String instanceId); @ApiOperation(httpMethod = "GET", value = "Get the creator details for a particular resource") @GetMapping(value = "/v1/{assetGroup}/{resourceType}/{resourceId}/creatordetails") ResponseEntity<Object> getEc2CreatorDetail(
            @PathVariable(name = "assetGroup", required = true) String assetGroup,
            @PathVariable(name = "resourceType", required = true) String resourceType,
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the ad group details for a ec2 instance") @GetMapping(value = "/v1/{assetGroup}/ec2/{resourceId}/ad-groups") ResponseEntity<Object> getAdGroupsDetail(@PathVariable(name = "assetGroup", required = true) String ag,
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the details from a particular data source for a particular resource") @GetMapping(value = "v1/{assetGroup}/{resourceType}/{resourceId}/details") ResponseEntity<Object> getEc2ResourceDetail(@PathVariable(name = "assetGroup", required = true) String ag,
            @PathVariable(name = "resourceType", required = true) String resourceType,
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the average cost and total cost for an EC2 resource") @GetMapping(value = "v1/{assetGroup}/ec2/{resourceId}/cost") ResponseEntity<Object> getEc2ResourceSummary(
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the summary from AWS for a particular resource") @GetMapping(value = "v1/{assetGroup}/{resourceType}/{resourceId}/summary") ResponseEntity<Object> getEc2ResourceSummary(@PathVariable(name = "assetGroup", required = true) String ag,
            @PathVariable(name = "resourceType", required = true) String resourceType,
            @PathVariable(name = "resourceId", required = true) String resourceId); }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST) public ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request, @PathVariable(name = "resourceId", required = true) String instanceId) { Map<String, Object> response = new HashMap<>(); if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } int from = request.getFrom(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } int size = request.getSize(); Map<String, String> filter = request.getFilter(); List<Map<String, Object>> detailInfo = new ArrayList<>(); try { detailInfo = assetService.getNotificationDetails(instanceId, filter, request.getSearchText()); response.put("response", detailInfo); if (detailInfo.isEmpty()) { throw new NoDataFoundException("No data found"); } if (from >= detailInfo.size()) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_EXCEEDS)); } int endIndex = 0; if ((from + size) > detailInfo.size()) { endIndex = detailInfo.size(); } else { endIndex = from + size; } if (endIndex == 0) { endIndex = detailInfo.size(); } List<Map<String, Object>> subDetailList = detailInfo.subList(from, endIndex); return ResponseUtils.buildSucessResponse(subDetailList); } catch (Exception e) { LOGGER.error("Error in getAwsNotificationDetails ",e); List<Map<String, Object>> subDetailList = new ArrayList<>(); return ResponseUtils.buildSucessResponse(subDetailList); } }  @GetMapping(value = "/v1/{assetGroup}/ec2/{resourceId}/cpu-utilization") ResponseEntity<Object> getCPUUtilizationByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/disk-utilization", method = RequestMethod.GET) ResponseEntity<Object> getDiskUtilizationByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/installed-softwares", method = RequestMethod.GET) ResponseEntity<Object> getInstalledSoftwareDetailsByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId,
            @RequestParam(name = "from", required = false) Integer from,
            @RequestParam(name = "size", required = false) Integer size,
            @RequestParam(name = "searchtext", required = false) String searchText); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/open-ports", method = RequestMethod.GET) ResponseEntity<Object> getOpenPortsByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId,
            @RequestParam(name = "from", required = false) Integer from,
            @RequestParam(name = "size", required = false) Integer size,
            @RequestParam(name = "searchtext", required = false) String searchText); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/summary", method = RequestMethod.GET) ResponseEntity<Object> getAwsNotificationSummary(
            @PathVariable(name = "resourceId", required = true) String instanceId); @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST) ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request,
            @PathVariable(name = "resourceId", required = true) String instanceId); @ApiOperation(httpMethod = "GET", value = "Get the creator details for a particular resource") @GetMapping(value = "/v1/{assetGroup}/{resourceType}/{resourceId}/creatordetails") ResponseEntity<Object> getEc2CreatorDetail(
            @PathVariable(name = "assetGroup", required = true) String assetGroup,
            @PathVariable(name = "resourceType", required = true) String resourceType,
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the ad group details for a ec2 instance") @GetMapping(value = "/v1/{assetGroup}/ec2/{resourceId}/ad-groups") ResponseEntity<Object> getAdGroupsDetail(@PathVariable(name = "assetGroup", required = true) String ag,
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the details from a particular data source for a particular resource") @GetMapping(value = "v1/{assetGroup}/{resourceType}/{resourceId}/details") ResponseEntity<Object> getEc2ResourceDetail(@PathVariable(name = "assetGroup", required = true) String ag,
            @PathVariable(name = "resourceType", required = true) String resourceType,
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the average cost and total cost for an EC2 resource") @GetMapping(value = "v1/{assetGroup}/ec2/{resourceId}/cost") ResponseEntity<Object> getEc2ResourceSummary(
            @PathVariable(name = "resourceId", required = true) String resourceId); @ApiOperation(httpMethod = "GET", value = "Get the summary from AWS for a particular resource") @GetMapping(value = "v1/{assetGroup}/{resourceType}/{resourceId}/summary") ResponseEntity<Object> getEc2ResourceSummary(@PathVariable(name = "assetGroup", required = true) String ag,
            @PathVariable(name = "resourceType", required = true) String resourceType,
            @PathVariable(name = "resourceId", required = true) String resourceId);  }