@Test public void test11searchPolicies() throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); RangerService service = rangerService(); RangerPolicy policy = rangerPolicy(); List<RangerPolicy> policyList = new ArrayList<RangerPolicy>(); policyList.add(policy); VXPolicy vXPolicy = vXPolicy(policy, service); List<VXPolicy> vXPolicies = new ArrayList<VXPolicy>(); vXPolicies.add(vXPolicy); VXPolicyList vXPolicyList = new VXPolicyList(vXPolicies); SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.POLICY_NAME, "policyName"); filter.setParam(SearchFilter.SERVICE_NAME, "serviceName"); filter.setStartIndex(0); filter.setMaxRows(10); Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields)).thenReturn(filter); Mockito.when(serviceREST.getPolicies(filter)).thenReturn(policyList); Mockito.when(serviceUtil.rangerPolicyListToPublic(policyList,filter)).thenReturn(vXPolicyList); VXPolicyList dbVXPolicyList = publicAPIs.searchPolicies(request); Assert.assertNotNull(dbVXPolicyList); Assert.assertEquals(dbVXPolicyList.getResultSize(), vXPolicyList.getResultSize()); Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields); Mockito.verify(serviceREST).getPolicies(filter); Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList,filter); }
@GET @Path("/api/policy") @Produces({ "application/json", "application/xml" }) public VXPolicyList searchPolicies(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.searchPolicies(): "); } SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields); int savedStartIndex = filter.getStartIndex(); int savedMaxRows = filter.getMaxRows(); filter.setStartIndex(0); filter.setMaxRows(Integer.MAX_VALUE); List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter); filter.setStartIndex(savedStartIndex); filter.setMaxRows(savedMaxRows); VXPolicyList vXPolicyList = null; if (rangerPolicyList != null) { vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList,filter); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList ); } return vXPolicyList; }
PublicAPIs { @GET @Path("/api/policy") @Produces({ "application/json", "application/xml" }) public VXPolicyList searchPolicies(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.searchPolicies(): "); } SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields); int savedStartIndex = filter.getStartIndex(); int savedMaxRows = filter.getMaxRows(); filter.setStartIndex(0); filter.setMaxRows(Integer.MAX_VALUE); List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter); filter.setStartIndex(savedStartIndex); filter.setMaxRows(savedMaxRows); VXPolicyList vXPolicyList = null; if (rangerPolicyList != null) { vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList,filter); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList ); } return vXPolicyList; } }
PublicAPIs { @GET @Path("/api/policy") @Produces({ "application/json", "application/xml" }) public VXPolicyList searchPolicies(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.searchPolicies(): "); } SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields); int savedStartIndex = filter.getStartIndex(); int savedMaxRows = filter.getMaxRows(); filter.setStartIndex(0); filter.setMaxRows(Integer.MAX_VALUE); List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter); filter.setStartIndex(savedStartIndex); filter.setMaxRows(savedMaxRows); VXPolicyList vXPolicyList = null; if (rangerPolicyList != null) { vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList,filter); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList ); } return vXPolicyList; }  }
PublicAPIs { @GET @Path("/api/policy") @Produces({ "application/json", "application/xml" }) public VXPolicyList searchPolicies(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.searchPolicies(): "); } SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields); int savedStartIndex = filter.getStartIndex(); int savedMaxRows = filter.getMaxRows(); filter.setStartIndex(0); filter.setMaxRows(Integer.MAX_VALUE); List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter); filter.setStartIndex(savedStartIndex); filter.setMaxRows(savedMaxRows); VXPolicyList vXPolicyList = null; if (rangerPolicyList != null) { vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList,filter); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList ); } return vXPolicyList; }  @GET @Path("/api/repository/{id}") @Produces({ "application/json", "application/xml" }) VXRepository getRepository(@PathParam("id") Long id); @POST @Path("/api/repository/") @Produces({ "application/json", "application/xml" }) VXRepository createRepository(VXRepository vXRepository); @PUT @Path("/api/repository/{id}") @Produces({ "application/json", "application/xml" }) VXRepository updateRepository(VXRepository vXRepository,
			@PathParam("id") Long id); @DELETE @Path("/api/repository/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXAsset.class) void deleteRepository(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/api/repository/") @Produces({ "application/json", "application/xml" }) VXRepositoryList searchRepositories(
			@Context HttpServletRequest request); @GET @Path("/api/repository/count") @Produces({ "application/json", "application/xml" }) VXLong countRepositories(@Context HttpServletRequest request); @GET @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) VXPolicy getPolicy(@PathParam("id") Long id); @POST @Path("/api/policy") @Produces({ "application/json", "application/xml" }) VXPolicy createPolicy(VXPolicy vXPolicy); @PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id); @DELETE @Path("/api/policy/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXResource.class) void deletePolicy(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/api/policy") @Produces({ "application/json", "application/xml" }) VXPolicyList searchPolicies(@Context HttpServletRequest request); @GET @Path("/api/policy/count") @Produces({ "application/xml", "application/json" }) VXLong countPolicies(@Context HttpServletRequest request); }
PublicAPIs { @GET @Path("/api/policy") @Produces({ "application/json", "application/xml" }) public VXPolicyList searchPolicies(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.searchPolicies(): "); } SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields); int savedStartIndex = filter.getStartIndex(); int savedMaxRows = filter.getMaxRows(); filter.setStartIndex(0); filter.setMaxRows(Integer.MAX_VALUE); List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter); filter.setStartIndex(savedStartIndex); filter.setMaxRows(savedMaxRows); VXPolicyList vXPolicyList = null; if (rangerPolicyList != null) { vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList,filter); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList ); } return vXPolicyList; }  @GET @Path("/api/repository/{id}") @Produces({ "application/json", "application/xml" }) VXRepository getRepository(@PathParam("id") Long id); @POST @Path("/api/repository/") @Produces({ "application/json", "application/xml" }) VXRepository createRepository(VXRepository vXRepository); @PUT @Path("/api/repository/{id}") @Produces({ "application/json", "application/xml" }) VXRepository updateRepository(VXRepository vXRepository,
			@PathParam("id") Long id); @DELETE @Path("/api/repository/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXAsset.class) void deleteRepository(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/api/repository/") @Produces({ "application/json", "application/xml" }) VXRepositoryList searchRepositories(
			@Context HttpServletRequest request); @GET @Path("/api/repository/count") @Produces({ "application/json", "application/xml" }) VXLong countRepositories(@Context HttpServletRequest request); @GET @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) VXPolicy getPolicy(@PathParam("id") Long id); @POST @Path("/api/policy") @Produces({ "application/json", "application/xml" }) VXPolicy createPolicy(VXPolicy vXPolicy); @PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id); @DELETE @Path("/api/policy/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXResource.class) void deletePolicy(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/api/policy") @Produces({ "application/json", "application/xml" }) VXPolicyList searchPolicies(@Context HttpServletRequest request); @GET @Path("/api/policy/count") @Produces({ "application/xml", "application/json" }) VXLong countPolicies(@Context HttpServletRequest request);  }