Search in sources :

Example 1 with Book

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

Example 2 with Book

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());
}
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 3 with Book

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());
}
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 4 with Book

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"));
}
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 5 with Book

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