@Test public void testgetDiskUtilizationByInstanceId() throws Exception { List<Map<String, Object>> utilList = new ArrayList<>(); Map<String, Object> utilMap = new HashMap<>(); utilMap.put("date", "d1"); utilMap.put("disk-utilization", 50); utilList.add(utilMap); when(service.getInstanceDiskUtilization(anyObject())).thenReturn(utilList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj1 = controller.getDiskUtilizationByInstanceId(""); assertTrue(responseObj1.getStatusCode() == HttpStatus.EXPECTATION_FAILED); ReflectionTestUtils.setField(controller, "qualysEnabled", true); ResponseEntity<Object> responseObj2 = controller.getDiskUtilizationByInstanceId("a1"); assertTrue(responseObj2.getStatusCode() == HttpStatus.OK); assertTrue(((Map<String, Object>) responseObj2.getBody()).get("data") != null); doThrow(new DataException()).when(service).getInstanceDiskUtilization(anyObject()); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj0 = controller.getDiskUtilizationByInstanceId("a1"); assertTrue(responseObj0.getStatusCode() == HttpStatus.EXPECTATION_FAILED); }
@RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/disk-utilization", method = RequestMethod.GET) public ResponseEntity<Object> getDiskUtilizationByInstanceId( @PathVariable(name = "resourceId", required = true) String instanceId) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } Response response; try { response = new Response(assetService.getInstanceDiskUtilization(instanceId)); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/disk-utilization", method = RequestMethod.GET) public ResponseEntity<Object> getDiskUtilizationByInstanceId( @PathVariable(name = "resourceId", required = true) String instanceId) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } Response response; try { response = new Response(assetService.getInstanceDiskUtilization(instanceId)); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); } }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/disk-utilization", method = RequestMethod.GET) public ResponseEntity<Object> getDiskUtilizationByInstanceId( @PathVariable(name = "resourceId", required = true) String instanceId) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } Response response; try { response = new Response(assetService.getInstanceDiskUtilization(instanceId)); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }  }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/disk-utilization", method = RequestMethod.GET) public ResponseEntity<Object> getDiskUtilizationByInstanceId( @PathVariable(name = "resourceId", required = true) String instanceId) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } Response response; try { response = new Response(assetService.getInstanceDiskUtilization(instanceId)); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }  @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}/disk-utilization", method = RequestMethod.GET) public ResponseEntity<Object> getDiskUtilizationByInstanceId( @PathVariable(name = "resourceId", required = true) String instanceId) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID)); } Response response; try { response = new Response(assetService.getInstanceDiskUtilization(instanceId)); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }  @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);  }