use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class RestApiLiveTest method whenDeleteCreatedBook_thenOk.
@Test
public void whenDeleteCreatedBook_thenOk() {
// create
final Book book = createRandomBook();
final String location = createBookAsUri(book);
// delete
Response response = RestAssured.delete(location);
assertEquals(HttpStatus.NO_CONTENT.value(), response.getStatusCode());
// confirm it was deleted
response = RestAssured.get(location);
assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatusCode());
}
use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class RestApiLiveTest method whenGetCreatedBookByName_thenOK.
@Test
public void whenGetCreatedBookByName_thenOK() {
final Book book = createRandomBook();
createBookAsUri(book);
final Response response = RestAssured.get(API_URI + "/search/findByTitle?title=" + book.getTitle());
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
assertTrue(response.jsonPath().getLong("page.totalElements") > 0);
}
use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class RestApiLiveTest method whenCreateDuplicateBook_thenError.
@Test
public void whenCreateDuplicateBook_thenError() {
final Book book = createRandomBook();
createBookAsUri(book);
// duplicate
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_URI);
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
}
use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class RestApiLiveTest method createRandomBook.
// =============================== Util
private Book createRandomBook() {
final Book book = new Book();
book.setTitle(randomAlphabetic(10));
book.setAuthor(randomAlphabetic(15));
return book;
}
use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class RestApiLiveTest method whenUpdateCreatedBook_thenUpdated.
@Test
public void whenUpdateCreatedBook_thenUpdated() {
// create
final Book book = createRandomBook();
final String location = createBookAsUri(book);
// update
book.setAuthor("newAuthor");
Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).put(location);
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
// check if changes saved
response = RestAssured.get(location);
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
assertEquals("newAuthor", response.jsonPath().get("author"));
}
Aggregations