ProductResource { @GET @Path("/products") public Response findAll(@BeanParam PageableImpl pageable) { LOGGER.debug("REST request to get all Products"); return Response.ok().entity(productService.findAll(pageable)).build(); } @Inject  ProductResource(ProductService productService); @GET @Path("/products") Response findAll(@BeanParam PageableImpl pageable); @GET @Path("/products/search") Page<ProductDTO> findAllByProductName(@QueryParam("name") String name, @BeanParam PageableImpl pageable); @GET @Path("/products/{id}") Response findById(@PathParam("id") long id); @POST @Path("/products") Response create(ProductDTO productDTO); @PUT @Path("/products") Response update(ProductDTO productDTO); @DELETE @Path("/products/{id}") Response delete(@PathParam("id") long id);  }
@Test public void createProduct() { int databaseSizeBeforeCreate = productRepository.findAll().size(); given() .contentType(JSON) .body(this.product) .when().post("/api/products") .then() .statusCode(201); List<Product> productList = productRepository.findAll(); Assertions.assertEquals(productList.size(), databaseSizeBeforeCreate + 1); Product product = productList.get(productList.size() - 1); Assertions.assertEquals(product.getName(), DEFAULT_NAME); }
@Test public void createProductWithExistingId() { int databaseSizeBeforeCreate = productRepository.findAll().size(); product.setId(10L); given() .contentType(JSON) .body(product) .when().post("/api/products") .then() .statusCode(400); List<Product> productList = productRepository.findAll(); Assertions.assertEquals(productList.size(), databaseSizeBeforeCreate); }
@Test public void updateProduct() { productRepository.save(product); int databaseSizeBeforeCreate = productRepository.findAll().size(); product.setName(DEFAULT_NAME); given() .contentType(JSON) .body(product) .when().put("/api/products") .then() .statusCode(200) .contentType(JSON) .body("name", equalTo(DEFAULT_NAME)); List<Product> productList = productRepository.findAll(); Assertions.assertEquals(productList.size(), databaseSizeBeforeCreate); }