@Test public void testlistPatchableAssets() throws Exception{ List<Map<String, Object>> aList = new ArrayList<>(); Request request = new Request(); ResponseEntity<Object> responseObj1 = controller.listPatchableAssets(request); assertTrue(responseObj1.getStatusCode() == HttpStatus.EXPECTATION_FAILED); request.setFrom(-1); request.setAg("ag"); ResponseEntity<Object> responseObj2 = controller.listPatchableAssets(request); assertTrue(responseObj2.getStatusCode() == HttpStatus.EXPECTATION_FAILED); request.setFrom(0); ResponseEntity<Object> responseObj3 = controller.listPatchableAssets(request); assertTrue(responseObj3.getStatusCode() == HttpStatus.EXPECTATION_FAILED); Map<String,String> filter = new HashMap<>(); filter.put("filterKey", "filterValue"); request.setFilter(filter); ResponseEntity<Object> responseObj4 = controller.listPatchableAssets(request); assertTrue(responseObj4.getStatusCode() == HttpStatus.EXPECTATION_FAILED); filter.clear(); filter.put("resourceType", "filterValue"); request.setFilter(filter); when(service.getListAssetsPatchable(anyString(), anyObject())).thenReturn(aList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj5 = controller.listPatchableAssets(request); assertTrue(responseObj5.getStatusCode() == HttpStatus.EXPECTATION_FAILED); filter.clear(); request.setFilter(filter); when(service.getListAssetsPatchable(anyString(), anyObject())).thenReturn(aList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj6 = controller.listPatchableAssets(request); assertTrue(responseObj6.getStatusCode() == HttpStatus.OK); Map<String,Object> aMap = new HashMap<>(); aMap.put("type", "ec2"); aList.add(aMap); request.setFrom(3); ResponseEntity<Object> responseObj7 = controller.listPatchableAssets(request); assertTrue(responseObj7.getStatusCode() == HttpStatus.EXPECTATION_FAILED); request.setFrom(0); ResponseEntity<Object> responseObj8 = controller.listPatchableAssets(request); assertTrue(responseObj8.getStatusCode() == HttpStatus.OK); request.setSize(8); ResponseEntity<Object> responseObj9 = controller.listPatchableAssets(request); assertTrue(responseObj9.getStatusCode() == HttpStatus.OK); }
@ApiOperation(httpMethod = "POST", value = "Get the list of patchable assets in an asset group. Optional filters -'application', 'environment', 'resourceType', 'patched'{true/false}, 'executiveSponsor' and 'director'.") @PostMapping(value = "/v1/list/assets/patchable") public ResponseEntity<Object> listPatchableAssets(@RequestBody(required = true) Request request) { String assetGroup = request.getAg(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION, AssetConstants.FILTER_ENVIRONMENT, AssetConstants.FILTER_RES_TYPE, AssetConstants.FILTER_PATCHED, AssetConstants.FILTER_EXEC_SPONSOR, AssetConstants.FILTER_DIRECTOR); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } List<Map<String, Object>> masterList; try { if (filter.containsKey(AssetConstants.FILTER_RES_TYPE) && !isEC2OrOnPremServer(filter)) { return ResponseUtils.buildFailureResponse(new Exception( "Value of resourceType must be ec2 or onpremserver")); } masterList = assetService.getListAssetsPatchable(assetGroup, filter); } catch (Exception e) { LOGGER.error("Error in listPatchableAssets ",e); return ResponseUtils.buildFailureResponse(e); } return formResponseWithCount(masterList, from, size, searchText); }
AssetListController { @ApiOperation(httpMethod = "POST", value = "Get the list of patchable assets in an asset group. Optional filters -'application', 'environment', 'resourceType', 'patched'{true/false}, 'executiveSponsor' and 'director'.") @PostMapping(value = "/v1/list/assets/patchable") public ResponseEntity<Object> listPatchableAssets(@RequestBody(required = true) Request request) { String assetGroup = request.getAg(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION, AssetConstants.FILTER_ENVIRONMENT, AssetConstants.FILTER_RES_TYPE, AssetConstants.FILTER_PATCHED, AssetConstants.FILTER_EXEC_SPONSOR, AssetConstants.FILTER_DIRECTOR); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } List<Map<String, Object>> masterList; try { if (filter.containsKey(AssetConstants.FILTER_RES_TYPE) && !isEC2OrOnPremServer(filter)) { return ResponseUtils.buildFailureResponse(new Exception( "Value of resourceType must be ec2 or onpremserver")); } masterList = assetService.getListAssetsPatchable(assetGroup, filter); } catch (Exception e) { LOGGER.error("Error in listPatchableAssets ",e); return ResponseUtils.buildFailureResponse(e); } return formResponseWithCount(masterList, from, size, searchText); } }
AssetListController { @ApiOperation(httpMethod = "POST", value = "Get the list of patchable assets in an asset group. Optional filters -'application', 'environment', 'resourceType', 'patched'{true/false}, 'executiveSponsor' and 'director'.") @PostMapping(value = "/v1/list/assets/patchable") public ResponseEntity<Object> listPatchableAssets(@RequestBody(required = true) Request request) { String assetGroup = request.getAg(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION, AssetConstants.FILTER_ENVIRONMENT, AssetConstants.FILTER_RES_TYPE, AssetConstants.FILTER_PATCHED, AssetConstants.FILTER_EXEC_SPONSOR, AssetConstants.FILTER_DIRECTOR); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } List<Map<String, Object>> masterList; try { if (filter.containsKey(AssetConstants.FILTER_RES_TYPE) && !isEC2OrOnPremServer(filter)) { return ResponseUtils.buildFailureResponse(new Exception( "Value of resourceType must be ec2 or onpremserver")); } masterList = assetService.getListAssetsPatchable(assetGroup, filter); } catch (Exception e) { LOGGER.error("Error in listPatchableAssets ",e); return ResponseUtils.buildFailureResponse(e); } return formResponseWithCount(masterList, from, size, searchText); }  }
AssetListController { @ApiOperation(httpMethod = "POST", value = "Get the list of patchable assets in an asset group. Optional filters -'application', 'environment', 'resourceType', 'patched'{true/false}, 'executiveSponsor' and 'director'.") @PostMapping(value = "/v1/list/assets/patchable") public ResponseEntity<Object> listPatchableAssets(@RequestBody(required = true) Request request) { String assetGroup = request.getAg(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION, AssetConstants.FILTER_ENVIRONMENT, AssetConstants.FILTER_RES_TYPE, AssetConstants.FILTER_PATCHED, AssetConstants.FILTER_EXEC_SPONSOR, AssetConstants.FILTER_DIRECTOR); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } List<Map<String, Object>> masterList; try { if (filter.containsKey(AssetConstants.FILTER_RES_TYPE) && !isEC2OrOnPremServer(filter)) { return ResponseUtils.buildFailureResponse(new Exception( "Value of resourceType must be ec2 or onpremserver")); } masterList = assetService.getListAssetsPatchable(assetGroup, filter); } catch (Exception e) { LOGGER.error("Error in listPatchableAssets ",e); return ResponseUtils.buildFailureResponse(e); } return formResponseWithCount(masterList, from, size, searchText); }  @ApiOperation(httpMethod = "POST", value = "Get the list of assets in an asset group. Optional filters -'application','environment','resourceType' ") @PostMapping(value = "/v1/list/assets") ResponseEntity<Object> listAssets(@RequestBody(required = true) Request request,
            @RequestParam(name = "domain", required = false) String domain); @ApiOperation(httpMethod = "POST", value = "Get the list of taggble assets in an asset group. Optional filters -'application','environment','resourceType','tagged'{true/false} ,'tagName' {Application/Environment/Stack/Role}") @PostMapping(value = "/v1/list/assets/taggable") ResponseEntity<Object> listTaggableAssets(@RequestBody(required = true) Request request); @ApiOperation(httpMethod = "POST", value = "Get the list of patchable assets in an asset group. Optional filters -'application', 'environment', 'resourceType', 'patched'{true/false}, 'executiveSponsor' and 'director'.") @PostMapping(value = "/v1/list/assets/patchable") ResponseEntity<Object> listPatchableAssets(@RequestBody(required = true) Request request); @ApiOperation(httpMethod = "POST", value = "Get the list of vulnerable assets in an asset group for a particualr qid. Mandatory Filter -'qid'. Optional filters -'application','environment','resourceType' ") @PostMapping(value = "/v1/list/assets/vulnerable") ResponseEntity<Object> listVulnerableAssets(@RequestBody(required = true) Request request); @ApiOperation(httpMethod = "POST", value = "Get the list of assets scanned by a ruleid in an asset group . Mandatory Filter -'ruleId'. Optional filters -'application','environment','resourceType','compliant'{true/false}") @PostMapping(value = "/v1/list/assets/scanned") ResponseEntity<Object> listScannedAssets(@RequestBody(required = true) Request request,
            @RequestParam(name = "domain", required = false) String domain); @ApiOperation(httpMethod = "POST", value = "Get the complete details assets") @PostMapping(value = "/v1/listing/assets") ResponseEntity<Object> getAssetLists(@RequestBody(required = true) Request request); @RequestMapping(path = "/v1/updateFieldsbyresourceType", method = RequestMethod.GET) ResponseEntity<Object> getEditableFieldsByTargetType(
            @RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "resourceType", required = true) String resourceType); }
