|
| 1 | +package org.acme.e2e; |
| 2 | + |
| 3 | +import static io.restassured.RestAssured.get; |
| 4 | +import static io.restassured.RestAssured.given; |
| 5 | +import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
| 6 | +import static org.hamcrest.Matchers.is; |
| 7 | + |
| 8 | +import jakarta.ws.rs.core.Response.Status; |
| 9 | + |
| 10 | +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; |
| 11 | +import org.junit.jupiter.api.Order; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | +import org.junit.jupiter.api.TestMethodOrder; |
| 14 | + |
| 15 | +import io.quarkus.test.junit.QuarkusIntegrationTest; |
| 16 | + |
| 17 | +import io.restassured.http.ContentType; |
| 18 | + |
| 19 | + |
| 20 | +// Note: There isn't an equivalent of this test in the Spring projects. |
| 21 | +// It tests the application as a prod mode application, from a different process. |
| 22 | +// Because the process is not shared and the application is run in prod mode, the database is empty initially. |
| 23 | +@QuarkusIntegrationTest |
| 24 | +@TestMethodOrder(OrderAnnotation.class) |
| 25 | +public class FruitControllerIT { |
| 26 | + private static final int DEFAULT_ORDER = 1; |
| 27 | + |
| 28 | + @Test |
| 29 | + @Order(DEFAULT_ORDER) |
| 30 | + public void getFruitNotFound() { |
| 31 | + get("/fruits/Watermelon").then() |
| 32 | + .statusCode(Status.NOT_FOUND.getStatusCode()); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + @Order(DEFAULT_ORDER + 1) |
| 37 | + public void addFruit() { |
| 38 | + get("/fruits").then() |
| 39 | + .body("$.size()", is(0)); |
| 40 | + |
| 41 | + given() |
| 42 | + .contentType(ContentType.JSON) |
| 43 | + .body("{\"name\":\"Pomelo\",\"description\":\"Exotic fruit\"}") |
| 44 | + .when().post("/fruits") |
| 45 | + .then() |
| 46 | + .contentType(ContentType.JSON) |
| 47 | + .statusCode(Status.OK.getStatusCode()) |
| 48 | + .body("id", greaterThanOrEqualTo(1)) |
| 49 | + .body("name", is("Pomelo")) |
| 50 | + .body("description", is("Exotic fruit")); |
| 51 | + |
| 52 | + get("/fruits").then() |
| 53 | + .body("$.size()", is(1)); |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | + @Test |
| 58 | + @Order(DEFAULT_ORDER+2) |
| 59 | + public void getFruitFound() { |
| 60 | + get("/fruits/Pomelo").then() |
| 61 | + .statusCode(Status.OK.getStatusCode()) |
| 62 | + .contentType(ContentType.JSON) |
| 63 | + .body("id", greaterThanOrEqualTo(1)) |
| 64 | + .body("name", is("Pomelo")) |
| 65 | + .body("description", is("Exotic fruit")); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + @Order(DEFAULT_ORDER+3) |
| 70 | + public void getAll() { |
| 71 | + get("/fruits").then() |
| 72 | + .statusCode(Status.OK.getStatusCode()) |
| 73 | + .contentType(ContentType.JSON) |
| 74 | + .body("$.size()", is(1)) |
| 75 | + .body("[0].id", greaterThanOrEqualTo(1)) |
| 76 | + .body("[0].name", is("Pomelo")) |
| 77 | + .body("[0].description", is("Exotic fruit")); |
| 78 | + } |
| 79 | + |
| 80 | +} |
0 commit comments