@SuppressWarnings("unchecked") @Test public void testUploadAssetGroupRuleCompliance() throws Exception{ PowerMockito.mockStatic(AssetGroupUtil.class); List<Map<String, Object>> ruleInfoList = new ArrayList<>(); Map<String,Object> ruleInfo = new HashMap<>(); ruleInfo.put("domain", "infra"); ruleInfo.put("ruleId", "testruleid1"); ruleInfo.put("compliance_percent", 55); ruleInfo.put("total", 1345l); ruleInfo.put("compliant", 1000l); ruleInfo.put("noncompliant", 345l); ruleInfo.put("contribution_percent", 66); ruleInfoList.add(ruleInfo); when(AssetGroupUtil.fetchRuleComplianceInfo(anyString(),anyString(),anyList(),anyString())).thenReturn(ruleInfoList); PowerMockito.mockStatic(ESManager.class); doNothing().when(ESManager.class); ESManager.uploadData(anyString(), anyString(), anyList(), anyString(), anyBoolean()); Map<String, List<String>> assetGroups = new HashMap<>(); List<String> domains = new ArrayList<>(); domains.add("infra"); assetGroups.put("pacman", domains); assetGroupStatsCollector.uploadAssetGroupRuleCompliance(assetGroups); }
public void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups) throws Exception { log.info(" Start Collecing Rule compliance"); List<Map<String, Object>> docs = new ArrayList<>(); assetGroups.entrySet().stream().forEach(entry -> { String ag = entry.getKey(); List<String> domains = entry.getValue(); List<Map<String, Object>> docList = new ArrayList<>(); try { docList = AssetGroupUtil.fetchRuleComplianceInfo(COMP_API_URL, ag, domains,getToken()); } catch (Exception e) { log.error("Exception in uploadAssetGroupRuleCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupRuleCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } docList.parallelStream().forEach(doc -> { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + doc.get(DOMAIN) + doc.get("ruleId") + CURR_DATE)); }); docs.addAll(docList); }); ESManager.uploadData(AG_STATS, "issuecompliance", docs, "@id", false); log.info(" End Collecing Rule compliance"); }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups) throws Exception { log.info(" Start Collecing Rule compliance"); List<Map<String, Object>> docs = new ArrayList<>(); assetGroups.entrySet().stream().forEach(entry -> { String ag = entry.getKey(); List<String> domains = entry.getValue(); List<Map<String, Object>> docList = new ArrayList<>(); try { docList = AssetGroupUtil.fetchRuleComplianceInfo(COMP_API_URL, ag, domains,getToken()); } catch (Exception e) { log.error("Exception in uploadAssetGroupRuleCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupRuleCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } docList.parallelStream().forEach(doc -> { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + doc.get(DOMAIN) + doc.get("ruleId") + CURR_DATE)); }); docs.addAll(docList); }); ESManager.uploadData(AG_STATS, "issuecompliance", docs, "@id", false); log.info(" End Collecing Rule compliance"); } }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups) throws Exception { log.info(" Start Collecing Rule compliance"); List<Map<String, Object>> docs = new ArrayList<>(); assetGroups.entrySet().stream().forEach(entry -> { String ag = entry.getKey(); List<String> domains = entry.getValue(); List<Map<String, Object>> docList = new ArrayList<>(); try { docList = AssetGroupUtil.fetchRuleComplianceInfo(COMP_API_URL, ag, domains,getToken()); } catch (Exception e) { log.error("Exception in uploadAssetGroupRuleCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupRuleCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } docList.parallelStream().forEach(doc -> { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + doc.get(DOMAIN) + doc.get("ruleId") + CURR_DATE)); }); docs.addAll(docList); }); ESManager.uploadData(AG_STATS, "issuecompliance", docs, "@id", false); log.info(" End Collecing Rule compliance"); }  }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups) throws Exception { log.info(" Start Collecing Rule compliance"); List<Map<String, Object>> docs = new ArrayList<>(); assetGroups.entrySet().stream().forEach(entry -> { String ag = entry.getKey(); List<String> domains = entry.getValue(); List<Map<String, Object>> docList = new ArrayList<>(); try { docList = AssetGroupUtil.fetchRuleComplianceInfo(COMP_API_URL, ag, domains,getToken()); } catch (Exception e) { log.error("Exception in uploadAssetGroupRuleCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupRuleCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } docList.parallelStream().forEach(doc -> { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + doc.get(DOMAIN) + doc.get("ruleId") + CURR_DATE)); }); docs.addAll(docList); }); ESManager.uploadData(AG_STATS, "issuecompliance", docs, "@id", false); log.info(" End Collecing Rule 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 uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups) throws Exception { log.info(" Start Collecing Rule compliance"); List<Map<String, Object>> docs = new ArrayList<>(); assetGroups.entrySet().stream().forEach(entry -> { String ag = entry.getKey(); List<String> domains = entry.getValue(); List<Map<String, Object>> docList = new ArrayList<>(); try { docList = AssetGroupUtil.fetchRuleComplianceInfo(COMP_API_URL, ag, domains,getToken()); } catch (Exception e) { log.error("Exception in uploadAssetGroupRuleCompliance" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupRuleCompliance for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } docList.parallelStream().forEach(doc -> { doc.put("ag", ag); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + doc.get(DOMAIN) + doc.get("ruleId") + CURR_DATE)); }); docs.addAll(docList); }); ESManager.uploadData(AG_STATS, "issuecompliance", docs, "@id", false); log.info(" End Collecing Rule 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);  }