Skip to content

Commit 039176c

Browse files
committed
Fix unit tests
1 parent 26cdad4 commit 039176c

File tree

3 files changed

+14
-35
lines changed

3 files changed

+14
-35
lines changed

src/main/java/graphql/servlet/ExecutionResultSubscriber.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ExecutionResultSubscriber implements Subscriber<ExecutionResult> {
1717
private final GraphQLObjectMapper graphQLObjectMapper;
1818
private final CountDownLatch completedLatch = new CountDownLatch(1);
1919

20-
public ExecutionResultSubscriber(AtomicReference<Subscription> subscriptionRef, AsyncContext asyncContext,
20+
ExecutionResultSubscriber(AtomicReference<Subscription> subscriptionRef, AsyncContext asyncContext,
2121
GraphQLObjectMapper graphQLObjectMapper) {
2222
this.subscriptionRef = subscriptionRef;
2323
this.asyncContext = asyncContext;
@@ -35,7 +35,7 @@ public void onNext(ExecutionResult executionResult) {
3535
try {
3636
Writer writer = asyncContext.getResponse().getWriter();
3737
writer.write("data: ");
38-
graphQLObjectMapper.serializeResultAsJson(writer, executionResult);
38+
writer.write(graphQLObjectMapper.serializeResultAsJson(executionResult));
3939
writer.write("\n\n");
4040
writer.flush();
4141
subscriptionRef.get().request(1);
@@ -55,7 +55,7 @@ public void onComplete() {
5555
completedLatch.countDown();
5656
}
5757

58-
public void await() throws InterruptedException {
58+
void await() throws InterruptedException {
5959
completedLatch.await();
6060
}
6161

src/main/java/graphql/servlet/SingleAsynchronousQueryResponseWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SingleAsynchronousQueryResponseWriter implements QueryResponseWriter {
2929
private final long subscriptionTimeout;
3030

3131
@Override
32-
public void write(HttpServletRequest request, HttpServletResponse response) throws IOException {
32+
public void write(HttpServletRequest request, HttpServletResponse response) {
3333
Objects.requireNonNull(request, "Http servlet request cannot be null");
3434
response.setContentType(APPLICATION_EVENT_STREAM_UTF8);
3535
response.setStatus(STATUS_OK);

src/test/groovy/graphql/servlet/AbstractGraphQLHttpServletSpec.groovy

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package graphql.servlet
33
import com.fasterxml.jackson.databind.ObjectMapper
44
import graphql.Scalars
55
import graphql.execution.ExecutionStepInfo
6+
import graphql.execution.MergedField
67
import graphql.execution.reactive.SingleSubscriberPublisher
8+
import graphql.language.Field
79
import graphql.schema.GraphQLNonNull
810
import graphql.servlet.input.GraphQLInvocationInputFactory
911
import org.springframework.mock.web.MockHttpServletRequest
@@ -112,7 +114,6 @@ class AbstractGraphQLHttpServletSpec extends Specification {
112114
getResponseContent().data.echo == "test"
113115
}
114116

115-
@Ignore
116117
def "async query over HTTP GET starts async request"() {
117118
setup:
118119
servlet = TestUtils.createDefaultServlet({ env -> env.arguments.arg },{ env -> env.arguments.arg }, { env ->
@@ -284,7 +285,6 @@ class AbstractGraphQLHttpServletSpec extends Specification {
284285
getBatchedResponseContent()[1].data.echo == "test"
285286
}
286287

287-
@Ignore
288288
def "deferred query over HTTP GET"() {
289289
setup:
290290
request.addParameter('query', 'query { echo(arg:"test") @defer }')
@@ -369,7 +369,6 @@ class AbstractGraphQLHttpServletSpec extends Specification {
369369
getBatchedResponseContent()[1].errors.size() == 1
370370
}
371371

372-
@Ignore
373372
def "subscription query over HTTP GET with variables as string returns data"() {
374373
setup:
375374
request.addParameter('query', 'subscription Subscription($arg: String!) { echo(arg: $arg) }')
@@ -1051,11 +1050,11 @@ class AbstractGraphQLHttpServletSpec extends Specification {
10511050
getBatchedResponseContent()[1].data.echo == "test"
10521051
}
10531052

1054-
@Ignore
10551053
def "subscription query over HTTP POST with variables as string returns data"() {
10561054
setup:
10571055
request.setContent('{"query": "subscription Subscription($arg: String!) { echo(arg: $arg) }", "operationName": "Subscription", "variables": {"arg": "test"}}'.bytes)
10581056
request.setAsyncSupported(true)
1057+
request.setMethod("POST")
10591058

10601059
when:
10611060
servlet.doPost(request, response)
@@ -1070,11 +1069,11 @@ class AbstractGraphQLHttpServletSpec extends Specification {
10701069
getSubscriptionResponseContent()[1].data.echo == "Second\n\ntest"
10711070
}
10721071

1073-
@Ignore
10741072
def "defer query over HTTP POST"() {
10751073
setup:
10761074
request.setContent('{"query": "subscription Subscription($arg: String!) { echo(arg: $arg) }", "operationName": "Subscription", "variables": {"arg": "test"}}'.bytes)
10771075
request.setAsyncSupported(true)
1076+
request.setMethod("POST")
10781077

10791078
when:
10801079
servlet.doPost(request, response)
@@ -1089,7 +1088,6 @@ class AbstractGraphQLHttpServletSpec extends Specification {
10891088
getSubscriptionResponseContent()[1].data.echo == "Second\n\ntest"
10901089
}
10911090

1092-
@Ignore
10931091
def "deferred query that takes longer than initial results, should still be sent second"() {
10941092
setup:
10951093
servlet = TestUtils.createDefaultServlet({ env ->
@@ -1109,6 +1107,7 @@ class AbstractGraphQLHttpServletSpec extends Specification {
11091107
'''
11101108
]))
11111109
request.setAsyncSupported(true)
1110+
request.setMethod("POST")
11121111

11131112
when:
11141113
servlet.doPost(request, response)
@@ -1230,33 +1229,13 @@ class AbstractGraphQLHttpServletSpec extends Specification {
12301229
resp[1].errors != null
12311230
}
12321231

1233-
@Ignore
12341232
def "typeInfo is serialized correctly"() {
1235-
expect:
1236-
servlet.getConfiguration().getObjectMapper().getJacksonMapper().writeValueAsString(ExecutionStepInfo.newExecutionStepInfo().type(new GraphQLNonNull(Scalars.GraphQLString)).build()) != "{}"
1237-
}
1238-
1239-
@Ignore
1240-
def "isBatchedQuery check uses buffer length as read limit"() {
12411233
setup:
1242-
HttpServletRequest mockRequest = Mock()
1243-
ServletInputStream mockInputStream = Mock()
1244-
1245-
mockInputStream.markSupported() >> true
1246-
mockRequest.getInputStream() >> mockInputStream
1247-
mockRequest.getMethod() >> "POST"
1248-
mockRequest.getParts() >> Collections.emptyList()
1249-
1250-
when:
1251-
servlet.doPost(mockRequest, response)
1252-
1253-
then:
1254-
1 * mockInputStream.mark(128)
1255-
1256-
then:
1257-
1 * mockInputStream.read({ it.length == 128 }) >> -1
1234+
MergedField field = MergedField.newMergedField().addField(new Field("test")).build()
1235+
ExecutionStepInfo stepInfo = ExecutionStepInfo.newExecutionStepInfo().field(field).type(new GraphQLNonNull(Scalars.GraphQLString)).build()
12581236

1259-
then:
1260-
1 * mockInputStream.reset()
1237+
expect:
1238+
servlet.getConfiguration().getObjectMapper().getJacksonMapper().writeValueAsString(stepInfo) != "{}"
12611239
}
1240+
12621241
}

0 commit comments

Comments
 (0)