@Test public void test9updatePolicy() throws Exception { RangerPolicy policy = rangerPolicy(); RangerService service = rangerService(); VXPolicy vXPolicy = vXPolicy(policy, service); XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class); XXPolicy xXPolicy = policy(); Mockito.when(daoMgr.getXXPolicy()).thenReturn(xXPolicyDao); Mockito.when(xXPolicyDao.getById(Id)).thenReturn(xXPolicy); Mockito.when(serviceREST.getServiceByName(vXPolicy.getRepositoryName())).thenReturn(service); Mockito.when(serviceUtil.toRangerPolicy(vXPolicy,service)).thenReturn(policy); Mockito.when(serviceREST.updatePolicy(policy)).thenReturn(policy); Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy); VXPolicy dbVXPolicy = publicAPIs.updatePolicy(vXPolicy, Id); Assert.assertNotNull(dbVXPolicy); Assert.assertEquals(dbVXPolicy, vXPolicy); Assert.assertEquals(dbVXPolicy.getId(), vXPolicy.getId()); Assert.assertEquals(dbVXPolicy.getRepositoryName(), vXPolicy.getRepositoryName()); Mockito.verify(serviceREST).updatePolicy(policy); Mockito.verify(serviceREST).getServiceByName(vXPolicy.getRepositoryName()); Mockito.verify(serviceUtil).toVXPolicy(policy, service); Mockito.verify(serviceUtil).toRangerPolicy(vXPolicy,service); Mockito.verify(daoMgr).getXXPolicy(); Mockito.verify(xXPolicyDao).getById(Id); }
@PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy ); } XXPolicy existing = daoMgr.getXXPolicy().getById(id); if(existing == null) { throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND); } vXPolicy.setId(id); RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName()); RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy,service); VXPolicy ret = null; if(policy != null) { policy.setVersion(existing.getVersion()); RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy); ret = serviceUtil.toVXPolicy(updatedPolicy, service); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.updatePolicy(" + policy + "): " + ret); } return ret; }
PublicAPIs { @PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy ); } XXPolicy existing = daoMgr.getXXPolicy().getById(id); if(existing == null) { throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND); } vXPolicy.setId(id); RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName()); RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy,service); VXPolicy ret = null; if(policy != null) { policy.setVersion(existing.getVersion()); RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy); ret = serviceUtil.toVXPolicy(updatedPolicy, service); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.updatePolicy(" + policy + "): " + ret); } return ret; } }
PublicAPIs { @PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy ); } XXPolicy existing = daoMgr.getXXPolicy().getById(id); if(existing == null) { throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND); } vXPolicy.setId(id); RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName()); RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy,service); VXPolicy ret = null; if(policy != null) { policy.setVersion(existing.getVersion()); RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy); ret = serviceUtil.toVXPolicy(updatedPolicy, service); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.updatePolicy(" + policy + "): " + ret); } return ret; }  }
PublicAPIs { @PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy ); } XXPolicy existing = daoMgr.getXXPolicy().getById(id); if(existing == null) { throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND); } vXPolicy.setId(id); RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName()); RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy,service); VXPolicy ret = null; if(policy != null) { policy.setVersion(existing.getVersion()); RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy); ret = serviceUtil.toVXPolicy(updatedPolicy, service); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.updatePolicy(" + 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); }
PublicAPIs { @PUT @Path("/api/policy/{id}") @Produces({ "application/json", "application/xml" }) public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) { if(logger.isDebugEnabled()) { logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy ); } XXPolicy existing = daoMgr.getXXPolicy().getById(id); if(existing == null) { throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND); } vXPolicy.setId(id); RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName()); RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy,service); VXPolicy ret = null; if(policy != null) { policy.setVersion(existing.getVersion()); RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy); ret = serviceUtil.toVXPolicy(updatedPolicy, service); } if(logger.isDebugEnabled()) { logger.debug("<== PublicAPIs.updatePolicy(" + 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);  }