@Test public void getNonCompliantNumberForAgAndResourceTypeTest() throws Exception { Map<String, Long> nonCompliant = new HashMap<>(); nonCompliant.put("app1", 100l); nonCompliant.put("app2", 200l); AssetCountDTO assetcountByTypes = new AssetCountDTO(); assetcountByTypes.setType("ec2"); AssetCountDTO[] ec2TargetType = new AssetCountDTO[] { assetcountByTypes }; when( elasticSearchRepository.getTotalDistributionForIndexAndType(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyInt(), anyObject())).thenReturn(nonCompliant); when(filterRepository.getListOfTargetTypes(anyString(), anyString())).thenReturn(ec2TargetType); patchingRepositoryImpl.getNonCompliantNumberForAgAndResourceType("aws-all", "ec2"); assetcountByTypes = new AssetCountDTO(); assetcountByTypes.setType("onpremserver"); AssetCountDTO[] onpremTargetType = new AssetCountDTO[] { assetcountByTypes }; when(filterRepository.getListOfTargetTypes(anyString(), anyString())).thenReturn(onpremTargetType); patchingRepositoryImpl.getNonCompliantNumberForAgAndResourceType("aws-all", "onpremserver"); assetcountByTypes = new AssetCountDTO(); assetcountByTypes.setType("s3"); AssetCountDTO[] s3TargetType = new AssetCountDTO[] { assetcountByTypes }; when(filterRepository.getListOfTargetTypes(anyString(), anyString())).thenReturn(s3TargetType); patchingRepositoryImpl.getNonCompliantNumberForAgAndResourceType("aws-all", "ec2"); patchingRepositoryImpl.getNonCompliantNumberForAgAndResourceType("aws-all", "onpremserver"); assetcountByTypes = new AssetCountDTO(); AssetCountDTO[] emptyTargetType = new AssetCountDTO[] { assetcountByTypes }; when(filterRepository.getListOfTargetTypes(anyString(), anyString())).thenReturn(emptyTargetType); patchingRepositoryImpl.getNonCompliantNumberForAgAndResourceType("aws-all", "ec2"); when( elasticSearchRepository.getTotalDistributionForIndexAndType(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyInt(), anyObject())) .thenThrow(new RuntimeException()); when(filterRepository.getListOfTargetTypes(anyString(), anyString())).thenReturn(ec2TargetType); assertThatThrownBy(() -> patchingRepositoryImpl.getNonCompliantNumberForAgAndResourceType("aws-all", "ec2")) .isInstanceOf(DataException.class); }
@Override public Map<String, Long> getNonCompliantNumberForAgAndResourceType( String assetGroup, String resourceType) throws DataException { Map<String, Long> map = new HashMap<>(); Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword(ISSUE_STATUS), OPEN); String aggsFilterFieldName = CommonUtils .convertAttributetoKeyword(TAGS_APPLICATION); AssetCountDTO[] targetTypes = filterRepository.getListOfTargetTypes( assetGroup, null); for (AssetCountDTO targettype : targetTypes) { if (StringUtils.isNotBlank(targettype.getType())) { try{ if (EC2.equals(resourceType) && resourceType.equals(targettype.getType())) { mustFilter.put( CommonUtils.convertAttributetoKeyword(RULEID), EC2_KERNEL_COMPLIANCE_RULE); mustFilter.put(HAS_PARENT, addParentConditionPatching(EC2)); map = elasticSearchRepository .getTotalDistributionForIndexAndType(assetGroup + "/issue_ec2", null, mustFilter, mustNotFilter, null, aggsFilterFieldName, FIVE_THOUSAND, null); } } catch(Exception e){ throw new DataException(e); } } } return map; }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Long> getNonCompliantNumberForAgAndResourceType( String assetGroup, String resourceType) throws DataException { Map<String, Long> map = new HashMap<>(); Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword(ISSUE_STATUS), OPEN); String aggsFilterFieldName = CommonUtils .convertAttributetoKeyword(TAGS_APPLICATION); AssetCountDTO[] targetTypes = filterRepository.getListOfTargetTypes( assetGroup, null); for (AssetCountDTO targettype : targetTypes) { if (StringUtils.isNotBlank(targettype.getType())) { try{ if (EC2.equals(resourceType) && resourceType.equals(targettype.getType())) { mustFilter.put( CommonUtils.convertAttributetoKeyword(RULEID), EC2_KERNEL_COMPLIANCE_RULE); mustFilter.put(HAS_PARENT, addParentConditionPatching(EC2)); map = elasticSearchRepository .getTotalDistributionForIndexAndType(assetGroup + "/issue_ec2", null, mustFilter, mustNotFilter, null, aggsFilterFieldName, FIVE_THOUSAND, null); } } catch(Exception e){ throw new DataException(e); } } } return map; } }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Long> getNonCompliantNumberForAgAndResourceType( String assetGroup, String resourceType) throws DataException { Map<String, Long> map = new HashMap<>(); Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword(ISSUE_STATUS), OPEN); String aggsFilterFieldName = CommonUtils .convertAttributetoKeyword(TAGS_APPLICATION); AssetCountDTO[] targetTypes = filterRepository.getListOfTargetTypes( assetGroup, null); for (AssetCountDTO targettype : targetTypes) { if (StringUtils.isNotBlank(targettype.getType())) { try{ if (EC2.equals(resourceType) && resourceType.equals(targettype.getType())) { mustFilter.put( CommonUtils.convertAttributetoKeyword(RULEID), EC2_KERNEL_COMPLIANCE_RULE); mustFilter.put(HAS_PARENT, addParentConditionPatching(EC2)); map = elasticSearchRepository .getTotalDistributionForIndexAndType(assetGroup + "/issue_ec2", null, mustFilter, mustNotFilter, null, aggsFilterFieldName, FIVE_THOUSAND, null); } } catch(Exception e){ throw new DataException(e); } } } return map; }  }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Long> getNonCompliantNumberForAgAndResourceType( String assetGroup, String resourceType) throws DataException { Map<String, Long> map = new HashMap<>(); Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword(ISSUE_STATUS), OPEN); String aggsFilterFieldName = CommonUtils .convertAttributetoKeyword(TAGS_APPLICATION); AssetCountDTO[] targetTypes = filterRepository.getListOfTargetTypes( assetGroup, null); for (AssetCountDTO targettype : targetTypes) { if (StringUtils.isNotBlank(targettype.getType())) { try{ if (EC2.equals(resourceType) && resourceType.equals(targettype.getType())) { mustFilter.put( CommonUtils.convertAttributetoKeyword(RULEID), EC2_KERNEL_COMPLIANCE_RULE); mustFilter.put(HAS_PARENT, addParentConditionPatching(EC2)); map = elasticSearchRepository .getTotalDistributionForIndexAndType(assetGroup + "/issue_ec2", null, mustFilter, mustNotFilter, null, aggsFilterFieldName, FIVE_THOUSAND, null); } } catch(Exception e){ throw new DataException(e); } } } return map; }  @Override List<Map<String, Object>> getPatchingProgress(String assetGroup,
            LocalDate startDate, LocalDate endDate); @Override List<Map<String, Object>> getIssueInfo(String assetGroup); List<Map<String, Object>> getClosedIssueInfo(String assetGroup,
            int size); @Override List<Map<String, Object>> getInstanceInfo(String assetGroup,
            Map<String, String> filters); @Override List<Map<String, Object>> getExecAndDirectorInfo(); @Override long getInstanceInfoCount(String assetGroup,
            Map<String, String> filters, String searchText); @Override String getAmilAvailDate(int year, int quarter); @Override int getPatchingWindow(); @Override Map<String, Long> getQuartersWithPatchingData(String assetGroup); Map<String, Object> addParentConditionPatching(String targetType); @Override List<Map<String, Object>> getOnpremIssueInfo(String assetGroup); @Override List<Map<String, Object>> getOnpremResourceInfo(String assetGroup,
            Map<String, String> filters); @Override Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag,
            String appType); @Override Map<String, Long> getNonCompliantNumberForAgAndResourceType(
            String assetGroup, String resourceType); @Override List<Map<String, Object>> getPatchingPercentForDateRange(String assetGroup, LocalDate fromDate,
			LocalDate toDate); }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Long> getNonCompliantNumberForAgAndResourceType( String assetGroup, String resourceType) throws DataException { Map<String, Long> map = new HashMap<>(); Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> mustNotFilter = new HashMap<>(); mustFilter.put(CommonUtils.convertAttributetoKeyword(ISSUE_STATUS), OPEN); String aggsFilterFieldName = CommonUtils .convertAttributetoKeyword(TAGS_APPLICATION); AssetCountDTO[] targetTypes = filterRepository.getListOfTargetTypes( assetGroup, null); for (AssetCountDTO targettype : targetTypes) { if (StringUtils.isNotBlank(targettype.getType())) { try{ if (EC2.equals(resourceType) && resourceType.equals(targettype.getType())) { mustFilter.put( CommonUtils.convertAttributetoKeyword(RULEID), EC2_KERNEL_COMPLIANCE_RULE); mustFilter.put(HAS_PARENT, addParentConditionPatching(EC2)); map = elasticSearchRepository .getTotalDistributionForIndexAndType(assetGroup + "/issue_ec2", null, mustFilter, mustNotFilter, null, aggsFilterFieldName, FIVE_THOUSAND, null); } } catch(Exception e){ throw new DataException(e); } } } return map; }  @Override List<Map<String, Object>> getPatchingProgress(String assetGroup,
            LocalDate startDate, LocalDate endDate); @Override List<Map<String, Object>> getIssueInfo(String assetGroup); List<Map<String, Object>> getClosedIssueInfo(String assetGroup,
            int size); @Override List<Map<String, Object>> getInstanceInfo(String assetGroup,
            Map<String, String> filters); @Override List<Map<String, Object>> getExecAndDirectorInfo(); @Override long getInstanceInfoCount(String assetGroup,
            Map<String, String> filters, String searchText); @Override String getAmilAvailDate(int year, int quarter); @Override int getPatchingWindow(); @Override Map<String, Long> getQuartersWithPatchingData(String assetGroup); Map<String, Object> addParentConditionPatching(String targetType); @Override List<Map<String, Object>> getOnpremIssueInfo(String assetGroup); @Override List<Map<String, Object>> getOnpremResourceInfo(String assetGroup,
            Map<String, String> filters); @Override Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag,
            String appType); @Override Map<String, Long> getNonCompliantNumberForAgAndResourceType(
            String assetGroup, String resourceType); @Override List<Map<String, Object>> getPatchingPercentForDateRange(String assetGroup, LocalDate fromDate,
			LocalDate toDate);  }