@Test
    public void testDeleteById() {

        List<Book> list = bookRepository.findByTitle("Book A");
        Book bookA = list.get(0);

        // get Book A id
        Long id = bookA.getId();

        // delete by id
        ResponseEntity<Void> response = restTemplate.exchange(
                BASEURI + "/books/" + id,
                HttpMethod.DELETE,
                null,
                Void.class
        );

        // test 204
        assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());

        // find Book A again, ensure no result
        List<Book> listAgain = bookRepository.findByTitle("Book A");
        assertEquals(0, listAgain.size());

    }
Testing with TestRestTemplate and @Testcontainers (image mysql:8.0-debian)
spring-data-jpa-mysql/src/test/java/com/mkyong/BookControllerTest.java