コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }