@Test public void getPoliciesTest() throws Exception { String targetTypes = "'ec2','s3','volume'"; Map<String, Object> policyMap = new HashMap<>(); List<Map<String, Object>> policyList = new ArrayList<>(); policyMap.put("policyId", "Policy"); policyMap.put("PolicyName", "policyId.keyword"); policyList.add(policyMap); when(complainceRepository.getTargetTypeForAG(anyString(),anyString())) .thenReturn(targetTypes); when(repository.getPoliciesFromDB(anyString())) .thenReturn(policyList); assertThat(filterServiceImpl.getPolicies("dummyString", "test"), is(notNullValue())); when(repository.getPoliciesFromDB(anyString())).thenThrow(new DataException()); assertThatThrownBy( () -> filterServiceImpl.getPolicies("www","qwe")).isInstanceOf(ServiceException.class); }
public List<Map<String, Object>> getPolicies(String assetGroup, String domain) throws ServiceException { List<Map<String, Object>> policyDetList = new ArrayList<>(); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> policyIdsFromDb; try{ policyIdsFromDb= repository .getPoliciesFromDB(ttypes); }catch(DataException e){ throw new ServiceException(e); } noDataFoundCheck(emptyAssetCount, policyIdsFromDb); policyIdsFromDb.parallelStream().forEach(policy -> { Map<String, Object> policyMap = new HashMap<>(); String policyId = policy.get(Constants.POLICYID).toString(); String policyName = policy.get(POLICY_DISPLAY_NAME).toString(); policyMap.put(NAME, policyName); policyMap.put(ID, policyId); synchronized (policyDetList) { policyDetList.add(policyMap); } }); if(policyDetList.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return policyDetList; }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getPolicies(String assetGroup, String domain) throws ServiceException { List<Map<String, Object>> policyDetList = new ArrayList<>(); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> policyIdsFromDb; try{ policyIdsFromDb= repository .getPoliciesFromDB(ttypes); }catch(DataException e){ throw new ServiceException(e); } noDataFoundCheck(emptyAssetCount, policyIdsFromDb); policyIdsFromDb.parallelStream().forEach(policy -> { Map<String, Object> policyMap = new HashMap<>(); String policyId = policy.get(Constants.POLICYID).toString(); String policyName = policy.get(POLICY_DISPLAY_NAME).toString(); policyMap.put(NAME, policyName); policyMap.put(ID, policyId); synchronized (policyDetList) { policyDetList.add(policyMap); } }); if(policyDetList.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return policyDetList; } }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getPolicies(String assetGroup, String domain) throws ServiceException { List<Map<String, Object>> policyDetList = new ArrayList<>(); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> policyIdsFromDb; try{ policyIdsFromDb= repository .getPoliciesFromDB(ttypes); }catch(DataException e){ throw new ServiceException(e); } noDataFoundCheck(emptyAssetCount, policyIdsFromDb); policyIdsFromDb.parallelStream().forEach(policy -> { Map<String, Object> policyMap = new HashMap<>(); String policyId = policy.get(Constants.POLICYID).toString(); String policyName = policy.get(POLICY_DISPLAY_NAME).toString(); policyMap.put(NAME, policyName); policyMap.put(ID, policyId); synchronized (policyDetList) { policyDetList.add(policyMap); } }); if(policyDetList.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return policyDetList; }  }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getPolicies(String assetGroup, String domain) throws ServiceException { List<Map<String, Object>> policyDetList = new ArrayList<>(); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> policyIdsFromDb; try{ policyIdsFromDb= repository .getPoliciesFromDB(ttypes); }catch(DataException e){ throw new ServiceException(e); } noDataFoundCheck(emptyAssetCount, policyIdsFromDb); policyIdsFromDb.parallelStream().forEach(policy -> { Map<String, Object> policyMap = new HashMap<>(); String policyId = policy.get(Constants.POLICYID).toString(); String policyName = policy.get(POLICY_DISPLAY_NAME).toString(); policyMap.put(NAME, policyName); policyMap.put(ID, policyId); synchronized (policyDetList) { policyDetList.add(policyMap); } }); if(policyDetList.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return policyDetList; }  List<Map<String, Object>> getFilters(int filterId, String domain); List<Map<String, Object>> getPolicies(String assetGroup,
            String domain); List<Map<String, Object>> getRegions(String assetGroup); List<Map<String, Object>> getAccounts(String assetGroup); List<Map<String, Object>> getRules(String assetGroup, String domain); List<Map<String, Object>> getApplications(String assetGroup,
            String domain); List<Map<String, Object>> getEnvironmentsByAssetGroup(
            String assetGroup, String application, String domain); List<Map<String, Object>> getTargetTypesForAssetGroup(
            String assetGroup, String domain); }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getPolicies(String assetGroup, String domain) throws ServiceException { List<Map<String, Object>> policyDetList = new ArrayList<>(); String ttypes = complianceRepository.getTargetTypeForAG(assetGroup, domain); List<Map<String, Object>> policyIdsFromDb; try{ policyIdsFromDb= repository .getPoliciesFromDB(ttypes); }catch(DataException e){ throw new ServiceException(e); } noDataFoundCheck(emptyAssetCount, policyIdsFromDb); policyIdsFromDb.parallelStream().forEach(policy -> { Map<String, Object> policyMap = new HashMap<>(); String policyId = policy.get(Constants.POLICYID).toString(); String policyName = policy.get(POLICY_DISPLAY_NAME).toString(); policyMap.put(NAME, policyName); policyMap.put(ID, policyId); synchronized (policyDetList) { policyDetList.add(policyMap); } }); if(policyDetList.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return policyDetList; }  List<Map<String, Object>> getFilters(int filterId, String domain); List<Map<String, Object>> getPolicies(String assetGroup,
            String domain); List<Map<String, Object>> getRegions(String assetGroup); List<Map<String, Object>> getAccounts(String assetGroup); List<Map<String, Object>> getRules(String assetGroup, String domain); List<Map<String, Object>> getApplications(String assetGroup,
            String domain); List<Map<String, Object>> getEnvironmentsByAssetGroup(
            String assetGroup, String application, String domain); List<Map<String, Object>> getTargetTypesForAssetGroup(
            String assetGroup, String domain);  }