Search in sources :

Example 6 with Book

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());
}
Also used : Response(io.restassured.response.Response) Book(org.baeldung.persistence.model.Book) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Book

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);
}
Also used : Response(io.restassured.response.Response) Book(org.baeldung.persistence.model.Book) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Book

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());
}
Also used : Response(io.restassured.response.Response) Book(org.baeldung.persistence.model.Book) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with Book

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;
}
Also used : Book(org.baeldung.persistence.model.Book)

Example 10 with 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"));
}
Also used : Response(io.restassured.response.Response) Book(org.baeldung.persistence.model.Book) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Book (org.baeldung.persistence.model.Book)15 Response (io.restassured.response.Response)13 Test (org.junit.Test)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 List (java.util.List)1