@Test public void testCreateSecurityZone() throws Exception { RangerSecurityZone rangerSecurityZone = createRangerSecurityZone(); XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class); XXService xService = Mockito.mock(XXService.class); XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class); when(rangerBizUtil.isAdmin()).thenReturn(true); when(daoManager.getXXService()).thenReturn(xServiceDao); when(xServiceDao.findByName("test_service_1")).thenReturn(xService); when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao); when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef); when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator); doNothing().when(validator).validate(rangerSecurityZone, RangerValidator.Action.CREATE); when(securityZoneStore.createSecurityZone(rangerSecurityZone)).thenReturn(rangerSecurityZone); RangerSecurityZone createdRangerSecurityZone = securityZoneREST.createSecurityZone(rangerSecurityZone); assertEquals(createdRangerSecurityZone.getName(), rangerSecurityZone.getName()); verify(validator, times(1)).validate(rangerSecurityZone, RangerValidator.Action.CREATE); }
@POST @Path("/zones") public RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone) { if (LOG.isDebugEnabled()) { LOG.debug("==> createSecurityZone("+ securityZone + ")"); } RangerSecurityZone ret; try { ensureAdminAccess(securityZone); removeEmptyEntries(securityZone); RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore); validator.validate(securityZone, RangerValidator.Action.CREATE); ret = securityZoneStore.createSecurityZone(securityZone); } catch(WebApplicationException excp) { throw excp; } catch(Throwable excp) { LOG.error("createSecurityZone(" + securityZone + ") failed", excp); throw restErrorUtil.createRESTException(excp.getMessage()); } if (LOG.isDebugEnabled()) { LOG.debug("<== createSecurityZone("+ securityZone + "):" + ret); } return ret; }
SecurityZoneREST { @POST @Path("/zones") public RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone) { if (LOG.isDebugEnabled()) { LOG.debug("==> createSecurityZone("+ securityZone + ")"); } RangerSecurityZone ret; try { ensureAdminAccess(securityZone); removeEmptyEntries(securityZone); RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore); validator.validate(securityZone, RangerValidator.Action.CREATE); ret = securityZoneStore.createSecurityZone(securityZone); } catch(WebApplicationException excp) { throw excp; } catch(Throwable excp) { LOG.error("createSecurityZone(" + securityZone + ") failed", excp); throw restErrorUtil.createRESTException(excp.getMessage()); } if (LOG.isDebugEnabled()) { LOG.debug("<== createSecurityZone("+ securityZone + "):" + ret); } return ret; } }
SecurityZoneREST { @POST @Path("/zones") public RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone) { if (LOG.isDebugEnabled()) { LOG.debug("==> createSecurityZone("+ securityZone + ")"); } RangerSecurityZone ret; try { ensureAdminAccess(securityZone); removeEmptyEntries(securityZone); RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore); validator.validate(securityZone, RangerValidator.Action.CREATE); ret = securityZoneStore.createSecurityZone(securityZone); } catch(WebApplicationException excp) { throw excp; } catch(Throwable excp) { LOG.error("createSecurityZone(" + securityZone + ") failed", excp); throw restErrorUtil.createRESTException(excp.getMessage()); } if (LOG.isDebugEnabled()) { LOG.debug("<== createSecurityZone("+ securityZone + "):" + ret); } return ret; }  }
SecurityZoneREST { @POST @Path("/zones") public RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone) { if (LOG.isDebugEnabled()) { LOG.debug("==> createSecurityZone("+ securityZone + ")"); } RangerSecurityZone ret; try { ensureAdminAccess(securityZone); removeEmptyEntries(securityZone); RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore); validator.validate(securityZone, RangerValidator.Action.CREATE); ret = securityZoneStore.createSecurityZone(securityZone); } catch(WebApplicationException excp) { throw excp; } catch(Throwable excp) { LOG.error("createSecurityZone(" + securityZone + ") failed", excp); throw restErrorUtil.createRESTException(excp.getMessage()); } if (LOG.isDebugEnabled()) { LOG.debug("<== createSecurityZone("+ securityZone + "):" + ret); } return ret; }  @POST @Path("/zones") RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @PUT @Path("/zones/{id}") RangerSecurityZone updateSecurityZone(@PathParam("id") Long zoneId,
                                                 RangerSecurityZone securityZone); @DELETE @Path("/zones/name/{name}") void deleteSecurityZone(@PathParam("name") String zoneName); @DELETE @Path("/zones/{id}") void deleteSecurityZone(@PathParam("id") Long zoneId); @GET @Path("/zones/name/{name}") RangerSecurityZone getSecurityZone(@PathParam("name") String zoneName); @GET @Path("/zones/{id}") RangerSecurityZone getSecurityZone(@PathParam("id") Long id); @GET @Path("/zones") RangerSecurityZoneList getAllZones(@Context HttpServletRequest request); }
SecurityZoneREST { @POST @Path("/zones") public RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone) { if (LOG.isDebugEnabled()) { LOG.debug("==> createSecurityZone("+ securityZone + ")"); } RangerSecurityZone ret; try { ensureAdminAccess(securityZone); removeEmptyEntries(securityZone); RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore); validator.validate(securityZone, RangerValidator.Action.CREATE); ret = securityZoneStore.createSecurityZone(securityZone); } catch(WebApplicationException excp) { throw excp; } catch(Throwable excp) { LOG.error("createSecurityZone(" + securityZone + ") failed", excp); throw restErrorUtil.createRESTException(excp.getMessage()); } if (LOG.isDebugEnabled()) { LOG.debug("<== createSecurityZone("+ securityZone + "):" + ret); } return ret; }  @POST @Path("/zones") RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @PUT @Path("/zones/{id}") RangerSecurityZone updateSecurityZone(@PathParam("id") Long zoneId,
                                                 RangerSecurityZone securityZone); @DELETE @Path("/zones/name/{name}") void deleteSecurityZone(@PathParam("name") String zoneName); @DELETE @Path("/zones/{id}") void deleteSecurityZone(@PathParam("id") Long zoneId); @GET @Path("/zones/name/{name}") RangerSecurityZone getSecurityZone(@PathParam("name") String zoneName); @GET @Path("/zones/{id}") RangerSecurityZone getSecurityZone(@PathParam("id") Long id); @GET @Path("/zones") RangerSecurityZoneList getAllZones(@Context HttpServletRequest request);  }