@Test
  public void updateBook() throws Exception {
    // Initialize the database
    bookRepository.save(book);

    int databaseSizeBeforeUpdate = bookRepository.findAll().size();

    // Update the book
    book.setTitle(UPDATED_TITLE);
    book.setDescription(UPDATED_DESCRIPTION);
    book.setPublisher(UPDATED_PUBLISHER);
    book.setPublicationDate(UPDATED_PUBLICATION_DATE);
    book.setPrice(UPDATED_PRICE);

    restBookMockMvc
        .perform(
            put("/api/books")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(book)))
        .andExpect(status().isOk());

    // Validate the Book in the database
    List<Book> books = bookRepository.findAll();
    assertThat(books).hasSize(databaseSizeBeforeUpdate);
    Book testBook = books.get(books.size() - 1);
    assertThat(testBook.getTitle()).isEqualTo(UPDATED_TITLE);
    assertThat(testBook.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testBook.getPublisher()).isEqualTo(UPDATED_PUBLISHER);
    assertThat(testBook.getPublicationDate()).isEqualTo(UPDATED_PUBLICATION_DATE);
    assertThat(testBook.getPrice()).isEqualTo(UPDATED_PRICE);
  }
  @Test
  public void deleteBook() throws Exception {
    // Initialize the database
    bookRepository.save(book);

    int databaseSizeBeforeDelete = bookRepository.findAll().size();

    // Get the book
    restBookMockMvc
        .perform(delete("/api/books/{id}", book.getId()).accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<Book> books = bookRepository.findAll();
    assertThat(books).hasSize(databaseSizeBeforeDelete - 1);
  }
  @Test
  public void checkTitleIsRequired() throws Exception {
    int databaseSizeBeforeTest = bookRepository.findAll().size();
    // set the field null
    book.setTitle(null);

    // Create the Book, which fails.

    restBookMockMvc
        .perform(
            post("/api/books")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(book)))
        .andExpect(status().isBadRequest());

    List<Book> books = bookRepository.findAll();
    assertThat(books).hasSize(databaseSizeBeforeTest);
  }
  @Test
  public void createBook() throws Exception {
    int databaseSizeBeforeCreate = bookRepository.findAll().size();

    // Create the Book

    restBookMockMvc
        .perform(
            post("/api/books")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(book)))
        .andExpect(status().isCreated());

    // Validate the Book in the database
    List<Book> books = bookRepository.findAll();
    assertThat(books).hasSize(databaseSizeBeforeCreate + 1);
    Book testBook = books.get(books.size() - 1);
    assertThat(testBook.getTitle()).isEqualTo(DEFAULT_TITLE);
    assertThat(testBook.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
    assertThat(testBook.getPublisher()).isEqualTo(DEFAULT_PUBLISHER);
    assertThat(testBook.getPublicationDate()).isEqualTo(DEFAULT_PUBLICATION_DATE);
    assertThat(testBook.getPrice()).isEqualTo(DEFAULT_PRICE);
  }