@Test public void getProductRequest() { String bookId = UUID.randomUUID().toString(); Book book = new Book(bookId, "1234567890", "Book Title", ""); String productId = UUID.randomUUID().toString(); Product product = new Product(productId, book, 1000L, null); when(productRepository.getProduct(productId)).thenReturn(product); ProductDto retrievedProduct = resources.client() .target(PRODUCT_RESOURCE + "/" + productId) .request(APPLICATION_JSON_TYPE) .get(ProductDto.class); assertThat(retrievedProduct, is(ProductDtoFactory.fromProduct(product))); }
@GET @Path("{productId}") public ProductDto getProduct(@PathParam("productId") String productId) { Product product = productRepository.getProduct(productId); if (product == null) { throw new IllegalArgumentException("No such product: " + productId); } logger.info("Returning product with id [{}]", product.productId); return ProductDtoFactory.fromProduct(product); }
ProductResource { @GET @Path("{productId}") public ProductDto getProduct(@PathParam("productId") String productId) { Product product = productRepository.getProduct(productId); if (product == null) { throw new IllegalArgumentException("No such product: " + productId); } logger.info("Returning product with id [{}]", product.productId); return ProductDtoFactory.fromProduct(product); } }
ProductResource { @GET @Path("{productId}") public ProductDto getProduct(@PathParam("productId") String productId) { Product product = productRepository.getProduct(productId); if (product == null) { throw new IllegalArgumentException("No such product: " + productId); } logger.info("Returning product with id [{}]", product.productId); return ProductDtoFactory.fromProduct(product); } ProductResource(ProductRepository productRepository); }
ProductResource { @GET @Path("{productId}") public ProductDto getProduct(@PathParam("productId") String productId) { Product product = productRepository.getProduct(productId); if (product == null) { throw new IllegalArgumentException("No such product: " + productId); } logger.info("Returning product with id [{}]", product.productId); return ProductDtoFactory.fromProduct(product); } ProductResource(ProductRepository productRepository); @GET @Path("{productId}") ProductDto getProduct(@PathParam("productId") String productId); @POST void createProduct(@Valid ProductDto request); @GET Collection<ProductDto> getProducts(); }
ProductResource { @GET @Path("{productId}") public ProductDto getProduct(@PathParam("productId") String productId) { Product product = productRepository.getProduct(productId); if (product == null) { throw new IllegalArgumentException("No such product: " + productId); } logger.info("Returning product with id [{}]", product.productId); return ProductDtoFactory.fromProduct(product); } ProductResource(ProductRepository productRepository); @GET @Path("{productId}") ProductDto getProduct(@PathParam("productId") String productId); @POST void createProduct(@Valid ProductDto request); @GET Collection<ProductDto> getProducts();  }