-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathDynamodbResourcesTest.java
64 lines (56 loc) · 2.21 KB
/
DynamodbResourcesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.acme.dynamodb;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import io.quarkus.test.junit.QuarkusTest;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response.Status;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@QuarkusTest
public class DynamodbResourcesTest {
private static final BiFunction<String, String, String> FRUIT = (name, description) -> String
.format("{\"name\":\"%s\", \"description\":\"%s\"}", name, description);
@ParameterizedTest
@ValueSource(strings = {"fruits", "async-fruits"})
void testResource(final String testedResource) {
List<String> data = Arrays.asList("Cherry", "Pear");
//Add fruits
data.forEach(fruit -> {
given()
.pathParam("resource", testedResource)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.body(FRUIT.apply(fruit, "description-" + fruit))
.when()
.post("/{resource}")
.then()
.statusCode(Status.OK.getStatusCode());
}
);
//List fruits
given()
.pathParam("resource", testedResource)
.when().get("/{resource}")
.then()
.statusCode(200)
.body("size()", equalTo(2))
.body("[0].name", equalTo(data.get(1)))
.body("[0].description", equalTo("description-" + data.get(1)))
.body("[1].name", equalTo(data.get(0)))
.body("[1].description", equalTo("description-" + data.get(0)));
//Get single fruit
data.forEach(fruit ->
given()
.pathParam("resource", testedResource)
.pathParam("key", fruit)
.when().get("/{resource}/{key}")
.then()
.statusCode(200)
.body("name", equalTo(fruit))
.body("description", equalTo("description-" + fruit))
);
}
}