コード例 #1
0
  @Test
  @Transactional
  public void updateAuthor() throws Exception {
    // Initialize the database
    authorRepository.saveAndFlush(author);

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

    // Update the author
    author.setName(UPDATED_NAME);
    author.setSurname(UPDATED_SURNAME);
    author.setDescription(UPDATED_DESCRIPTION);
    author.setBirthDate(UPDATED_BIRTH_DATE);
    restAuthorMockMvc
        .perform(
            put("/api/authors")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(author)))
        .andExpect(status().isOk());

    // Validate the Author in the database
    List<Author> authors = authorRepository.findAll();
    assertThat(authors).hasSize(databaseSizeBeforeUpdate);
    Author testAuthor = authors.get(authors.size() - 1);
    assertThat(testAuthor.getName()).isEqualTo(UPDATED_NAME);
    assertThat(testAuthor.getSurname()).isEqualTo(UPDATED_SURNAME);
    assertThat(testAuthor.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testAuthor.getBirthDate()).isEqualTo(UPDATED_BIRTH_DATE);
  }
コード例 #2
0
  @Test
  @Transactional
  public void createAuthor() throws Exception {
    int databaseSizeBeforeCreate = authorRepository.findAll().size();

    // Create the Author
    restAuthorMockMvc
        .perform(
            post("/api/authors")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(author)))
        .andExpect(status().isCreated());

    // Validate the Author in the database
    List<Author> authors = authorRepository.findAll();
    assertThat(authors).hasSize(databaseSizeBeforeCreate + 1);
    Author testAuthor = authors.get(authors.size() - 1);
    assertThat(testAuthor.getName()).isEqualTo(DEFAULT_NAME);
    assertThat(testAuthor.getSurname()).isEqualTo(DEFAULT_SURNAME);
    assertThat(testAuthor.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
    assertThat(testAuthor.getBirthDate()).isEqualTo(DEFAULT_BIRTH_DATE);
  }