✅ (api): Cover REST API in native integration tests
Changes
1 file changed, +85 -0
ADD
src/test/java/de/workaround/api/ApiSmokeIT.java
+85 -0
@@ -0,0 +1,85 @@
1
+package de.workaround.api;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import io.quarkus.test.junit.QuarkusIntegrationTest;
6
+
7
+import static io.restassured.RestAssured.given;
8
+import static org.hamcrest.CoreMatchers.equalTo;
9
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
10
+import static org.hamcrest.Matchers.hasItem;
11
+
12
+/**
13
+ * Exercises the JSON REST API against the packaged application (JVM jar or native binary). The seeded
14
+ * alice/demo repository — public, with a demo merge request carrying a line comment (enabled via
15
+ * GITSHARK_DEV_SEED_DATA in the failsafe config) — lets anonymous reads drive the native-sensitive path:
16
+ * JAX-RS routing, the {@code /api} bearer-token filter, and Jackson serialization of the response records.
17
+ * Token-authenticated writes stay in the JVM-only {@code *Test} classes (a black-box IT cannot mint a token).
18
+ */
19
+@QuarkusIntegrationTest
20
+class ApiSmokeIT
21
+{
22
+ @Test
23
+ void repositoryListIncludesTheSeededPublicRepository()
24
+ {
25
+ given()
26
+ .when().get("/api/v1/repos")
27
+ .then()
28
+ .statusCode(200)
29
+ .contentType("application/json")
30
+ .body("name", hasItem("demo"));
31
+ }
32
+
33
+ @Test
34
+ void repositoryDetailIsServedAsJson()
35
+ {
36
+ given()
37
+ .when().get("/api/v1/repos/alice/demo")
38
+ .then()
39
+ .statusCode(200)
40
+ .contentType("application/json")
41
+ .body("owner", equalTo("alice"))
42
+ .body("name", equalTo("demo"))
43
+ .body("visibility", equalTo("PUBLIC"));
44
+ }
45
+
46
+ @Test
47
+ void issuesListIsServedAsJson()
48
+ {
49
+ given()
50
+ .when().get("/api/v1/repos/alice/demo/issues")
51
+ .then()
52
+ .statusCode(200)
53
+ .contentType("application/json")
54
+ .body("size()", greaterThanOrEqualTo(0));
55
+ }
56
+
57
+ @Test
58
+ void mergeRequestAndCommentViewsSerialize()
59
+ {
60
+ // the seeder creates one demo merge request with a line comment; both must serialize under native
61
+ int number = given()
62
+ .when().get("/api/v1/repos/alice/demo/merge-requests")
63
+ .then()
64
+ .statusCode(200)
65
+ .contentType("application/json")
66
+ .body("size()", greaterThanOrEqualTo(1))
67
+ .extract().path("[0].number");
68
+
69
+ given()
70
+ .when().get("/api/v1/repos/alice/demo/merge-requests/" + number + "/comments")
71
+ .then()
72
+ .statusCode(200)
73
+ .contentType("application/json")
74
+ .body("size()", greaterThanOrEqualTo(1));
75
+ }
76
+
77
+ @Test
78
+ void currentUserWithoutTokenIsUnauthorized()
79
+ {
80
+ given()
81
+ .when().get("/api/v1/user")
82
+ .then()
83
+ .statusCode(401);
84
+ }
85
+}