Skip to content

Commit

Permalink
fix test method with category
Browse files Browse the repository at this point in the history
  • Loading branch information
don-bigdad committed Jan 24, 2024
1 parent 70aa337 commit 1769139
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public class BookControllerTest {
private ObjectMapper objectMapper;

@BeforeAll
static void beforeAll(@Autowired WebApplicationContext applicationContext,
@Autowired DataSource dataSource) throws SQLException {
static void beforeAll(@Autowired WebApplicationContext applicationContext) {
mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext)
.apply(springSecurity())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void updateBookByIdAssertSuccess() throws Exception {

@Test
@DisplayName("Get all books by category id")
@Sql(scripts = {"classpath:database/books/insert-new-books.sql",
@Sql(scripts = {"classpath:database/books/clear-books-db.sql",
"classpath:database/books/insert-new-books.sql",
"classpath:database/books-categories/insert-books-categories.sql"},
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:database/books-categories/clear-book-category.sql",
Expand All @@ -194,8 +195,8 @@ void getAllBooksByCategoryAssertSuccess() throws Exception {
.andReturn();
List<BookDtoWithoutCategoryIds> bookDtoWithoutCategoryIds = objectMapper.readValue(
result.getResponse().getContentAsString(), new TypeReference<>() {});
assertEquals(2, bookDtoWithoutCategoryIds.size());
assertEquals("Book 5", bookDtoWithoutCategoryIds.get(1).title());
assertEquals(1, bookDtoWithoutCategoryIds.size());
assertEquals("Book 5", bookDtoWithoutCategoryIds.get(0).title());
}

private CategoryDto getExpectDto() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
INSERT INTO books_categories (book_id, category_id)
VALUES
(1, 1),
(2, 2),
(3, 3),
(4, 1),
(5, 2),
(6, 3);

0 comments on commit 1769139

Please sign in to comment.