@Test public void testgetEc2ResourceSummary1() throws Exception { PolicyViolationApiData violationData = new PolicyViolationApiData(); violationData.setCompliance("75"); String compliance = violationData.getCompliance(); PolicyViolationApi violationSummary = new PolicyViolationApi(); violationSummary.setData(violationData); violationSummary.getData(); violationSummary.setMessage("Compliance Data"); violationSummary.getMessage(); violationSummary.toString(); List<Map<String, Object>> utilList = new ArrayList<>(); Map<String, Object> utilMap = new HashMap<>(); utilMap.put("date", "d1"); utilMap.put("cpu-utilization", 50); utilList.add(utilMap); when(complianceServiceClient.getPolicyViolationSummary(anyString(), anyString(), anyString())) .thenReturn(violationSummary); when(service.getEc2StateDetail(anyString(), anyString())).thenReturn("Started"); when(service.getInstanceCPUUtilization(anyString())).thenReturn(utilList); ReflectionTestUtils.setField(controller, "complianceServiceClient", complianceServiceClient); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj1 = controller.getEc2ResourceSummary("ag", "ec2", "a1"); assertTrue(responseObj1.getStatusCode() == HttpStatus.OK); assertTrue(((Map<String, Object>) responseObj1.getBody()).get("data") != null); doThrow(new NullPointerException()).when(service).getInstanceCPUUtilization(anyString()); ResponseEntity<Object> responseObj2 = controller.getEc2ResourceSummary("ag", "ec2", "a1"); assertTrue(responseObj2.getStatusCode() == HttpStatus.OK); doThrow(new NullPointerException()).when(service).getEc2StateDetail(anyString(),anyString()); ResponseEntity<Object> responseObj3 = controller.getEc2ResourceSummary("ag", "ec2", "a1"); assertTrue(responseObj3.getStatusCode() == HttpStatus.OK); }
@ApiOperation(httpMethod = "GET", value = "Get the average cost and total cost for an EC2 resource") @GetMapping(value = "v1/{assetGroup}/ec2/{resourceId}/cost") public ResponseEntity<Object> getEc2ResourceSummary( @PathVariable(name = "resourceId", required = true) String resourceId) throws DataException { Map<String, Object> dataMap = null; try { dataMap = assetService.getEC2AvgAndTotalCost(resourceId); } catch (Exception e) { LOGGER.error("Error in getEc2ResourceSummary ",e); dataMap = new HashMap<>(); } return ResponseUtils.buildSucessResponse(dataMap); }
AssetDetailController { @ApiOperation(httpMethod = "GET", value = "Get the average cost and total cost for an EC2 resource") @GetMapping(value = "v1/{assetGroup}/ec2/{resourceId}/cost") public ResponseEntity<Object> getEc2ResourceSummary( @PathVariable(name = "resourceId", required = true) String resourceId) throws DataException { Map<String, Object> dataMap = null; try { dataMap = assetService.getEC2AvgAndTotalCost(resourceId); } catch (Exception e) { LOGGER.error("Error in getEc2ResourceSummary ",e); dataMap = new HashMap<>(); } return ResponseUtils.buildSucessResponse(dataMap); } }
AssetDetailController { @ApiOperation(httpMethod = "GET", value = "Get the average cost and total cost for an EC2 resource") @GetMapping(value = "v1/{assetGroup}/ec2/{resourceId}/cost") public ResponseEntity<Object> getEc2ResourceSummary( @PathVariable(name = "resourceId", required = true) String resourceId) throws DataException { Map<String, Object> dataMap = null; try { dataMap = assetService.getEC2AvgAndTotalCost(resourceId); } catch (Exception e) { LOGGER.error("Error in getEc2ResourceSummary ",e); dataMap = new HashMap<>(); } return ResponseUtils.buildSucessResponse(dataMap); }  }
AssetDetailController { @ApiOperation(httpMethod = "GET", value = "Get the average cost and total cost for an EC2 resource") @GetMapping(value = "v1/{assetGroup}/ec2/{resourceId}/cost") public ResponseEntity<Object> getEc2ResourceSummary( @PathVariable(name = "resourceId", required = true) String resourceId) throws DataException { Map<String, Object> dataMap = null; try { dataMap = assetService.getEC2AvgAndTotalCost(resourceId); } catch (Exception e) { LOGGER.error("Error in getEc2ResourceSummary ",e); dataMap = new HashMap<>(); } return ResponseUtils.buildSucessResponse(dataMap); }  @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 { @ApiOperation(httpMethod = "GET", value = "Get the average cost and total cost for an EC2 resource") @GetMapping(value = "v1/{assetGroup}/ec2/{resourceId}/cost") public ResponseEntity<Object> getEc2ResourceSummary( @PathVariable(name = "resourceId", required = true) String resourceId) throws DataException { Map<String, Object> dataMap = null; try { dataMap = assetService.getEC2AvgAndTotalCost(resourceId); } catch (Exception e) { LOGGER.error("Error in getEc2ResourceSummary ",e); dataMap = new HashMap<>(); } return ResponseUtils.buildSucessResponse(dataMap); }  @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);  }