Search in sources :

Example 11 with Book

use of org.baeldung.persistence.model.Book 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());
}
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 12 with Book

use of org.baeldung.persistence.model.Book in project tutorials by eugenp.

the class SpringBootBootstrapIntegrationTest method whenCreateNewBook_thenCreated.

// POST
@Test
public void whenCreateNewBook_thenCreated() {
    final Book book = createRandomBook();
    final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_ROOT);
    assertEquals(HttpStatus.CREATED.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 13 with Book

use of org.baeldung.persistence.model.Book in project tutorials by eugenp.

the class SpringBootBootstrapIntegrationTest method createRandomBook.

// ===============================
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 14 with Book

use of org.baeldung.persistence.model.Book in project tutorials by eugenp.

the class RestApiLiveTest method whenCreateNewBook_thenCreated.

// POST
@Test
public void whenCreateNewBook_thenCreated() {
    final Book book = createRandomBook();
    final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_URI);
    assertEquals(HttpStatus.CREATED.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 15 with Book

use of org.baeldung.persistence.model.Book in project tutorials by eugenp.

the class RestApiLiveTest 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"));
}
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