Skip to content

Commit b3f13b9

Browse files
committed
Refactoring in Client and Tester builder implementations
The default transport-specific client and tester extensions contained their builder implementations, but it makes more sense the other way around since the extensions are mainly about the builders they provide.
1 parent f9b84cb commit b3f13b9

30 files changed

+1219
-1200
lines changed

spring-graphql-docs/src/docs/asciidoc/testing.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ request execution as any `GraphQlTester`.
198198

199199
Many times it's enough to test GraphQL requests on the server side, without the use of a
200200
client to send requests over a transport protocol. To test directly against a
201-
`ExecutionGraphQlService`, use the `GraphQlServiceTester` extension:
201+
`ExecutionGraphQlService`, use the `ExecutionGraphQlServiceTester` extension:
202202

203203
[source,java,indent=0,subs="verbatim,quotes"]
204204
----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.graphql.test.tester;
18+
19+
20+
import java.util.function.Consumer;
21+
22+
import org.springframework.graphql.ExecutionGraphQlService;
23+
import org.springframework.util.Assert;
24+
25+
26+
/**
27+
* Default {@link ExecutionGraphQlServiceTester.Builder} implementation that
28+
* wraps an {@code ExecutionGraphQlService}.
29+
*
30+
* @author Rossen Stoyanchev
31+
* @since 1.0.0
32+
*/
33+
final class DefaultExecutionGraphQlServiceTesterBuilder
34+
extends AbstractGraphQlTesterBuilder<DefaultExecutionGraphQlServiceTesterBuilder>
35+
implements ExecutionGraphQlServiceTester.Builder<DefaultExecutionGraphQlServiceTesterBuilder> {
36+
37+
private final ExecutionGraphQlService service;
38+
39+
40+
DefaultExecutionGraphQlServiceTesterBuilder(ExecutionGraphQlService service) {
41+
Assert.notNull(service, "GraphQlService is required");
42+
this.service = service;
43+
}
44+
45+
DefaultExecutionGraphQlServiceTesterBuilder(GraphQlServiceGraphQlTransport transport) {
46+
this.service = transport.getGraphQlService();
47+
}
48+
49+
50+
@Override
51+
public ExecutionGraphQlServiceTester build() {
52+
GraphQlServiceGraphQlTransport transport = new GraphQlServiceGraphQlTransport(this.service);
53+
GraphQlTester tester = super.buildGraphQlTester(transport);
54+
return new DefaultExecutionGraphQlServiceTester(tester, transport, getBuilderInitializer());
55+
}
56+
57+
58+
/**
59+
* Default {@link ExecutionGraphQlServiceTester} implementation.
60+
*/
61+
private static class DefaultExecutionGraphQlServiceTester
62+
extends AbstractDelegatingGraphQlTester implements ExecutionGraphQlServiceTester {
63+
64+
private final GraphQlServiceGraphQlTransport transport;
65+
66+
private final Consumer<AbstractGraphQlTesterBuilder<?>> builderInitializer;
67+
68+
private DefaultExecutionGraphQlServiceTester(GraphQlTester tester, GraphQlServiceGraphQlTransport transport,
69+
Consumer<AbstractGraphQlTesterBuilder<?>> builderInitializer) {
70+
71+
super(tester);
72+
73+
Assert.notNull(transport, "GraphQlServiceTransport is required");
74+
Assert.notNull(builderInitializer, "`builderInitializer` is required");
75+
76+
this.transport = transport;
77+
this.builderInitializer = builderInitializer;
78+
}
79+
80+
@Override
81+
public DefaultExecutionGraphQlServiceTesterBuilder mutate() {
82+
DefaultExecutionGraphQlServiceTesterBuilder builder = new DefaultExecutionGraphQlServiceTesterBuilder(this.transport);
83+
this.builderInitializer.accept(builder);
84+
return builder;
85+
}
86+
87+
}
88+
89+
}

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlServiceTester.java

Lines changed: 0 additions & 87 deletions
This file was deleted.

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultHttpGraphQlTester.java

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)