PolicyRest { @PUT @Path("{policyId}") @Consumes(MediaType.APPLICATION_JSON) @RolesAllowed("admin") @ApiOperation("Updates an existing security policy using the provided JSON body.") @ResourceId(type = ValueType.PATH, value = "policyId") public Response updatePolicy(@PathParam("policyId") String policyId, String policyJson) { try { XACMLPolicy policy = jsonToPolicy(policyJson); if (!policy.getId().equals(vf.createIRI(policyId))) { throw ErrorUtils.sendError("Policy Id does not match provided policy", Response.Status.BAD_REQUEST); } policyManager.updatePolicy(policy); return Response.ok().build(); } catch (IllegalArgumentException | PolicySyntaxException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST); } catch (IllegalStateException | MobiException ex) { throw ErrorUtils.sendError(ex, "Policy could not be updated", Response.Status.INTERNAL_SERVER_ERROR); } }  @GET @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves security policies matching the provided filters.") Response getPolicies(@QueryParam("relatedSubject") String relatedSubject,
                         @QueryParam("relatedResource") String relatedResource,
                         @QueryParam("relatedAction") String relatedAction); @POST @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_JSON) @RolesAllowed("admin") @ApiOperation("Creates a new security policy using the provided JSON body.") Response createPolicy(String policyJson); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{policyId}") @RolesAllowed("user") @ApiOperation("Retrieves a specific security policy by its ID.") @ResourceId(type = ValueType.PATH, value = "policyId") Response retrievePolicy(@PathParam("policyId") String policyId); @PUT @Path("{policyId}") @Consumes(MediaType.APPLICATION_JSON) @RolesAllowed("admin") @ApiOperation("Updates an existing security policy using the provided JSON body.") @ResourceId(type = ValueType.PATH, value = "policyId") Response updatePolicy(@PathParam("policyId") String policyId, String policyJson);  }
@Test public void updatePolicyTest() { Response response = target().path("policies/" + encode(policyId.stringValue())).request().put(Entity.json(json)); assertEquals(response.getStatus(), 200); verify(policyManager).createPolicy(any(PolicyType.class)); verify(policyManager).updatePolicy(policy); }