diff --git a/src/test/java/mate/academy/bookstore/controller/BookControllerTest.java b/src/test/java/mate/academy/bookstore/controller/BookControllerTest.java index 82e3c1c..e1acaa2 100644 --- a/src/test/java/mate/academy/bookstore/controller/BookControllerTest.java +++ b/src/test/java/mate/academy/bookstore/controller/BookControllerTest.java @@ -1,5 +1,22 @@ package mate.academy.bookstore.controller; +import static mate.academy.bookstore.util.TestConstants.ADMIN_ROLE; +import static mate.academy.bookstore.util.TestConstants.AUTHOR_PARAM_NAME; +import static mate.academy.bookstore.util.TestConstants.BASE_URL; +import static mate.academy.bookstore.util.TestConstants.ID; +import static mate.academy.bookstore.util.TestConstants.ISBN_PARAM_NAME; +import static mate.academy.bookstore.util.TestConstants.PRICE_PARAM_NAME; +import static mate.academy.bookstore.util.TestConstants.SEARCH_URL; +import static mate.academy.bookstore.util.TestConstants.SET_OF_VALID_CATEGORY_ID; +import static mate.academy.bookstore.util.TestConstants.TITLE_0_EXPRESSION; +import static mate.academy.bookstore.util.TestConstants.TITLE_EXPRESSION; +import static mate.academy.bookstore.util.TestConstants.TITLE_PARAM_NAME; +import static mate.academy.bookstore.util.TestConstants.USER_ROLE; +import static mate.academy.bookstore.util.TestConstants.VALID_BOOK_AUTHOR; +import static mate.academy.bookstore.util.TestConstants.VALID_BOOK_ID; +import static mate.academy.bookstore.util.TestConstants.VALID_BOOK_ISBN; +import static mate.academy.bookstore.util.TestConstants.VALID_BOOK_PRICE; +import static mate.academy.bookstore.util.TestConstants.VALID_BOOK_TITLE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; @@ -12,9 +29,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; -import java.math.BigDecimal; import java.util.Collections; -import java.util.Set; import mate.academy.bookstore.dto.book.BookDto; import mate.academy.bookstore.dto.book.BookSearchParametersDto; import mate.academy.bookstore.dto.book.CreateBookRequestDto; @@ -35,24 +50,6 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class BookControllerTest { - private static final String ID = "/{id}"; - private static final String TITLE_PARAM_NAME = "title"; - private static final String AUTHOR_PARAM_NAME = "author"; - private static final String ISBN_PARAM_NAME = "isbn"; - private static final String PRICE_PARAM_NAME = "price"; - private static final String BASE_URL = "/books"; - private static final String SEARCH_URL = BASE_URL + "/search"; - private static final String ADMIN_ROLE = "ADMIN"; - private static final String USER_ROLE = "USER"; - private static final String VALID_BOOK_TITLE = "Kobzar"; - private static final String VALID_BOOK_AUTHOR = "Taras Shevchenko"; - private static final String VALID_BOOK_ISBN = "978-0-7847-5628-7"; - private static final BigDecimal VALID_BOOK_PRICE = BigDecimal.valueOf(14.99); - private static final Set VALID_CATEGORY_ID = Set.of(1L); - private static final Long VALID_BOOK_ID = 1L; - private static final String TITLE_0_EXPRESSION = "$[0].title"; - private static final String TITLE_EXPRESSION = "$.title"; - private static MockMvc mockMvc; @MockBean @@ -85,7 +82,7 @@ void setup() { createBookDto.setTitle(VALID_BOOK_TITLE); createBookDto.setAuthor(VALID_BOOK_AUTHOR); createBookDto.setIsbn(VALID_BOOK_ISBN); - createBookDto.setCategoryIds(VALID_CATEGORY_ID); + createBookDto.setCategoryIds(SET_OF_VALID_CATEGORY_ID); createBookDto.setPrice(VALID_BOOK_PRICE); } diff --git a/src/test/java/mate/academy/bookstore/controller/CategoryControllerTest.java b/src/test/java/mate/academy/bookstore/controller/CategoryControllerTest.java index 0fad4e0..43da559 100644 --- a/src/test/java/mate/academy/bookstore/controller/CategoryControllerTest.java +++ b/src/test/java/mate/academy/bookstore/controller/CategoryControllerTest.java @@ -1,5 +1,14 @@ package mate.academy.bookstore.controller; +import static mate.academy.bookstore.util.TestConstants.ADMIN_ROLE; +import static mate.academy.bookstore.util.TestConstants.CATEGORIES_ID_BOOKS_URL; +import static mate.academy.bookstore.util.TestConstants.CATEGORIES_ID_URL; +import static mate.academy.bookstore.util.TestConstants.CATEGORIES_URL; +import static mate.academy.bookstore.util.TestConstants.EXPRESSION; +import static mate.academy.bookstore.util.TestConstants.NAME_EXPRESSION; +import static mate.academy.bookstore.util.TestConstants.USER_ROLE; +import static mate.academy.bookstore.util.TestConstants.VALID_CATEGORY_ID; +import static mate.academy.bookstore.util.TestConstants.VALID_CATEGORY_NAME; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -32,15 +41,6 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class CategoryControllerTest { - private static final Long VALID_CATEGORY_ID = 1L; - private static final String VALID_CATEGORY_NAME = "Fiction"; - private static final String CATEGORIES_URL = "/categories"; - private static final String CATEGORIES_ID_URL = "/categories/{id}"; - private static final String CATEGORIES_ID_BOOKS_URL = "/categories/{id}/books"; - private static final String EXPRESSION = "$"; - private static final String NAME_EXPRESSION = "$.name"; - private static final String ADMIN_ROLE = "ADMIN"; - private static final String USER_ROLE = "USER"; private static MockMvc mockMvc; @Mock diff --git a/src/test/java/mate/academy/bookstore/util/TestConstants.java b/src/test/java/mate/academy/bookstore/util/TestConstants.java index fc2e112..52cd628 100644 --- a/src/test/java/mate/academy/bookstore/util/TestConstants.java +++ b/src/test/java/mate/academy/bookstore/util/TestConstants.java @@ -38,4 +38,24 @@ public class TestConstants { public static final String VALID_BOOK_ISBN_NOT_IN_DB = "978-1-2345-6789-0"; public static final Long INVALID_ID = -1L; public static final Long EMPTY_CATEGORY_ID = 4L; + + public static final String ID = "/{id}"; + public static final String TITLE_PARAM_NAME = "title"; + public static final String AUTHOR_PARAM_NAME = "author"; + public static final String ISBN_PARAM_NAME = "isbn"; + public static final String PRICE_PARAM_NAME = "price"; + public static final String BASE_URL = "/books"; + public static final String SEARCH_URL = BASE_URL + "/search"; + + public static final String ADMIN_ROLE = "ADMIN"; + public static final String USER_ROLE = "USER"; + + public static final String TITLE_0_EXPRESSION = "$[0].title"; + public static final String TITLE_EXPRESSION = "$.title"; + + public static final String CATEGORIES_URL = "/categories"; + public static final String CATEGORIES_ID_URL = "/categories/{id}"; + public static final String CATEGORIES_ID_BOOKS_URL = "/categories/{id}/books"; + public static final String EXPRESSION = "$"; + public static final String NAME_EXPRESSION = "$.name"; }