@Test public void getTrendIssuesTest() throws Exception { List<Map<String, Object>> issueTrend = new ArrayList<>(); Map<String, Object> issueTrendSev = new HashMap<>(); issueTrendSev.put("date", 01 - 10 - 2018); issueTrendSev.put("total", 1000); issueTrendSev.put("Critical", 50); issueTrendSev.put("High", 300); issueTrendSev.put("Medium", 200); issueTrendSev.put("Low", 450); issueTrend.add(issueTrendSev); Set<String> ruleSeverity = new HashSet<>(); ruleSeverity.add("Critical"); ruleSeverity.add("High"); ruleSeverity.add("Medium"); ruleSeverity.add("Low"); Map<String, String> filter = new HashMap<>(); filter.put("domain", "Infra & Platform"); when( elasticSearchRepository.getSortedDataFromES(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject())).thenReturn(issueTrend); trendRepositoryImpl.getTrendIssues("aws-all", LocalDate.now(), LocalDate.now(), filter, ruleSeverity); when( elasticSearchRepository.getSortedDataFromES(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject())).thenThrow(new RuntimeException()); assertThatThrownBy( () -> trendRepositoryImpl.getTrendIssues("aws-all", LocalDate.now(), LocalDate.now(), filter, ruleSeverity)).isInstanceOf(DataException.class); }
@Override public List<Map<String, Object>> getTrendIssues(String assetGroup, LocalDate startDate, LocalDate endDate, Map<String, String> filter, Set<String> ruleSev) throws DataException { String domain = filter.get(DOMAIN); List<String> severityList = new ArrayList<>(ruleSev); Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword("ag"), assetGroup); mustFilter.put(CommonUtils.convertAttributetoKeyword(DOMAIN), domain); Map<String, Object> rangeMap = new HashMap<>(); rangeMap.put("gte", startDate.format(DateTimeFormatter.ISO_DATE)); rangeMap.put("lte", endDate.format(DateTimeFormatter.ISO_DATE)); Map<String, Object> dateRangeMap = new HashMap<>(); dateRangeMap.put("date", rangeMap); mustFilter.put(RANGE, dateRangeMap); severityList.add("date"); severityList.add("total"); try{ return elasticSearchRepository.getSortedDataFromES(AG_STATS, "issues", mustFilter, null, null, severityList, null,null); }catch(Exception e){ throw new DataException(e); } }
TrendRepositoryImpl implements TrendRepository, Constants { @Override public List<Map<String, Object>> getTrendIssues(String assetGroup, LocalDate startDate, LocalDate endDate, Map<String, String> filter, Set<String> ruleSev) throws DataException { String domain = filter.get(DOMAIN); List<String> severityList = new ArrayList<>(ruleSev); Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword("ag"), assetGroup); mustFilter.put(CommonUtils.convertAttributetoKeyword(DOMAIN), domain); Map<String, Object> rangeMap = new HashMap<>(); rangeMap.put("gte", startDate.format(DateTimeFormatter.ISO_DATE)); rangeMap.put("lte", endDate.format(DateTimeFormatter.ISO_DATE)); Map<String, Object> dateRangeMap = new HashMap<>(); dateRangeMap.put("date", rangeMap); mustFilter.put(RANGE, dateRangeMap); severityList.add("date"); severityList.add("total"); try{ return elasticSearchRepository.getSortedDataFromES(AG_STATS, "issues", mustFilter, null, null, severityList, null,null); }catch(Exception e){ throw new DataException(e); } } }
TrendRepositoryImpl implements TrendRepository, Constants { @Override public List<Map<String, Object>> getTrendIssues(String assetGroup, LocalDate startDate, LocalDate endDate, Map<String, String> filter, Set<String> ruleSev) throws DataException { String domain = filter.get(DOMAIN); List<String> severityList = new ArrayList<>(ruleSev); Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword("ag"), assetGroup); mustFilter.put(CommonUtils.convertAttributetoKeyword(DOMAIN), domain); Map<String, Object> rangeMap = new HashMap<>(); rangeMap.put("gte", startDate.format(DateTimeFormatter.ISO_DATE)); rangeMap.put("lte", endDate.format(DateTimeFormatter.ISO_DATE)); Map<String, Object> dateRangeMap = new HashMap<>(); dateRangeMap.put("date", rangeMap); mustFilter.put(RANGE, dateRangeMap); severityList.add("date"); severityList.add("total"); try{ return elasticSearchRepository.getSortedDataFromES(AG_STATS, "issues", mustFilter, null, null, severityList, null,null); }catch(Exception e){ throw new DataException(e); } }  }
TrendRepositoryImpl implements TrendRepository, Constants { @Override public List<Map<String, Object>> getTrendIssues(String assetGroup, LocalDate startDate, LocalDate endDate, Map<String, String> filter, Set<String> ruleSev) throws DataException { String domain = filter.get(DOMAIN); List<String> severityList = new ArrayList<>(ruleSev); Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword("ag"), assetGroup); mustFilter.put(CommonUtils.convertAttributetoKeyword(DOMAIN), domain); Map<String, Object> rangeMap = new HashMap<>(); rangeMap.put("gte", startDate.format(DateTimeFormatter.ISO_DATE)); rangeMap.put("lte", endDate.format(DateTimeFormatter.ISO_DATE)); Map<String, Object> dateRangeMap = new HashMap<>(); dateRangeMap.put("date", rangeMap); mustFilter.put(RANGE, dateRangeMap); severityList.add("date"); severityList.add("total"); try{ return elasticSearchRepository.getSortedDataFromES(AG_STATS, "issues", mustFilter, null, null, severityList, null,null); }catch(Exception e){ throw new DataException(e); } }  @Override List<Map<String, Object>> getComplianceTrendProgress(
            String assetGroup, LocalDate fromDate, String domain,
            Set<String> ruleCat); @Override List<Map<String, Object>> getTrendProgress(String assetGroup,
            String ruleId, LocalDate startDate, LocalDate endDate,
            String trendCategory); @Override List<Map<String, Object>> getTrendIssues(String assetGroup,
            LocalDate startDate, LocalDate endDate, Map<String, String> filter,
            Set<String> ruleSev); }
