PublicAPIs { @POST @Path("/api/policy") @Produces({ "application/json", "application/xml" }) public VXPolicy createPolicy(VXPolicy vXPolicy) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.createPolicy()"); } RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName()); RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy,service); VXPolicy ret = null; if(policy != null) { if(logger.isDebugEnabled()) { logger.debug("RANGERPOLICY: " + policy.toString()); } RangerPolicy createdPolicy = serviceREST.createPolicy(policy,null); ret = serviceUtil.toVXPolicy(createdPolicy, service); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.createPolicy(" + policy + "): " + ret); } return ret; }  @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);  }
@Test public void test8createPolicy() throws Exception { RangerPolicy policy = rangerPolicy(); RangerService service = rangerService(); VXPolicy vXPolicy = vXPolicy(policy, service); Mockito.when(serviceREST.getServiceByName(vXPolicy.getRepositoryName())).thenReturn(service); Mockito.when(serviceUtil.toRangerPolicy(vXPolicy,service)).thenReturn(policy); Mockito.when(serviceREST.createPolicy(policy, null)).thenReturn(policy); Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy); VXPolicy dbVXPolicy = publicAPIs.createPolicy(vXPolicy); Assert.assertNotNull(dbVXPolicy); Assert.assertEquals(dbVXPolicy, vXPolicy); Assert.assertEquals(dbVXPolicy.getId(), vXPolicy.getId()); Assert.assertEquals(dbVXPolicy.getRepositoryName(), vXPolicy.getRepositoryName()); Mockito.verify(serviceREST).createPolicy(policy, null); Mockito.verify(serviceREST).getServiceByName(vXPolicy.getRepositoryName()); Mockito.verify(serviceUtil).toVXPolicy(policy, service); Mockito.verify(serviceUtil).toRangerPolicy(vXPolicy,service); }