@Test
    public void testUpdate() {
        // Find Book D
        Book bookD = bookRepository.findByTitle("Book D").get(0);
        Long id = bookD.getId();

        // Update the book details
        bookD.setTitle("Book DDD");
        bookD.setPrice(new BigDecimal("199.99"));
        bookD.setPublishDate(LocalDate.of(2024, 1, 31));

        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");

        // put the updated book in HttpEntity
        HttpEntity<Book> request = new HttpEntity<>(bookD, headers);

        // Perform the PUT request to update the book
        ResponseEntity<Book> responseEntity = restTemplate.exchange(
                "http://localhost:" + port + "/books",
                HttpMethod.PUT,
                request,
                Book.class
        );

        // ensure OK
        assertEquals(HttpStatus.OK, responseEntity.getStatusCode());

        // verify the updated book
        Book updatedBook = bookRepository.findById(id).orElseThrow();

        assertEquals(id, updatedBook.getId());
        assertEquals("Book DDD", updatedBook.getTitle());
        assertEquals(BigDecimal.valueOf(199.99), updatedBook.getPrice());
        assertEquals(LocalDate.of(2024, 1, 31), updatedBook.getPublishDate());

    }
Book b4 = new Book("Book D",
BigDecimal.valueOf(39.99),
LocalDate.of(2023, 5, 5));
spring-data-jpa-mysql/src/test/java/com/mkyong/BookControllerTest.java