@Test public void testgetInstalledSoftwareDetailsByInstanceId() throws Exception { List<Map<String, Object>> softwareList = new ArrayList<>(); when(service.getInstanceSoftwareInstallDetails(anyObject(), anyObject(), anyObject(), anyObject())) .thenReturn(softwareList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj0 = controller.getInstalledSoftwareDetailsByInstanceId("a1", 1, 1, "pacman"); assertTrue(responseObj0.getStatusCode() == HttpStatus.EXPECTATION_FAILED); Map<String, Object> softwareMap1 = new HashMap<>(); softwareMap1.put("name", "x"); softwareMap1.put("value", "y"); Map<String, Object> softwareMap2 = new HashMap<>(); softwareMap2.put("name", "p"); softwareMap2.put("value", "q"); softwareList.add(softwareMap2); Map<String, Object> softwareMap3 = new HashMap<>(); softwareMap3.put("name", "a"); softwareMap3.put("value", "b"); softwareList.add(softwareMap3); when(service.getInstanceSoftwareInstallDetails(anyObject(), anyObject(), anyObject(), anyObject())) .thenReturn(softwareList); ReflectionTestUtils.setField(controller, "assetService", service); ReflectionTestUtils.setField(controller, "qualysEnabled", true); ResponseEntity<Object> responseObj1 = controller.getInstalledSoftwareDetailsByInstanceId("a1", 0, 1, "pacman"); assertTrue(responseObj1.getStatusCode() == HttpStatus.OK); assertTrue(((Map<String, Object>) responseObj1.getBody()).get("data") != null); ResponseEntity<Object> responseObj2 = controller.getInstalledSoftwareDetailsByInstanceId("a1", 1, 1, "pacman"); assertTrue(responseObj2.getStatusCode() == HttpStatus.OK); assertTrue(((Map<String, Object>) responseObj2.getBody()).get("data") != null); ResponseEntity<Object> responseObj3 = controller.getInstalledSoftwareDetailsByInstanceId("a1", 6, 1, "pacman"); assertTrue(responseObj3.getStatusCode() == HttpStatus.EXPECTATION_FAILED); ResponseEntity<Object> responseObj4 = controller.getInstalledSoftwareDetailsByInstanceId("", 1, 1, "pacman"); assertTrue(responseObj4.getStatusCode() == HttpStatus.EXPECTATION_FAILED); ResponseEntity<Object> responseObj5 = controller.getInstalledSoftwareDetailsByInstanceId("a1", 1, 8, "pacman"); assertTrue(responseObj5.getStatusCode() == HttpStatus.OK); ResponseEntity<Object> responseObj6 = controller.getInstalledSoftwareDetailsByInstanceId("a1", 0, 0, "pacman"); assertTrue(responseObj6.getStatusCode() == HttpStatus.OK); ResponseEntity<Object> responseObj7 = controller.getInstalledSoftwareDetailsByInstanceId("a1", null, 0, "pacman"); assertTrue(responseObj7.getStatusCode() == HttpStatus.OK); }
@RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/installed-softwares", method = RequestMethod.GET) public 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) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } List<Map<String, Object>> subDetailList ; if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception("Instance Id is Mandatory")); } ResponseWithCount response; try { List<Map<String, Object>> softWareList = assetService.getInstanceSoftwareInstallDetails(instanceId, from, size, searchText); if (softWareList.isEmpty()) { throw new NoDataFoundException(" No data found"); } if (from != null && size != null) { if (from >= softWareList.size()) { throw new DataException(AssetConstants.ERROR_FROM_EXCEEDS); } int endIndex = 0; if ((from + size) > softWareList.size()) { endIndex = softWareList.size(); } else { endIndex = from + size; } if (from == 0 && size == 0) { subDetailList = softWareList; } else { subDetailList = softWareList.subList(from, endIndex); } } else { subDetailList = softWareList; } response = new ResponseWithCount(subDetailList, softWareList.size()); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/installed-softwares", method = RequestMethod.GET) public 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) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } List<Map<String, Object>> subDetailList ; if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception("Instance Id is Mandatory")); } ResponseWithCount response; try { List<Map<String, Object>> softWareList = assetService.getInstanceSoftwareInstallDetails(instanceId, from, size, searchText); if (softWareList.isEmpty()) { throw new NoDataFoundException(" No data found"); } if (from != null && size != null) { if (from >= softWareList.size()) { throw new DataException(AssetConstants.ERROR_FROM_EXCEEDS); } int endIndex = 0; if ((from + size) > softWareList.size()) { endIndex = softWareList.size(); } else { endIndex = from + size; } if (from == 0 && size == 0) { subDetailList = softWareList; } else { subDetailList = softWareList.subList(from, endIndex); } } else { subDetailList = softWareList; } response = new ResponseWithCount(subDetailList, softWareList.size()); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); } }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/installed-softwares", method = RequestMethod.GET) public 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) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } List<Map<String, Object>> subDetailList ; if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception("Instance Id is Mandatory")); } ResponseWithCount response; try { List<Map<String, Object>> softWareList = assetService.getInstanceSoftwareInstallDetails(instanceId, from, size, searchText); if (softWareList.isEmpty()) { throw new NoDataFoundException(" No data found"); } if (from != null && size != null) { if (from >= softWareList.size()) { throw new DataException(AssetConstants.ERROR_FROM_EXCEEDS); } int endIndex = 0; if ((from + size) > softWareList.size()) { endIndex = softWareList.size(); } else { endIndex = from + size; } if (from == 0 && size == 0) { subDetailList = softWareList; } else { subDetailList = softWareList.subList(from, endIndex); } } else { subDetailList = softWareList; } response = new ResponseWithCount(subDetailList, softWareList.size()); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }  }
AssetDetailController { @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/installed-softwares", method = RequestMethod.GET) public 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) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } List<Map<String, Object>> subDetailList ; if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception("Instance Id is Mandatory")); } ResponseWithCount response; try { List<Map<String, Object>> softWareList = assetService.getInstanceSoftwareInstallDetails(instanceId, from, size, searchText); if (softWareList.isEmpty()) { throw new NoDataFoundException(" No data found"); } if (from != null && size != null) { if (from >= softWareList.size()) { throw new DataException(AssetConstants.ERROR_FROM_EXCEEDS); } int endIndex = 0; if ((from + size) > softWareList.size()) { endIndex = softWareList.size(); } else { endIndex = from + size; } if (from == 0 && size == 0) { subDetailList = softWareList; } else { subDetailList = softWareList.subList(from, endIndex); } } else { subDetailList = softWareList; } response = new ResponseWithCount(subDetailList, softWareList.size()); } 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}/installed-softwares", method = RequestMethod.GET) public 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) { if (!qualysEnabled) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED)); } List<Map<String, Object>> subDetailList ; if (Strings.isNullOrEmpty(instanceId)) { return ResponseUtils.buildFailureResponse(new Exception("Instance Id is Mandatory")); } ResponseWithCount response; try { List<Map<String, Object>> softWareList = assetService.getInstanceSoftwareInstallDetails(instanceId, from, size, searchText); if (softWareList.isEmpty()) { throw new NoDataFoundException(" No data found"); } if (from != null && size != null) { if (from >= softWareList.size()) { throw new DataException(AssetConstants.ERROR_FROM_EXCEEDS); } int endIndex = 0; if ((from + size) > softWareList.size()) { endIndex = softWareList.size(); } else { endIndex = from + size; } if (from == 0 && size == 0) { subDetailList = softWareList; } else { subDetailList = softWareList.subList(from, endIndex); } } else { subDetailList = softWareList; } response = new ResponseWithCount(subDetailList, softWareList.size()); } 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);  }