use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class SpringBootBootstrapIntegrationTest method whenGetBooksByTitle_thenOK.
@Test
public void whenGetBooksByTitle_thenOK() {
final Book book = createRandomBook();
createBookAsUri(book);
final Response response = RestAssured.get(API_ROOT + "/title/" + book.getTitle());
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
assertTrue(response.as(List.class).size() > 0);
}
use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class SpringBootBootstrapIntegrationTest method whenDeleteCreatedBook_thenOk.
@Test
public void whenDeleteCreatedBook_thenOk() {
final Book book = createRandomBook();
final String location = createBookAsUri(book);
Response response = RestAssured.delete(location);
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
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 SpringBootBootstrapIntegrationTest method whenInvalidBook_thenError.
@Test
public void whenInvalidBook_thenError() {
final Book book = createRandomBook();
book.setAuthor(null);
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_ROOT);
assertEquals(HttpStatus.BAD_REQUEST.value(), response.getStatusCode());
}
use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class SpringBootBootstrapIntegrationTest method whenGetCreatedBookById_thenOK.
@Test
public void whenGetCreatedBookById_thenOK() {
final Book book = createRandomBook();
final String location = createBookAsUri(book);
final Response response = RestAssured.get(location);
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
assertEquals(book.getTitle(), response.jsonPath().get("title"));
}
use of org.baeldung.persistence.model.Book in project tutorials by eugenp.
the class SpringBootBootstrapIntegrationTest method whenUpdateCreatedBook_thenUpdated.
@Test
public void whenUpdateCreatedBook_thenUpdated() {
final Book book = createRandomBook();
final String location = createBookAsUri(book);
book.setId(Long.parseLong(location.split("api/books/")[1]));
book.setAuthor("newAuthor");
Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).put(location);
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
response = RestAssured.get(location);
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
assertEquals("newAuthor", response.jsonPath().get("author"));
}
Aggregations