@Test public void testPut() throws URISyntaxException { String id = resourceService.postEntity(resource, createTestEntity()); setupMocks(BASE_URI + "/" + id); Response response = defaultResource.put(id, createTestUpdateEntity(), uriInfo); assertEquals("Status code should be OK", Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); Response getResponse = defaultResource.getWithId(id, uriInfo); EntityResponse entityResponse = (EntityResponse) getResponse.getEntity(); EntityBody body = (EntityBody) entityResponse.getEntity(); assertEquals("Status code should be OK", Response.Status.OK.getStatusCode(), getResponse.getStatus()); assertEquals("Should match", id, body.get("id")); assertEquals("Should match", 1234, body.get("studentUniqueStateId")); assertEquals("Should match", "Female", body.get("sex")); }
@PUT @Path("{id}") public Response put(@PathParam("id") final String id, final EntityBody entityBody, @Context final UriInfo uriInfo) { writeValidator.validateWriteRequest(entityBody, uriInfo, SecurityUtil.getSLIPrincipal()); return defaultResponseBuilder.build(uriInfo, twoPartTemplate, ResourceMethod.PUT, new ResourceLogic() { @Override public Response run(Resource resource) { EntityDefinition entityDefinition = entityDefinitionStore.lookupByResourceName(resource.getResourceType()); if(entityDefinition.supportsPut()) { resourceService.putEntity(resource, id, entityBody); return Response.status(Response.Status.NO_CONTENT).build(); } else { return Response.status(405).build(); } } }); }
DefaultResource extends GenericResource implements CustomEntityReturnable { @PUT @Path("{id}") public Response put(@PathParam("id") final String id, final EntityBody entityBody, @Context final UriInfo uriInfo) { writeValidator.validateWriteRequest(entityBody, uriInfo, SecurityUtil.getSLIPrincipal()); return defaultResponseBuilder.build(uriInfo, twoPartTemplate, ResourceMethod.PUT, new ResourceLogic() { @Override public Response run(Resource resource) { EntityDefinition entityDefinition = entityDefinitionStore.lookupByResourceName(resource.getResourceType()); if(entityDefinition.supportsPut()) { resourceService.putEntity(resource, id, entityBody); return Response.status(Response.Status.NO_CONTENT).build(); } else { return Response.status(405).build(); } } }); } }
DefaultResource extends GenericResource implements CustomEntityReturnable { @PUT @Path("{id}") public Response put(@PathParam("id") final String id, final EntityBody entityBody, @Context final UriInfo uriInfo) { writeValidator.validateWriteRequest(entityBody, uriInfo, SecurityUtil.getSLIPrincipal()); return defaultResponseBuilder.build(uriInfo, twoPartTemplate, ResourceMethod.PUT, new ResourceLogic() { @Override public Response run(Resource resource) { EntityDefinition entityDefinition = entityDefinitionStore.lookupByResourceName(resource.getResourceType()); if(entityDefinition.supportsPut()) { resourceService.putEntity(resource, id, entityBody); return Response.status(Response.Status.NO_CONTENT).build(); } else { return Response.status(405).build(); } } }); } DefaultResource(); }
DefaultResource extends GenericResource implements CustomEntityReturnable { @PUT @Path("{id}") public Response put(@PathParam("id") final String id, final EntityBody entityBody, @Context final UriInfo uriInfo) { writeValidator.validateWriteRequest(entityBody, uriInfo, SecurityUtil.getSLIPrincipal()); return defaultResponseBuilder.build(uriInfo, twoPartTemplate, ResourceMethod.PUT, new ResourceLogic() { @Override public Response run(Resource resource) { EntityDefinition entityDefinition = entityDefinitionStore.lookupByResourceName(resource.getResourceType()); if(entityDefinition.supportsPut()) { resourceService.putEntity(resource, id, entityBody); return Response.status(Response.Status.NO_CONTENT).build(); } else { return Response.status(405).build(); } } }); } DefaultResource(); @GET Response getAll(@Context final UriInfo uriInfo); @POST Response post(final EntityBody entityBody,
                         @Context final UriInfo uriInfo); @GET @Path("{id}") Response getWithId(@PathParam("id") final String id,
                              @Context final UriInfo uriInfo); @PUT @Path("{id}") Response put(@PathParam("id") final String id,
                        final EntityBody entityBody,
                        @Context final UriInfo uriInfo); @DELETE @Path("{id}") Response delete(@PathParam("id") final String id,
                           @Context final UriInfo uriInfo); @PATCH @Path("{id}") Response patch(@PathParam("id") final String id,
                          final EntityBody entityBody,
                          @Context final UriInfo uriInfo); @Override CustomEntityResource getCustomResource(final String id, final UriInfo uriInfo); }
DefaultResource extends GenericResource implements CustomEntityReturnable { @PUT @Path("{id}") public Response put(@PathParam("id") final String id, final EntityBody entityBody, @Context final UriInfo uriInfo) { writeValidator.validateWriteRequest(entityBody, uriInfo, SecurityUtil.getSLIPrincipal()); return defaultResponseBuilder.build(uriInfo, twoPartTemplate, ResourceMethod.PUT, new ResourceLogic() { @Override public Response run(Resource resource) { EntityDefinition entityDefinition = entityDefinitionStore.lookupByResourceName(resource.getResourceType()); if(entityDefinition.supportsPut()) { resourceService.putEntity(resource, id, entityBody); return Response.status(Response.Status.NO_CONTENT).build(); } else { return Response.status(405).build(); } } }); } DefaultResource(); @GET Response getAll(@Context final UriInfo uriInfo); @POST Response post(final EntityBody entityBody,
                         @Context final UriInfo uriInfo); @GET @Path("{id}") Response getWithId(@PathParam("id") final String id,
                              @Context final UriInfo uriInfo); @PUT @Path("{id}") Response put(@PathParam("id") final String id,
                        final EntityBody entityBody,
                        @Context final UriInfo uriInfo); @DELETE @Path("{id}") Response delete(@PathParam("id") final String id,
                           @Context final UriInfo uriInfo); @PATCH @Path("{id}") Response patch(@PathParam("id") final String id,
                          final EntityBody entityBody,
                          @Context final UriInfo uriInfo); @Override CustomEntityResource getCustomResource(final String id, final UriInfo uriInfo);  }