use of io.restassured.response.Response 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"));
}
use of io.restassured.response.Response in project tutorials by eugenp.
the class RestApiLiveTest method whenGetNotExistBookByName_thenNotFound.
@Test
public void whenGetNotExistBookByName_thenNotFound() {
final Response response = RestAssured.get(API_URI + "/search/findByTitle?title=" + randomAlphabetic(20));
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
assertTrue(response.jsonPath().getLong("page.totalElements") == 0);
}
use of io.restassured.response.Response in project tutorials by eugenp.
the class RestApiLiveTest 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_URI);
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
}
use of io.restassured.response.Response in project tutorials by eugenp.
the class RestApiLiveTest method whenGetNotExistBookById_thenNotFound.
@Test
public void whenGetNotExistBookById_thenNotFound() {
final Response response = RestAssured.get(API_URI + "/" + randomNumeric(4));
assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatusCode());
}
use of io.restassured.response.Response in project tutorials by eugenp.
the class SessionLiveTest method givenUnauthorizeUser_whenAccessResources_then_unAuthorized.
@Test
public void givenUnauthorizeUser_whenAccessResources_then_unAuthorized() {
final Response response = RestAssured.get(API_URI);
assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatusCode());
}
Aggregations