TrendRepositoryImpl implements TrendRepository, Constants { @Override public List<Map<String, Object>> getTrendIssues(String assetGroup, LocalDate startDate, LocalDate endDate, Map<String, String> filter, Set<String> ruleSev) throws DataException { String domain = filter.get(DOMAIN); List<String> severityList = new ArrayList<>(ruleSev); Map<String, Object> mustFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword("ag"), assetGroup); mustFilter.put(CommonUtils.convertAttributetoKeyword(DOMAIN), domain); Map<String, Object> rangeMap = new HashMap<>(); rangeMap.put("gte", startDate.format(DateTimeFormatter.ISO_DATE)); rangeMap.put("lte", endDate.format(DateTimeFormatter.ISO_DATE)); Map<String, Object> dateRangeMap = new HashMap<>(); dateRangeMap.put("date", rangeMap); mustFilter.put(RANGE, dateRangeMap); severityList.add("date"); severityList.add("total"); try{ return elasticSearchRepository.getSortedDataFromES(AG_STATS, "issues", mustFilter, null, null, severityList, null,null); }catch(Exception e){ throw new DataException(e); } }  @Override List<Map<String, Object>> getComplianceTrendProgress(
            String assetGroup, LocalDate fromDate, String domain,
            Set<String> ruleCat); @Override List<Map<String, Object>> getTrendProgress(String assetGroup,
            String ruleId, LocalDate startDate, LocalDate endDate,
            String trendCategory); @Override List<Map<String, Object>> getTrendIssues(String assetGroup,
            LocalDate startDate, LocalDate endDate, Map<String, String> filter,
            Set<String> ruleSev);  }