StateRest { @DELETE @Path("{stateId}") @RolesAllowed("user") @ApiOperation("Deletes State as long as it belongs to the User making the request") public Response deleteState(@Context ContainerRequestContext context, @PathParam("stateId") String stateId) { String username = RestUtils.getActiveUsername(context); try { if (!stateManager.stateExistsForUser(factory.createIRI(stateId), username)) { throw ErrorUtils.sendError("Not allowed", Response.Status.UNAUTHORIZED); } stateManager.deleteState(factory.createIRI(stateId)); } catch (IllegalArgumentException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.NOT_FOUND); } catch (MobiException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } return Response.ok().build(); }  @GET @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves State for the User making the request based on filter criteria") Response getStates(@Context ContainerRequestContext context,
                       @QueryParam("application") String applicationId,
                       @QueryParam("subjects") List<String> subjectIds); @POST @Consumes(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Creates a new State for the User making the request") Response createState(@Context ContainerRequestContext context,
                         @QueryParam("application") String applicationId,
                         String stateJson); @GET @Path("{stateId}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves State by ID as long it belongs to the User making the request") Response getState(@Context ContainerRequestContext context, @PathParam("stateId") String stateId); @PUT @Path("{stateId}") @Consumes(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Updates State as long as it belongs to the User making the request") Response updateState(@Context ContainerRequestContext context,
                         @PathParam("stateId") String stateId,
                         String newStateJson); @DELETE @Path("{stateId}") @RolesAllowed("user") @ApiOperation("Deletes State as long as it belongs to the User making the request") Response deleteState(@Context ContainerRequestContext context, @PathParam("stateId") String stateId);  }
@Test public void deleteStateTest() { Response response = target().path("states/" + encode(stateId.stringValue())) .request().delete(); assertEquals(response.getStatus(), 200); verify(stateManager).deleteState(eq(stateId)); }
@Test public void deleteStateThatDoesNotExistTest() { doThrow(new IllegalArgumentException()).when(stateManager).deleteState(any(Resource.class)); Response response = target().path("states/" + encode(stateId.stringValue())) .request().delete(); assertEquals(response.getStatus(), 404); }
@Test public void deleteStateExceptionThrownTest() { doThrow(new MobiException()).when(stateManager).deleteState(any(Resource.class)); Response response = target().path("states/" + encode(stateId.stringValue())) .request().delete(); assertEquals(response.getStatus(), 500); }