@Test public void getAccountsTest() throws Exception { Map<String, Object> accountMap = new HashMap<>(); List<Map<String, Object>> accountList = new ArrayList<>(); accountMap.put("accountid", "12345678"); accountMap.put("accountname", "JON DOE"); accountMap.put("_id", "12345678"); accountList.add(accountMap); when(repository.getAccountsFromES(anyString())) .thenReturn(accountList); assertThat(filterServiceImpl.getAccounts("dummyString"), is(notNullValue())); when(repository.getAccountsFromES(anyString())).thenThrow(new DataException()); assertThatThrownBy( () -> filterServiceImpl.getAccounts("dummyString")).isInstanceOf(ServiceException.class); }
public List<Map<String, Object>> getAccounts(String assetGroup) throws ServiceException { List<Map<String, Object>> accounts; try{ accounts = repository.getAccountsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } List<Map<String, Object>> accountDetails = new ArrayList<>(); noDataFoundCheck(emptyAssetCount, accounts); accounts.parallelStream().forEach(account -> { Map<String, Object> accMap = new HashMap<>(); accMap.put(NAME, account.get(ACCOUNT_NAME)); accMap.put(ID, account.get(ACCOUNT_ID)); synchronized (accountDetails) { accountDetails.add(accMap); } }); if(accountDetails.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return accountDetails; }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getAccounts(String assetGroup) throws ServiceException { List<Map<String, Object>> accounts; try{ accounts = repository.getAccountsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } List<Map<String, Object>> accountDetails = new ArrayList<>(); noDataFoundCheck(emptyAssetCount, accounts); accounts.parallelStream().forEach(account -> { Map<String, Object> accMap = new HashMap<>(); accMap.put(NAME, account.get(ACCOUNT_NAME)); accMap.put(ID, account.get(ACCOUNT_ID)); synchronized (accountDetails) { accountDetails.add(accMap); } }); if(accountDetails.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return accountDetails; } }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getAccounts(String assetGroup) throws ServiceException { List<Map<String, Object>> accounts; try{ accounts = repository.getAccountsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } List<Map<String, Object>> accountDetails = new ArrayList<>(); noDataFoundCheck(emptyAssetCount, accounts); accounts.parallelStream().forEach(account -> { Map<String, Object> accMap = new HashMap<>(); accMap.put(NAME, account.get(ACCOUNT_NAME)); accMap.put(ID, account.get(ACCOUNT_ID)); synchronized (accountDetails) { accountDetails.add(accMap); } }); if(accountDetails.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return accountDetails; }  }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getAccounts(String assetGroup) throws ServiceException { List<Map<String, Object>> accounts; try{ accounts = repository.getAccountsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } List<Map<String, Object>> accountDetails = new ArrayList<>(); noDataFoundCheck(emptyAssetCount, accounts); accounts.parallelStream().forEach(account -> { Map<String, Object> accMap = new HashMap<>(); accMap.put(NAME, account.get(ACCOUNT_NAME)); accMap.put(ID, account.get(ACCOUNT_ID)); synchronized (accountDetails) { accountDetails.add(accMap); } }); if(accountDetails.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return accountDetails; }  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>> getAccounts(String assetGroup) throws ServiceException { List<Map<String, Object>> accounts; try{ accounts = repository.getAccountsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } List<Map<String, Object>> accountDetails = new ArrayList<>(); noDataFoundCheck(emptyAssetCount, accounts); accounts.parallelStream().forEach(account -> { Map<String, Object> accMap = new HashMap<>(); accMap.put(NAME, account.get(ACCOUNT_NAME)); accMap.put(ID, account.get(ACCOUNT_ID)); synchronized (accountDetails) { accountDetails.add(accMap); } }); if(accountDetails.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return accountDetails; }  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);  }