@Test public void testgetEditableFieldsByTargetType() throws Exception{ ResponseEntity<Object> responseObj1 = controller.getEditableFieldsByTargetType("","ec2"); assertTrue(responseObj1.getStatusCode()==HttpStatus.EXPECTATION_FAILED); List<Map<String, Object>> aList = new ArrayList<>(); Map<String,Object> aMap = new HashMap<>(); aMap.put("type", "ec2"); aList.add(aMap); when(service.getTargetTypesForAssetGroup(anyString(),anyString(),anyString())).thenReturn(aList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj2 = controller.getEditableFieldsByTargetType("ag","ec2"); assertTrue(responseObj2.getStatusCode()==HttpStatus.OK); ResponseEntity<Object> responseObj3 = controller.getEditableFieldsByTargetType("ag","s3"); assertTrue(responseObj3.getStatusCode()==HttpStatus.EXPECTATION_FAILED); }
@RequestMapping(path = "/v1/updateFieldsbyresourceType", method = RequestMethod.GET) public ResponseEntity<Object> getEditableFieldsByTargetType( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "resourceType", required = true) String resourceType) { if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception("Asset group/TargetType is Mandatory")); } boolean isTargetTypePresent = false; for (Map<String, Object> targetType : assetService.getTargetTypesForAssetGroup(assetGroup, null, null)) { if (targetType.get("type").toString().equals(resourceType)) { isTargetTypePresent = true; break; } } if (isTargetTypePresent) { ResponseWithFieldsByTargetType response = assetService.getEditFieldsByTargetType(resourceType); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("TargetType not present in Asset Group")); } }
AssetListController { @RequestMapping(path = "/v1/updateFieldsbyresourceType", method = RequestMethod.GET) public ResponseEntity<Object> getEditableFieldsByTargetType( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "resourceType", required = true) String resourceType) { if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception("Asset group/TargetType is Mandatory")); } boolean isTargetTypePresent = false; for (Map<String, Object> targetType : assetService.getTargetTypesForAssetGroup(assetGroup, null, null)) { if (targetType.get("type").toString().equals(resourceType)) { isTargetTypePresent = true; break; } } if (isTargetTypePresent) { ResponseWithFieldsByTargetType response = assetService.getEditFieldsByTargetType(resourceType); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("TargetType not present in Asset Group")); } } }
AssetListController { @RequestMapping(path = "/v1/updateFieldsbyresourceType", method = RequestMethod.GET) public ResponseEntity<Object> getEditableFieldsByTargetType( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "resourceType", required = true) String resourceType) { if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception("Asset group/TargetType is Mandatory")); } boolean isTargetTypePresent = false; for (Map<String, Object> targetType : assetService.getTargetTypesForAssetGroup(assetGroup, null, null)) { if (targetType.get("type").toString().equals(resourceType)) { isTargetTypePresent = true; break; } } if (isTargetTypePresent) { ResponseWithFieldsByTargetType response = assetService.getEditFieldsByTargetType(resourceType); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("TargetType not present in Asset Group")); } }  }
AssetListController { @RequestMapping(path = "/v1/updateFieldsbyresourceType", method = RequestMethod.GET) public ResponseEntity<Object> getEditableFieldsByTargetType( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "resourceType", required = true) String resourceType) { if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception("Asset group/TargetType is Mandatory")); } boolean isTargetTypePresent = false; for (Map<String, Object> targetType : assetService.getTargetTypesForAssetGroup(assetGroup, null, null)) { if (targetType.get("type").toString().equals(resourceType)) { isTargetTypePresent = true; break; } } if (isTargetTypePresent) { ResponseWithFieldsByTargetType response = assetService.getEditFieldsByTargetType(resourceType); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("TargetType not present in Asset Group")); } }  @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 { @RequestMapping(path = "/v1/updateFieldsbyresourceType", method = RequestMethod.GET) public ResponseEntity<Object> getEditableFieldsByTargetType( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "resourceType", required = true) String resourceType) { if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception("Asset group/TargetType is Mandatory")); } boolean isTargetTypePresent = false; for (Map<String, Object> targetType : assetService.getTargetTypesForAssetGroup(assetGroup, null, null)) { if (targetType.get("type").toString().equals(resourceType)) { isTargetTypePresent = true; break; } } if (isTargetTypePresent) { ResponseWithFieldsByTargetType response = assetService.getEditFieldsByTargetType(resourceType); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("TargetType not present in Asset Group")); } }  @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);  }