@Test public void test7getSecurityZonesForService() throws Exception { String serviceName = "hdfs_service"; Map<String, RangerSecurityZone.RangerSecurityZoneService> retMap = null; SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.ZONE_NAME, "sz1"); filter.setParam(SearchFilter.SERVICE_NAME, serviceName); List<RangerSecurityZone> ret = new ArrayList<>(); List<XXSecurityZone> xxSecurityZones = new ArrayList<XXSecurityZone>(); XXSecurityZone xxSecurityZone = new XXSecurityZone(); xxSecurityZone.setId(2L); xxSecurityZone.setName("sz1"); xxSecurityZones.add(xxSecurityZone); RangerSecurityZone rangerSecurityZone = new RangerSecurityZone(); rangerSecurityZone.setId(3L); ret.add(rangerSecurityZone); XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class); Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao); Mockito.when(xXSecurityZoneDao.getAll()).thenReturn(xxSecurityZones); Mockito.when(securityZoneService.read(xxSecurityZone.getId())).thenReturn(rangerSecurityZone); retMap = new HashMap<>(); retMap.put(rangerSecurityZone.getName(), rangerSecurityZone.getServices().get(serviceName)); securityZoneDBStore.getSecurityZonesForService(serviceName); Assert.assertNotNull(xxSecurityZone); Assert.assertNotNull(xxSecurityZones); Mockito.verify(daoManager).getXXSecurityZoneDao(); Mockito.verify(securityZoneService).read(xxSecurityZone.getId()); }
@Override public Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName) { Map<String, RangerSecurityZone.RangerSecurityZoneService> ret = null; SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.SERVICE_NAME, serviceName); try { List<RangerSecurityZone> matchingZones = getSecurityZones(filter); if (CollectionUtils.isNotEmpty(matchingZones)) { ret = new HashMap<>(); for (RangerSecurityZone matchingZone : matchingZones) { ret.put(matchingZone.getName(), matchingZone.getServices().get(serviceName)); } } } catch (Exception excp) { LOG.error("Failed to get security zones for service:[" + serviceName + "]", excp); } return ret; }
SecurityZoneDBStore implements SecurityZoneStore { @Override public Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName) { Map<String, RangerSecurityZone.RangerSecurityZoneService> ret = null; SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.SERVICE_NAME, serviceName); try { List<RangerSecurityZone> matchingZones = getSecurityZones(filter); if (CollectionUtils.isNotEmpty(matchingZones)) { ret = new HashMap<>(); for (RangerSecurityZone matchingZone : matchingZones) { ret.put(matchingZone.getName(), matchingZone.getServices().get(serviceName)); } } } catch (Exception excp) { LOG.error("Failed to get security zones for service:[" + serviceName + "]", excp); } return ret; } }
SecurityZoneDBStore implements SecurityZoneStore { @Override public Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName) { Map<String, RangerSecurityZone.RangerSecurityZoneService> ret = null; SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.SERVICE_NAME, serviceName); try { List<RangerSecurityZone> matchingZones = getSecurityZones(filter); if (CollectionUtils.isNotEmpty(matchingZones)) { ret = new HashMap<>(); for (RangerSecurityZone matchingZone : matchingZones) { ret.put(matchingZone.getName(), matchingZone.getServices().get(serviceName)); } } } catch (Exception excp) { LOG.error("Failed to get security zones for service:[" + serviceName + "]", excp); } return ret; }  }
SecurityZoneDBStore implements SecurityZoneStore { @Override public Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName) { Map<String, RangerSecurityZone.RangerSecurityZoneService> ret = null; SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.SERVICE_NAME, serviceName); try { List<RangerSecurityZone> matchingZones = getSecurityZones(filter); if (CollectionUtils.isNotEmpty(matchingZones)) { ret = new HashMap<>(); for (RangerSecurityZone matchingZone : matchingZones) { ret.put(matchingZone.getName(), matchingZone.getServices().get(serviceName)); } } } catch (Exception excp) { LOG.error("Failed to get security zones for service:[" + serviceName + "]", excp); } return ret; }  void init(); @PostConstruct void initStore(); @Override RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @Override RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone); @Override void deleteSecurityZoneByName(String zoneName); @Override void deleteSecurityZoneById(Long zoneId); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZoneByName(String name); @Override List<RangerSecurityZone> getSecurityZones(SearchFilter filter); @Override Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName); }
SecurityZoneDBStore implements SecurityZoneStore { @Override public Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName) { Map<String, RangerSecurityZone.RangerSecurityZoneService> ret = null; SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.SERVICE_NAME, serviceName); try { List<RangerSecurityZone> matchingZones = getSecurityZones(filter); if (CollectionUtils.isNotEmpty(matchingZones)) { ret = new HashMap<>(); for (RangerSecurityZone matchingZone : matchingZones) { ret.put(matchingZone.getName(), matchingZone.getServices().get(serviceName)); } } } catch (Exception excp) { LOG.error("Failed to get security zones for service:[" + serviceName + "]", excp); } return ret; }  void init(); @PostConstruct void initStore(); @Override RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @Override RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone); @Override void deleteSecurityZoneByName(String zoneName); @Override void deleteSecurityZoneById(Long zoneId); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZoneByName(String name); @Override List<RangerSecurityZone> getSecurityZones(SearchFilter filter); @Override Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName);  }