SecurityZoneREST { @GET @Path("/zones") public RangerSecurityZoneList getAllZones(@Context HttpServletRequest request) { RangerSecurityZoneList ret = new RangerSecurityZoneList(); if (LOG.isDebugEnabled()) { LOG.debug("==> getAllZones()"); } SearchFilter filter = searchUtil.getSearchFilter(request, securityZoneService.sortFields); List<RangerSecurityZone> securityZones; try { securityZones = securityZoneStore.getSecurityZones(filter); ret.setSecurityZoneList(securityZones); if (securityZones != null) { ret.setTotalCount(securityZones.size()); ret.setSortBy(filter.getSortBy()); ret.setSortType(filter.getSortType()); ret.setResultSize(securityZones.size()); } } catch(WebApplicationException excp) { throw excp; } catch(Throwable excp) { LOG.error("getSecurityZones() failed", excp); throw restErrorUtil.createRESTException(excp.getMessage()); } if (LOG.isDebugEnabled()) { LOG.debug("<== getAllZones():" + 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 testGetAllSecurityZone() throws Exception { RangerSecurityZone securityZone = createRangerSecurityZone(); HttpServletRequest request = Mockito.mock(HttpServletRequest.class); SearchFilter filter = new SearchFilter(); when( searchUtil.getSearchFilter(request, securityZoneService.sortFields)) .thenReturn(filter); Long securityZoneId = 2L; securityZone.setId(securityZoneId); List<RangerSecurityZone> zonesList = new ArrayList<>(); zonesList.add(securityZone); RangerSecurityZoneList rangerZoneList = new RangerSecurityZoneList(); rangerZoneList.setSecurityZoneList(zonesList); when(securityZoneStore.getSecurityZones(filter)).thenReturn(zonesList); RangerSecurityZoneList returnedZonesList = securityZoneREST.getAllZones(request); assertEquals(returnedZonesList.getResultSize(), rangerZoneList.getList().size()); verify(securityZoneStore, times(1)).getSecurityZones(filter); }