@Test public void getRegionsTest() throws Exception { Map<String, Long> regionMap = new HashMap<>(); regionMap.put("us-east-1", 1l); regionMap.put("us-west-2", 2l); when(repository.getRegionsFromES(anyString())) .thenReturn(regionMap); assertThat(filterServiceImpl.getRegions("dummyString"), is(notNullValue())); when(filterServiceImpl.getRegions(anyString())).thenThrow(new DataException()); assertThatThrownBy( () -> filterServiceImpl.getRegions("qwe")).isInstanceOf(ServiceException.class); }
public List<Map<String, Object>> getRegions(String assetGroup) throws ServiceException { Map<String, Long> regionsMap; List<Map<String, Object>> regions = new ArrayList<>(); try{ regionsMap = repository.getRegionsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } if (regionsMap.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } regionsMap.entrySet().parallelStream().forEach(region -> { Map<String, Object> regMap = new HashMap<>(); if (StringUtils.isNotBlank(region.getKey())) { regMap.put(NAME, region.getKey()); regMap.put(ID, region.getKey()); synchronized (regions) { regions.add(regMap); } } }); if(regions.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return regions; }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getRegions(String assetGroup) throws ServiceException { Map<String, Long> regionsMap; List<Map<String, Object>> regions = new ArrayList<>(); try{ regionsMap = repository.getRegionsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } if (regionsMap.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } regionsMap.entrySet().parallelStream().forEach(region -> { Map<String, Object> regMap = new HashMap<>(); if (StringUtils.isNotBlank(region.getKey())) { regMap.put(NAME, region.getKey()); regMap.put(ID, region.getKey()); synchronized (regions) { regions.add(regMap); } } }); if(regions.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return regions; } }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getRegions(String assetGroup) throws ServiceException { Map<String, Long> regionsMap; List<Map<String, Object>> regions = new ArrayList<>(); try{ regionsMap = repository.getRegionsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } if (regionsMap.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } regionsMap.entrySet().parallelStream().forEach(region -> { Map<String, Object> regMap = new HashMap<>(); if (StringUtils.isNotBlank(region.getKey())) { regMap.put(NAME, region.getKey()); regMap.put(ID, region.getKey()); synchronized (regions) { regions.add(regMap); } } }); if(regions.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return regions; }  }
FilterServiceImpl implements FilterService, Constants { public List<Map<String, Object>> getRegions(String assetGroup) throws ServiceException { Map<String, Long> regionsMap; List<Map<String, Object>> regions = new ArrayList<>(); try{ regionsMap = repository.getRegionsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } if (regionsMap.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } regionsMap.entrySet().parallelStream().forEach(region -> { Map<String, Object> regMap = new HashMap<>(); if (StringUtils.isNotBlank(region.getKey())) { regMap.put(NAME, region.getKey()); regMap.put(ID, region.getKey()); synchronized (regions) { regions.add(regMap); } } }); if(regions.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return regions; }  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>> getRegions(String assetGroup) throws ServiceException { Map<String, Long> regionsMap; List<Map<String, Object>> regions = new ArrayList<>(); try{ regionsMap = repository.getRegionsFromES(assetGroup); }catch(DataException e){ throw new ServiceException(e); } if (regionsMap.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } regionsMap.entrySet().parallelStream().forEach(region -> { Map<String, Object> regMap = new HashMap<>(); if (StringUtils.isNotBlank(region.getKey())) { regMap.put(NAME, region.getKey()); regMap.put(ID, region.getKey()); synchronized (regions) { regions.add(regMap); } } }); if(regions.isEmpty()){ throw new ServiceException(NO_DATA_FOUND); } return regions; }  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);  }