SecurityZoneREST { @GET @Path("/zones/name/{name}") public RangerSecurityZone getSecurityZone(@PathParam("name") String zoneName) { if (LOG.isDebugEnabled()) { LOG.debug("==> getSecurityZone(name=" + zoneName + ")"); } RangerSecurityZone ret; try { ret = securityZoneStore.getSecurityZoneByName(zoneName); } catch(WebApplicationException excp) { throw excp; } catch(Throwable excp) { LOG.error("getSecurityZone(" + zoneName + ") failed", excp); throw restErrorUtil.createRESTException(excp.getMessage()); } if (LOG.isDebugEnabled()) { LOG.debug("<== getSecurityZone(name=" + zoneName + "):" + 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);  }
@Test public void testGetSecurityZoneById() throws Exception { RangerSecurityZone securityZone = createRangerSecurityZone(); Long securityZoneId = 2L; securityZone.setId(securityZoneId); when(securityZoneStore.getSecurityZone(securityZoneId)).thenReturn(securityZone); RangerSecurityZone rangerSecurityZone = securityZoneREST.getSecurityZone(securityZoneId); assertEquals(securityZoneId, rangerSecurityZone.getId()); verify(securityZoneStore, times(1)).getSecurityZone(securityZoneId); }
@Test public void testGetSecurityZoneByName() throws Exception { RangerSecurityZone securityZone = createRangerSecurityZone(); Long securityZoneId = 2L; String securityZoneName = securityZone.getName(); securityZone.setId(securityZoneId); when(securityZoneStore.getSecurityZoneByName(securityZoneName)).thenReturn(securityZone); RangerSecurityZone rangerSecurityZone = securityZoneREST.getSecurityZone(securityZoneName); assertEquals(securityZoneName, rangerSecurityZone.getName()); verify(securityZoneStore, times(1)).getSecurityZoneByName(securityZoneName); }