@Test public void getDeliveries(){ final DbProduct product = new DbProduct(); product.setName("product1"); Delivery delivery = new Delivery(); delivery.setCommercialName("delivery1"); delivery.setCommercialVersion("1.0.0"); delivery.setVersion("1.0.0-1"); delivery.setJenkinsBuildUrl("http: product.getDeliveries().add(delivery); when(repositoryHandler.getProduct(product.getName())).thenReturn(product); WebResource resource = client().resource("/" + ServerAPI.PRODUCT_RESOURCE + "/" + product.getName() + ServerAPI.GET_DELIVERIES); ClientResponse response = resource.type(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); List<Delivery> deliveries = response.getEntity(new GenericType<List<Delivery>>(){}); assertNotNull(deliveries); assertEquals(1, deliveries.size()); assertEquals("delivery1", deliveries.get(0).getCommercialName()); assertEquals("1.0.0-1", deliveries.get(0).getVersion()); assertEquals("http: }
@GET @Path("/{name}" + ServerAPI.GET_DELIVERIES) @Produces(MediaType.APPLICATION_JSON) public Response getDeliveries(@PathParam("name") final String name){ if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a get deliveries request for product [%s]", name)); } final DbProduct dbProduct = getProductHandler().getProduct(name); final List<Delivery> delivery = dbProduct.getDeliveries(); delivery.sort(Comparator.comparing(Delivery::getCommercialName)); return Response.ok(delivery).build(); }
ProductResource extends AbstractResource { @GET @Path("/{name}" + ServerAPI.GET_DELIVERIES) @Produces(MediaType.APPLICATION_JSON) public Response getDeliveries(@PathParam("name") final String name){ if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a get deliveries request for product [%s]", name)); } final DbProduct dbProduct = getProductHandler().getProduct(name); final List<Delivery> delivery = dbProduct.getDeliveries(); delivery.sort(Comparator.comparing(Delivery::getCommercialName)); return Response.ok(delivery).build(); } }
ProductResource extends AbstractResource { @GET @Path("/{name}" + ServerAPI.GET_DELIVERIES) @Produces(MediaType.APPLICATION_JSON) public Response getDeliveries(@PathParam("name") final String name){ if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a get deliveries request for product [%s]", name)); } final DbProduct dbProduct = getProductHandler().getProduct(name); final List<Delivery> delivery = dbProduct.getDeliveries(); delivery.sort(Comparator.comparing(Delivery::getCommercialName)); return Response.ok(delivery).build(); } ProductResource(final RepositoryHandler repositoryHandler, final GrapesServerConfig configuration); }
ProductResource extends AbstractResource { @GET @Path("/{name}" + ServerAPI.GET_DELIVERIES) @Produces(MediaType.APPLICATION_JSON) public Response getDeliveries(@PathParam("name") final String name){ if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a get deliveries request for product [%s]", name)); } final DbProduct dbProduct = getProductHandler().getProduct(name); final List<Delivery> delivery = dbProduct.getDeliveries(); delivery.sort(Comparator.comparing(Delivery::getCommercialName)); return Response.ok(delivery).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); }
ProductResource extends AbstractResource { @GET @Path("/{name}" + ServerAPI.GET_DELIVERIES) @Produces(MediaType.APPLICATION_JSON) public Response getDeliveries(@PathParam("name") final String name){ if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a get deliveries request for product [%s]", name)); } final DbProduct dbProduct = getProductHandler().getProduct(name); final List<Delivery> delivery = dbProduct.getDeliveries(); delivery.sort(Comparator.comparing(Delivery::getCommercialName)); return Response.ok(delivery).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);  }