@Test public void deleteProvider() { ProviderAPI providerAPI = new ProviderAPI(); providerAPI.providerDAO = providerDAO; List<Provider> providers = providerDAO.getAll(); int id = providers.get(0).getId(); Response response = providerAPI.deleteProvider(id); assertEquals(204, response.getStatus()); assertEquals(1, providerDAO.getAll().size()); response = providerAPI.deleteProvider(Integer.MAX_VALUE); assertEquals(400, response.getStatus()); assertEquals("No provider by that id to be deleted.", response.getEntity()); }
@DELETE @Path("/{id}") public Response deleteProvider(@PathParam("id") int id) { logger.info("DELETE /" + id); Provider provider = providerDAO.getById(id); if(provider != null) { providerDAO.delete(provider); logger.debug("Provider deleted."); return Response.status(Status.NO_CONTENT).build(); } else { logger.debug("Provider not found in database, impossible to delete"); return buildResponse(Status.BAD_REQUEST, "No provider by that id to be deleted."); } }
ProviderAPI extends RestAbstract { @DELETE @Path("/{id}") public Response deleteProvider(@PathParam("id") int id) { logger.info("DELETE /" + id); Provider provider = providerDAO.getById(id); if(provider != null) { providerDAO.delete(provider); logger.debug("Provider deleted."); return Response.status(Status.NO_CONTENT).build(); } else { logger.debug("Provider not found in database, impossible to delete"); return buildResponse(Status.BAD_REQUEST, "No provider by that id to be deleted."); } } }
ProviderAPI extends RestAbstract { @DELETE @Path("/{id}") public Response deleteProvider(@PathParam("id") int id) { logger.info("DELETE /" + id); Provider provider = providerDAO.getById(id); if(provider != null) { providerDAO.delete(provider); logger.debug("Provider deleted."); return Response.status(Status.NO_CONTENT).build(); } else { logger.debug("Provider not found in database, impossible to delete"); return buildResponse(Status.BAD_REQUEST, "No provider by that id to be deleted."); } }  }
ProviderAPI extends RestAbstract { @DELETE @Path("/{id}") public Response deleteProvider(@PathParam("id") int id) { logger.info("DELETE /" + id); Provider provider = providerDAO.getById(id); if(provider != null) { providerDAO.delete(provider); logger.debug("Provider deleted."); return Response.status(Status.NO_CONTENT).build(); } else { logger.debug("Provider not found in database, impossible to delete"); return buildResponse(Status.BAD_REQUEST, "No provider by that id to be deleted."); } }  @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProviders(); @GET @Path("/") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProvidersJSON(); @GET @Path("/{id}") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProvider(@PathParam("id") int id); @GET @Path("/{id}") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProviderJSON(@PathParam("id") int id); @POST @Path("/") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response postProvider(String payload); @DELETE @Path("/{id}") Response deleteProvider(@PathParam("id") int id); @PUT @Path("/{id}") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response putProvider(@PathParam("id") int id, String payload); }
ProviderAPI extends RestAbstract { @DELETE @Path("/{id}") public Response deleteProvider(@PathParam("id") int id) { logger.info("DELETE /" + id); Provider provider = providerDAO.getById(id); if(provider != null) { providerDAO.delete(provider); logger.debug("Provider deleted."); return Response.status(Status.NO_CONTENT).build(); } else { logger.debug("Provider not found in database, impossible to delete"); return buildResponse(Status.BAD_REQUEST, "No provider by that id to be deleted."); } }  @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProviders(); @GET @Path("/") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProvidersJSON(); @GET @Path("/{id}") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProvider(@PathParam("id") int id); @GET @Path("/{id}") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProviderJSON(@PathParam("id") int id); @POST @Path("/") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response postProvider(String payload); @DELETE @Path("/{id}") Response deleteProvider(@PathParam("id") int id); @PUT @Path("/{id}") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response putProvider(@PathParam("id") int id, String payload);  }