This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ralf-ueberfuhr-ars/feature/test-fix
Replace @nested test classes by separate outer classes
- Loading branch information
Showing
4 changed files
with
205 additions
and
188 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...vider/src/test/java/de/schulung/sample/quarkus/boundary/CustomerApiGetCustomersTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.schulung.sample.quarkus.boundary; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.endsWith; | ||
import static org.hamcrest.Matchers.startsWith; | ||
|
||
/* | ||
* We test the app as a black box. | ||
* (Integration Test) | ||
*/ | ||
@QuarkusTest | ||
@DisplayName("API-Tests for: GET /customers") | ||
public class CustomerApiGetCustomersTests { | ||
|
||
/* | ||
* GET /customers, Accept: application/json | ||
* -> 200, Content-Type: application/json | ||
*/ | ||
@Test | ||
void shouldReturn200WhenGetCustomers() { | ||
given() | ||
.when() | ||
.accept(ContentType.JSON) | ||
.get("/customers") | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.JSON) | ||
.body(startsWith("[")) | ||
.body(endsWith("]")); | ||
// we could also test for JSON schema: https://medium.com/@dhadiprasetyo/asserting-json-schema-for-api-testing-with-java-and-restassured-79b4a851f282 | ||
} | ||
|
||
/* | ||
* GET /customers, Accept: application/xml | ||
* -> 406 | ||
*/ | ||
@Test | ||
void shouldReturn406WhenGetCustomersWithInvalidContentType() { | ||
given() | ||
.when() | ||
.accept(ContentType.XML) | ||
.get("/customers") | ||
.then() | ||
.statusCode(406); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
.../src/test/java/de/schulung/sample/quarkus/boundary/CustomerApiGetSingleCustomerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package de.schulung.sample.quarkus.boundary; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
/* | ||
* We test the app as a black box. | ||
* (Integration Test) | ||
*/ | ||
@QuarkusTest | ||
@DisplayName("API-Tests for: GET /customers/{uuid}") | ||
public class CustomerApiGetSingleCustomerTests { | ||
|
||
String customerLocation; | ||
|
||
@BeforeEach | ||
// we need to create a customer to be sure that one exist | ||
void setup() { | ||
customerLocation = given() | ||
.when() | ||
.contentType(ContentType.JSON) | ||
.body(""" | ||
{ | ||
"name": "Tom", | ||
"birth_date": "2000-10-04", | ||
"state": "active" | ||
} | ||
""") | ||
.accept(ContentType.JSON) | ||
.post("/customers") | ||
.then() | ||
.statusCode(201) | ||
.header("Location", is(notNullValue())) | ||
.extract() | ||
.header("Location"); | ||
} | ||
|
||
private void ensureCustomerIsDeleted() { | ||
given() | ||
.when() | ||
.delete(customerLocation) | ||
.then() | ||
.statusCode(204); | ||
} | ||
|
||
@Test | ||
void shouldReturn404WhenNotFound() { | ||
ensureCustomerIsDeleted(); | ||
given() | ||
.when() | ||
.accept(ContentType.JSON) | ||
.get(customerLocation) | ||
.then() | ||
.statusCode(404); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...ider/src/test/java/de/schulung/sample/quarkus/boundary/CustomerApiPostCustomersTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package de.schulung.sample.quarkus.boundary; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
/* | ||
* We test the app as a black box. | ||
* (Integration Test) | ||
*/ | ||
@QuarkusTest | ||
@DisplayName("API-Tests for: POST /customers") | ||
public class CustomerApiPostCustomersTests { | ||
|
||
@Test | ||
void shouldCreateCustomer() { | ||
var location = given() | ||
.when() | ||
.contentType(ContentType.JSON) | ||
.body(""" | ||
{ | ||
"name": "Tom", | ||
"birth_date": "2000-10-04", | ||
"state": "active" | ||
} | ||
""") | ||
.accept(ContentType.JSON) | ||
.post("/customers") | ||
.then() | ||
.statusCode(201) | ||
.header("Location", is(notNullValue())) | ||
.header("Location", startsWith("http")) | ||
.contentType(ContentType.JSON) | ||
.body("name", is(equalTo("Tom"))) | ||
.body("birth_date", is(equalTo("2000-10-04"))) | ||
.body("uuid", is(notNullValue())) | ||
.extract() | ||
.header("Location"); | ||
|
||
given() | ||
.when() | ||
.accept(ContentType.JSON) | ||
.get(location) | ||
.then() | ||
.statusCode(200) | ||
.body("name", is(equalTo("Tom"))) | ||
.body("birth_date", is(equalTo("2000-10-04"))); | ||
} | ||
|
||
@Test | ||
void shouldNotCreateCustomerWithInvalidName() { | ||
given() | ||
.when() | ||
.contentType(ContentType.JSON) | ||
.body(""" | ||
{ | ||
"name": "T", | ||
"birth_date": "2000-10-04", | ||
"state": "active" | ||
} | ||
""") | ||
.accept(ContentType.JSON) | ||
.post("/customers") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
@Test | ||
void shouldNotCreateCustomerWithInvalidState() { | ||
given() | ||
.when() | ||
.contentType(ContentType.JSON) | ||
.body(""" | ||
{ | ||
"name": "Tom Mayer", | ||
"birth_date": "2000-10-04", | ||
"state": "gelbekatze" | ||
} | ||
""") | ||
.accept(ContentType.JSON) | ||
.post("/customers") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
} |
188 changes: 0 additions & 188 deletions
188
...omer-api-provider/src/test/java/de/schulung/sample/quarkus/boundary/CustomerApiTests.java
This file was deleted.
Oops, something went wrong.