forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorTest.java
80 lines (63 loc) · 2.08 KB
/
ErrorTest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package io.quarkus.smallrye.graphql.deployment;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
import io.smallrye.common.annotation.NonBlocking;
public class ErrorTest extends AbstractGraphQLTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(ErrorApi.class, Foo.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
@Test
public void testNonBlockingError() {
String query = getPayload("{ foo { message} }");
RestAssured.given()
.body(query)
.contentType(MEDIATYPE_JSON)
.post("/graphql/")
.then()
.assertThat()
.statusCode(500);
}
@Test
public void testBlockingError() {
String query = getPayload("{ blockingFoo { message} }");
RestAssured.given()
.body(query)
.contentType(MEDIATYPE_JSON)
.post("/graphql/")
.then()
.log().everything()
.assertThat()
.statusCode(500);
}
public static class Foo {
private String message;
public Foo(String foo) {
this.message = foo;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
@GraphQLApi
public static class ErrorApi {
@Query
@NonBlocking
public Foo foo() {
throw new OutOfMemoryError("a SuperHero has used all the memory");
}
@Query
public Foo blockingFoo() {
throw new OutOfMemoryError("a SuperHero has used all the memory");
}
}
}