Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
don-bigdad committed Jan 29, 2024
1 parent aa873a0 commit 8767754
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import com.example.springbootbookshop.dto.book.BookDto;
import com.example.springbootbookshop.dto.book.CreateBookRequestDto;
import com.example.springbootbookshop.entity.Book;
import com.example.springbootbookshop.repository.BookRepository;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.math.BigDecimal;
Expand Down Expand Up @@ -42,6 +44,8 @@ public class BookControllerTest {
protected static MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private BookRepository bookRepository;

@BeforeAll
static void beforeAll(@Autowired WebApplicationContext applicationContext) {
Expand Down Expand Up @@ -174,13 +178,9 @@ void deleteBookByIdAssertSuccess() throws Exception {
@DisplayName("Update book by id")
@WithMockUser(username = "admin", roles = {"ADMIN","USER"})
void updateBookById_ValidId_Ok() throws Exception {
MvcResult result = mockMvc.perform(get("/books/2")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();
BookDto dto = objectMapper.readValue(result.getResponse()
.getContentAsString(), BookDto.class);
assertEquals("Book 2", dto.getTitle());
Book bookFromDB = bookRepository.findById(2L).get();
assertNotNull(bookFromDB);
assertEquals("Book 2", bookFromDB.getTitle());

CreateBookRequestDto updatedDto = new CreateBookRequestDto(
"Updated Title", "Updated Author", "Updated ISBN",
Expand Down

0 comments on commit 8767754

Please sign in to comment.