ProductResource extends AbstractResource { @POST public Response createProduct(@Auth final DbCredential credential, final String productName){ if(!credential.getRoles().contains(DbCredential.AvailableRoles.DATA_UPDATER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a create product request."); if(productName == null || productName.isEmpty()){ throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Product name should neither be null nor empty.").build()); } final DbProduct dbProduct = new DbProduct(); dbProduct.setName(productName); getProductHandler().create(dbProduct); return Response.ok().status(HttpStatus.CREATED_201).build(); } ProductResource(final RepositoryHandler repositoryHandler, final GrapesServerConfig configuration); @POST Response createProduct(@Auth final DbCredential credential, final String productName); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @GET @Path("/{name}" + ServerAPI.GET_MODULES) @Produces(MediaType.APPLICATION_JSON) Response getModuleNames(@PathParam("name") final String name); @POST @Path("/{name}" + ServerAPI.GET_MODULES) Response setModuleNames(@Auth final DbCredential credential, @PathParam("name") final String name, final List<String> moduleNames); @GET @Path("/{name}" + ServerAPI.GET_DELIVERIES) @Produces(MediaType.APPLICATION_JSON) Response getDeliveries(@PathParam("name") final String name); @POST @Path("/{name}" + ServerAPI.GET_DELIVERIES) Response createNewDelivery(@Auth final DbCredential credential, @PathParam("name") final String name, final Delivery delivery); @GET @Path("/{name}" + ServerAPI.GET_DELIVERIES+"/{commercialName}"+"/{commercialVersion}") @Produces(MediaType.APPLICATION_JSON) Response getDelivery(@PathParam("name") final String name, @PathParam("commercialName") final String commercialName, @PathParam("commercialVersion") final String commercialVersion); @DELETE @Path("/{name}" + ServerAPI.GET_DELIVERIES+"/{commercialName}"+"/{commercialVersion}") @Produces(MediaType.APPLICATION_JSON) Response deleteDelivery(@Auth final DbCredential credential, @PathParam("name") final String name, @PathParam("commercialName") final String commercialName, @PathParam("commercialVersion") final String commercialVersion); @POST @Path("/{name}" + ServerAPI.GET_DELIVERIES+"/{commercialName}"+"/{commercialVersion}") @Produces(MediaType.APPLICATION_JSON) Response setDeliveryDependency(@Auth final DbCredential credential,
                                          @PathParam("name") final String name,
                                          @PathParam("commercialName") final String commercialName,
                                          @PathParam("commercialVersion") final String commercialVersion,
                                          List<String> dependencies);  }
@Test public void createProduct(){ client().addFilter(new HTTPBasicAuthFilter(GrapesTestUtils.USER_4TEST, GrapesTestUtils.PASSWORD_4TEST)); WebResource resource = client().resource("/" + ServerAPI.PRODUCT_RESOURCE); ClientResponse response = resource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, "product"); assertNotNull(response); assertEquals(HttpStatus.CREATED_201, response.getStatus()); }