Skip to content

Commit 1d8d944

Browse files
authored
Elide 5.x - Async Tests, Break loop when fail (#1422)
* Loop Break when query fails * adding assert fail * Removing queued * Import fix * Tomcat version fix * Assert import * Error message
1 parent a7ba85a commit 1d8d944

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

elide-integration-tests/src/test/java/com/yahoo/elide/async/integration/tests/AsyncIT.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ public void jsonApiHappyPath1() throws InterruptedException {
204204
.accept("application/vnd.api+json")
205205
.get("/asyncQuery/edc4a871-dff2-4054-804e-d80075cf830e");
206206

207+
String outputResponse = response.jsonPath().getString("data.attributes.status");
208+
207209
// If Async Query is created and completed
208-
if (response.jsonPath().getString("data.attributes.status").equals("COMPLETE")) {
210+
if (outputResponse.equals("COMPLETE")) {
209211

210212
// Validate AsyncQuery Response
211213
response
@@ -223,9 +225,12 @@ public void jsonApiHappyPath1() throws InterruptedException {
223225
.body("data.attributes.result.httpStatus", equalTo(200))
224226
.body("data.attributes.result.resultType", equalTo(ResultType.EMBEDDED.toString()));
225227

226-
228+
break;
229+
} else if (!(outputResponse.equals("PROCESSING"))) {
230+
fail("Async Query has failed.");
227231
break;
228232
}
233+
229234
i++;
230235

231236
if (i == 1000) {
@@ -350,6 +355,9 @@ public void graphQLHappyPath1() throws InterruptedException {
350355

351356
assertEquals(expectedResponse, responseGraphQL);
352357
break;
358+
} else if (!(responseGraphQL.contains("\"status\":\"PROCESSING\""))) {
359+
fail("Async Query has failed.");
360+
break;
353361
}
354362
i++;
355363

@@ -460,8 +468,10 @@ public void jsonApiUnknownRequestTests() throws InterruptedException {
460468
.accept("application/vnd.api+json")
461469
.get("/asyncQuery/ba31ca4e-ed8f-4be0-a0f3-12088fa9263b");
462470

471+
String outputResponse = response.jsonPath().getString("data.attributes.status");
472+
463473
// If Async Query is created and completed then validate results
464-
if (response.jsonPath().getString("data.attributes.status").equals("COMPLETE")) {
474+
if (outputResponse.equals("COMPLETE")) {
465475
// Validate AsyncQuery Response
466476
response
467477
.then()
@@ -475,6 +485,9 @@ public void jsonApiUnknownRequestTests() throws InterruptedException {
475485
.body("data.attributes.result.httpStatus", equalTo(404));
476486

477487
break;
488+
} else if (!(outputResponse.equals("PROCESSING"))) {
489+
fail("Async Query has failed.");
490+
break;
478491
}
479492
i++;
480493

@@ -560,8 +573,10 @@ public void noReadEntityTests() throws InterruptedException {
560573
.accept("application/vnd.api+json")
561574
.get("/asyncQuery/0b0dd4e7-9cdc-4bbc-8db2-5c1491c5ee1e");
562575

576+
String outputResponse = response.jsonPath().getString("data.attributes.status");
577+
563578
// If Async Query is created and completed
564-
if (response.jsonPath().getString("data.attributes.status").equals("COMPLETE")) {
579+
if (outputResponse.equals("COMPLETE")) {
565580
// Validate AsyncQuery Response
566581
response
567582
.then()
@@ -576,6 +591,9 @@ public void noReadEntityTests() throws InterruptedException {
576591
.body("data.attributes.result.resultType", equalTo(ResultType.EMBEDDED.toString()));
577592

578593
break;
594+
} else if (!(outputResponse.equals("PROCESSING"))) {
595+
fail("Async Query has failed.");
596+
break;
579597
}
580598
i++;
581599

elide-spring/elide-spring-boot-autoconfigure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
<properties>
4343
<spring.boot.version>2.3.0.RELEASE</spring.boot.version>
44-
<tomcat.version>9.0.35</tomcat.version>
44+
<tomcat.version>9.0.37</tomcat.version>
4545
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
4646
<min_jdk_version>1.8</min_jdk_version>
4747
<max_jdk_version>1.8</max_jdk_version>

elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/AsyncTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.hamcrest.CoreMatchers.equalTo;
1818
import static org.hamcrest.CoreMatchers.notNullValue;
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.fail;
2021

2122
import com.yahoo.elide.core.HttpStatus;
2223

@@ -71,8 +72,10 @@ public void testAsyncApiEndpoint() throws InterruptedException {
7172
.accept("application/vnd.api+json")
7273
.get("/json/asyncQuery/ba31ca4e-ed8f-4be0-a0f3-12088fa9263d");
7374

75+
String outputResponse = response.jsonPath().getString("data.attributes.status");
76+
7477
//If Async Query is created and completed then validate results
75-
if (response.jsonPath().getString("data.attributes.status").equals("COMPLETE")) {
78+
if (outputResponse.equals("COMPLETE")) {
7679

7780
// Validate AsyncQuery Response
7881
response
@@ -103,6 +106,9 @@ public void testAsyncApiEndpoint() throws InterruptedException {
103106

104107
assertEquals(expectedResponse, responseGraphQL);
105108
break;
109+
} else if (!(outputResponse.equals("PROCESSING"))) {
110+
fail("Async Query has failed.");
111+
break;
106112
}
107113
}
108114
}

elide-standalone/src/test/java/example/ElideStandaloneTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ public void testAsyncApiEndpoint() throws InterruptedException {
281281
.accept("application/vnd.api+json")
282282
.get("/api/v1/asyncQuery/ba31ca4e-ed8f-4be0-a0f3-12088fa9263d");
283283

284+
String outputResponse = response.jsonPath().getString("data.attributes.status");
285+
284286
// If Async Query is created and completed
285-
if (response.jsonPath().getString("data.attributes.status").equals("COMPLETE")) {
287+
if (outputResponse.equals("COMPLETE")) {
286288

287289
// Validate AsyncQuery Response
288290
response
@@ -311,6 +313,9 @@ public void testAsyncApiEndpoint() throws InterruptedException {
311313
String expectedResponse = "{\"data\":{\"asyncQuery\":{\"edges\":[{\"node\":{\"id\":\"ba31ca4e-ed8f-4be0-a0f3-12088fa9263d\",\"queryType\":\"JSONAPI_V1_0\",\"status\":\"COMPLETE\",\"result\":{\"responseBody\":\"{\\\"data\\\":[{\\\"type\\\":\\\"post\\\",\\\"id\\\":\\\"2\\\",\\\"attributes\\\":{\\\"abusiveContent\\\":false,\\\"content\\\":\\\"This is my first post. woot.\\\",\\\"date\\\":\\\"2019-01-01T00:00Z\\\"}}]}\",\"httpStatus\":200,\"resultType\":\"EMBEDDED\",\"contentLength\":141}}}]}}}";
312314
assertEquals(expectedResponse, responseGraphQL);
313315
break;
316+
} else if (!(outputResponse.equals("PROCESSING"))) {
317+
fail("Async Query has failed.");
318+
break;
314319
}
315320
i++;
316321

0 commit comments

Comments
 (0)