AssetListController { @ApiOperation(httpMethod = "POST", value = "Get the list of patchable assets in an asset group. Optional filters -'application', 'environment', 'resourceType', 'patched'{true/false}, 'executiveSponsor' and 'director'.") @PostMapping(value = "/v1/list/assets/patchable") public ResponseEntity<Object> listPatchableAssets(@RequestBody(required = true) Request request) { String assetGroup = request.getAg(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION, AssetConstants.FILTER_ENVIRONMENT, AssetConstants.FILTER_RES_TYPE, AssetConstants.FILTER_PATCHED, AssetConstants.FILTER_EXEC_SPONSOR, AssetConstants.FILTER_DIRECTOR); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } List<Map<String, Object>> masterList; try { if (filter.containsKey(AssetConstants.FILTER_RES_TYPE) && !isEC2OrOnPremServer(filter)) { return ResponseUtils.buildFailureResponse(new Exception( "Value of resourceType must be ec2 or onpremserver")); } masterList = assetService.getListAssetsPatchable(assetGroup, filter); } catch (Exception e) { LOGGER.error("Error in listPatchableAssets ",e); return ResponseUtils.buildFailureResponse(e); } return formResponseWithCount(masterList, from, size, searchText); }  @ApiOperation(httpMethod = "POST", value = "Get the list of assets in an asset group. Optional filters -'application','environment','resourceType' ") @PostMapping(value = "/v1/list/assets") ResponseEntity<Object> listAssets(@RequestBody(required = true) Request request,
            @RequestParam(name = "domain", required = false) String domain); @ApiOperation(httpMethod = "POST", value = "Get the list of taggble assets in an asset group. Optional filters -'application','environment','resourceType','tagged'{true/false} ,'tagName' {Application/Environment/Stack/Role}") @PostMapping(value = "/v1/list/assets/taggable") ResponseEntity<Object> listTaggableAssets(@RequestBody(required = true) Request request); @ApiOperation(httpMethod = "POST", value = "Get the list of patchable assets in an asset group. Optional filters -'application', 'environment', 'resourceType', 'patched'{true/false}, 'executiveSponsor' and 'director'.") @PostMapping(value = "/v1/list/assets/patchable") ResponseEntity<Object> listPatchableAssets(@RequestBody(required = true) Request request); @ApiOperation(httpMethod = "POST", value = "Get the list of vulnerable assets in an asset group for a particualr qid. Mandatory Filter -'qid'. Optional filters -'application','environment','resourceType' ") @PostMapping(value = "/v1/list/assets/vulnerable") ResponseEntity<Object> listVulnerableAssets(@RequestBody(required = true) Request request); @ApiOperation(httpMethod = "POST", value = "Get the list of assets scanned by a ruleid in an asset group . Mandatory Filter -'ruleId'. Optional filters -'application','environment','resourceType','compliant'{true/false}") @PostMapping(value = "/v1/list/assets/scanned") ResponseEntity<Object> listScannedAssets(@RequestBody(required = true) Request request,
            @RequestParam(name = "domain", required = false) String domain); @ApiOperation(httpMethod = "POST", value = "Get the complete details assets") @PostMapping(value = "/v1/listing/assets") ResponseEntity<Object> getAssetLists(@RequestBody(required = true) Request request); @RequestMapping(path = "/v1/updateFieldsbyresourceType", method = RequestMethod.GET) ResponseEntity<Object> getEditableFieldsByTargetType(
            @RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "resourceType", required = true) String resourceType);  }