CategoryResource { @GET @Path("/categories") public Response findAll(@BeanParam PageableImpl pageable) { LOGGER.debug("REST request to get all Categories"); return Response.ok().entity(categoryService.findAll(pageable)).build(); } @Inject  CategoryResource(CategoryService categoryService); @GET @Path("/categories") Response findAll(@BeanParam PageableImpl pageable); @GET @Path("/categories/search") List<CategoryDTO> findAllByCategoryName(@QueryParam("name") String fullName); @GET @Path("/categories/{id}") Response findById(@PathParam("id") long id); @POST @Path("/categories") Response create(CategoryDTO categoryDTO); @PUT @Path("/categories") Response update(CategoryDTO categoryDTO); @DELETE @Path("/categories/{id}") Response delete(@PathParam("id") long id);  }
@Test public void createCategory() { int databaseSizeBeforeCreate = Iterators.size(categoryRepository.findAll().iterator()); given() .contentType(JSON) .body(this.category) .when().post("/api/categories") .then() .statusCode(201); List<Category> categoryList = categoryRepository.findAll(); Assertions.assertEquals(categoryList.size(), databaseSizeBeforeCreate + 1); Category category = categoryList.get(categoryList.size() - 1); Assertions.assertEquals(category.getName(), DEFAULT_NAME); }
@Test public void createCategoryWithExistingId() { int databaseSizeBeforeCreate = categoryRepository.findAll().size(); category.setId(10L); given() .contentType(JSON) .body(category) .when().post("/api/categories") .then() .statusCode(400); List<Category> categoryList = categoryRepository.findAll(); Assertions.assertEquals(categoryList.size(), databaseSizeBeforeCreate); }
@Test public void updateCategory() { categoryRepository.save(category); int databaseSizeBeforeCreate = categoryRepository.findAll().size(); category.setName(DEFAULT_NAME); given() .contentType(JSON) .body(category) .when().put("/api/categories") .then() .statusCode(200) .contentType(JSON) .body("name", equalTo(DEFAULT_NAME)); List<Category> categoryList = categoryRepository.findAll(); Assertions.assertEquals(categoryList.size(), databaseSizeBeforeCreate); }