@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);
  }
 @Before
 public void initTest() {
   bookRepository.deleteAll();
   book = new Book();
   book.setTitle(DEFAULT_TITLE);
   book.setDescription(DEFAULT_DESCRIPTION);
   book.setPublisher(DEFAULT_PUBLISHER);
   book.setPublicationDate(DEFAULT_PUBLICATION_DATE);
   book.setPrice(DEFAULT_PRICE);
 }
  @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);
  }
  @Test
  public void getBook() throws Exception {
    // Initialize the database
    bookRepository.save(book);

    // Get the book
    restBookMockMvc
        .perform(get("/api/books/{id}", book.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(book.getId()))
        .andExpect(jsonPath("$.title").value(DEFAULT_TITLE.toString()))
        .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString()))
        .andExpect(jsonPath("$.publisher").value(DEFAULT_PUBLISHER.toString()))
        .andExpect(jsonPath("$.publicationDate").value(DEFAULT_PUBLICATION_DATE.toString()))
        .andExpect(jsonPath("$.price").value(DEFAULT_PRICE.intValue()));
  }