-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
InstrumentationTest.java
84 lines (66 loc) · 2.47 KB
/
InstrumentationTest.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
81
82
83
84
package io.quarkus.smallrye.graphql.deployment;
import static io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest.getPropertyAsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;
import org.eclipse.microprofile.graphql.Source;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
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 InstrumentationTest extends AbstractGraphQLTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(FooApi.class, Foo.class)
.addAsResource(new StringAsset(getPropertyAsString(configuration())), "application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
@Test
public void testQueryDepth() {
String query = getPayload("{ foo { nestedFoo { nestedFoo { message}}}}");
RestAssured.given()
.body(query)
.contentType(MEDIATYPE_JSON)
.post("/graphql/")
.then()
.log().all()
.assertThat()
.body("errors[0].message", equalTo("maximum query depth exceeded 4 > 1"))
.body("data", nullValue());
}
private static Map<String, String> configuration() {
Map<String, String> m = new HashMap<>();
m.put("quarkus.smallrye-graphql.events.enabled", "true");
m.put("smallrye.graphql.instrumentation.queryDepth", "1");
return m;
}
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 FooApi {
@Query
@NonBlocking
public Foo foo() {
return new Foo("foo");
}
public Foo nestedFoo(@Source Foo foo) {
return new Foo("foo");
}
}
}