@Test public void testgeAssetCountByTypeAndApplication() throws Exception { List<Map<String, Object>> tTypeList = new ArrayList<>(); Map<String, Object> tTypeMap = new HashMap<>(); tTypeMap.put("count", "100"); tTypeMap.put("type", "ec2"); tTypeList.add(tTypeMap); mockStatic(Util.class); when(Util.isValidTargetType(anyString(), anyString())).thenReturn(true, true, false); when(service.getAssetCountByApplication(anyObject(), anyObject())).thenReturn(tTypeList); ReflectionTestUtils.setField(controller, "assetService", service); ResponseEntity<Object> responseObj = controller.geAssetCountByTypeAndApplication("ag", "type"); assertTrue(responseObj.getStatusCode() == HttpStatus.OK); assertTrue(((Map<String, Object>) responseObj.getBody()).get("data") != null); doThrow(new DataException()).when(service).getAssetCountByApplication(anyObject(), anyObject()); responseObj = controller.geAssetCountByTypeAndApplication("ag", "type"); assertTrue(responseObj.getStatusCode() == HttpStatus.EXPECTATION_FAILED); responseObj = controller.geAssetCountByTypeAndApplication("ag", "type"); assertTrue(responseObj.getStatusCode() == HttpStatus.EXPECTATION_FAILED); }
@GetMapping(value = "/v1/count/byapplication") public ResponseEntity<Object> geAssetCountByTypeAndApplication( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "type", required = true) String type) { if (Util.isValidTargetType(assetGroup, type)) { List<Map<String, Object>> countMap = null; try { countMap = assetService.getAssetCountByApplication(assetGroup, type); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } Map<String, Object> response = new LinkedHashMap<>(); response.put("ag", assetGroup); response.put("type", type); response.put(AssetConstants.ASSET_COUNT, countMap); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("Invalid Target type for the assetgroup ")); } }
AssetCountController { @GetMapping(value = "/v1/count/byapplication") public ResponseEntity<Object> geAssetCountByTypeAndApplication( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "type", required = true) String type) { if (Util.isValidTargetType(assetGroup, type)) { List<Map<String, Object>> countMap = null; try { countMap = assetService.getAssetCountByApplication(assetGroup, type); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } Map<String, Object> response = new LinkedHashMap<>(); response.put("ag", assetGroup); response.put("type", type); response.put(AssetConstants.ASSET_COUNT, countMap); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("Invalid Target type for the assetgroup ")); } } }
AssetCountController { @GetMapping(value = "/v1/count/byapplication") public ResponseEntity<Object> geAssetCountByTypeAndApplication( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "type", required = true) String type) { if (Util.isValidTargetType(assetGroup, type)) { List<Map<String, Object>> countMap = null; try { countMap = assetService.getAssetCountByApplication(assetGroup, type); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } Map<String, Object> response = new LinkedHashMap<>(); response.put("ag", assetGroup); response.put("type", type); response.put(AssetConstants.ASSET_COUNT, countMap); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("Invalid Target type for the assetgroup ")); } }  }
AssetCountController { @GetMapping(value = "/v1/count/byapplication") public ResponseEntity<Object> geAssetCountByTypeAndApplication( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "type", required = true) String type) { if (Util.isValidTargetType(assetGroup, type)) { List<Map<String, Object>> countMap = null; try { countMap = assetService.getAssetCountByApplication(assetGroup, type); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } Map<String, Object> response = new LinkedHashMap<>(); response.put("ag", assetGroup); response.put("type", type); response.put(AssetConstants.ASSET_COUNT, countMap); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("Invalid Target type for the assetgroup ")); } }  @GetMapping(value = "/v1/count") ResponseEntity<Object> geAssetCount(@RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "type", required = false) String type,
            @RequestParam(name = "domain", required = false) String domain,
            @RequestParam(name = "application", required = false) String application,
            @RequestParam(name = "provider", required = false) String provider); @GetMapping(value = "/v1/count/byapplication") ResponseEntity<Object> geAssetCountByTypeAndApplication(
            @RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "type", required = true) String type); @GetMapping(value = "/v1/count/byenvironment") ResponseEntity<Object> geAssetCountByTypeEnvironment(
            @RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "application", required = false) String application,
            @RequestParam(name = "type", required = true) String type); }
AssetCountController { @GetMapping(value = "/v1/count/byapplication") public ResponseEntity<Object> geAssetCountByTypeAndApplication( @RequestParam(name = "ag", required = true) String assetGroup, @RequestParam(name = "type", required = true) String type) { if (Util.isValidTargetType(assetGroup, type)) { List<Map<String, Object>> countMap = null; try { countMap = assetService.getAssetCountByApplication(assetGroup, type); } catch (Exception e) { return ResponseUtils.buildFailureResponse(e); } Map<String, Object> response = new LinkedHashMap<>(); response.put("ag", assetGroup); response.put("type", type); response.put(AssetConstants.ASSET_COUNT, countMap); return ResponseUtils.buildSucessResponse(response); } else { return ResponseUtils.buildFailureResponse(new Exception("Invalid Target type for the assetgroup ")); } }  @GetMapping(value = "/v1/count") ResponseEntity<Object> geAssetCount(@RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "type", required = false) String type,
            @RequestParam(name = "domain", required = false) String domain,
            @RequestParam(name = "application", required = false) String application,
            @RequestParam(name = "provider", required = false) String provider); @GetMapping(value = "/v1/count/byapplication") ResponseEntity<Object> geAssetCountByTypeAndApplication(
            @RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "type", required = true) String type); @GetMapping(value = "/v1/count/byenvironment") ResponseEntity<Object> geAssetCountByTypeEnvironment(
            @RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "application", required = false) String application,
            @RequestParam(name = "type", required = true) String type);  }