@SuppressWarnings("unchecked") @Test public void testUploadAssetGroupTagCompliance() throws Exception{ PowerMockito.mockStatic(AssetGroupUtil.class); Map<String,Object> comSummaryMap = new HashMap<>(); comSummaryMap.put("total", 1345l); comSummaryMap.put("compliant", 1000l); comSummaryMap.put("noncompliant", 345l); when(AssetGroupUtil.fetchTaggingSummary(anyString(),anyString(),anyString())).thenReturn(comSummaryMap); PowerMockito.mockStatic(ESManager.class); doNothing().when(ESManager.class); ESManager.uploadData(anyString(), anyString(), anyList(), anyString(), anyBoolean()); assetGroupStatsCollector.uploadAssetGroupTagCompliance(Arrays.asList("pacman")); }
public void uploadAssetGroupTagCompliance(List<String> assetGroups) throws Exception { log.info(" Start Collecing tag compliance"); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { Map<String, Object> doc = AssetGroupUtil.fetchTaggingSummary(COMP_API_URL, ag, getToken()); if (!doc.isEmpty()) { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + CURR_DATE)); docs.add(doc); } } catch (Exception e) { log.error("Exception in uploadAssetGroupTagCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupTagCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "tagcompliance", docs, "@id", false); log.info(" End Collecing tag compliance"); }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupTagCompliance(List<String> assetGroups) throws Exception { log.info(" Start Collecing tag compliance"); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { Map<String, Object> doc = AssetGroupUtil.fetchTaggingSummary(COMP_API_URL, ag, getToken()); if (!doc.isEmpty()) { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + CURR_DATE)); docs.add(doc); } } catch (Exception e) { log.error("Exception in uploadAssetGroupTagCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupTagCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "tagcompliance", docs, "@id", false); log.info(" End Collecing tag compliance"); } }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupTagCompliance(List<String> assetGroups) throws Exception { log.info(" Start Collecing tag compliance"); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { Map<String, Object> doc = AssetGroupUtil.fetchTaggingSummary(COMP_API_URL, ag, getToken()); if (!doc.isEmpty()) { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + CURR_DATE)); docs.add(doc); } } catch (Exception e) { log.error("Exception in uploadAssetGroupTagCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupTagCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "tagcompliance", docs, "@id", false); log.info(" End Collecing tag compliance"); }  }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupTagCompliance(List<String> assetGroups) throws Exception { log.info(" Start Collecing tag compliance"); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { Map<String, Object> doc = AssetGroupUtil.fetchTaggingSummary(COMP_API_URL, ag, getToken()); if (!doc.isEmpty()) { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + CURR_DATE)); docs.add(doc); } } catch (Exception e) { log.error("Exception in uploadAssetGroupTagCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupTagCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "tagcompliance", docs, "@id", false); log.info(" End Collecing tag compliance"); }  List<Map<String, String>> collectAssetGroupStats(); void uploadAssetGroupTagCompliance(List<String> assetGroups); void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCountStats(List<String> assetGroups); void uploadAssetGroupIssues(Map<String, List<String>> assetGroups); void uploadAssetGroupVulnCompliance(List<String> assetGroups); }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupTagCompliance(List<String> assetGroups) throws Exception { log.info(" Start Collecing tag compliance"); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { Map<String, Object> doc = AssetGroupUtil.fetchTaggingSummary(COMP_API_URL, ag, getToken()); if (!doc.isEmpty()) { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + CURR_DATE)); docs.add(doc); } } catch (Exception e) { log.error("Exception in uploadAssetGroupTagCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupTagCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "tagcompliance", docs, "@id", false); log.info(" End Collecing tag compliance"); }  List<Map<String, String>> collectAssetGroupStats(); void uploadAssetGroupTagCompliance(List<String> assetGroups); void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCountStats(List<String> assetGroups); void uploadAssetGroupIssues(Map<String, List<String>> assetGroups); void uploadAssetGroupVulnCompliance(List<String> assetGroups);  }