Shorten GraphQlResponse[Field|Error] and rename GraphQlService

Rename GraphQlService to ExecutionGraphQlService following the renaming
of the request and response to ExecutionGraphQl[Request|Response].

See gh-332
This commit is contained in:
rstoyanchev
2022-03-20 20:47:15 +00:00
parent 67711f7331
commit 91e7f285fa
43 changed files with 168 additions and 164 deletions

View File

@@ -27,7 +27,7 @@ import org.springframework.graphql.ExecutionGraphQlRequest;
import org.springframework.graphql.ExecutionGraphQlResponse;
import org.springframework.graphql.GraphQlRequest;
import org.springframework.graphql.GraphQlResponse;
import org.springframework.graphql.GraphQlResponseError;
import org.springframework.graphql.ResponseError;
import org.springframework.graphql.support.DefaultExecutionGraphQlRequest;
import org.springframework.graphql.support.DefaultExecutionGraphQlResponse;
import org.springframework.graphql.client.GraphQlTransport;
@@ -61,7 +61,7 @@ abstract class AbstractDirectTransport implements GraphQlTransport {
Object data = response.getData();
AssertionErrors.assertTrue("Not a Publisher: " + data, data instanceof Publisher);
List<GraphQlResponseError> errors = response.getErrors();
List<ResponseError> errors = response.getErrors();
AssertionErrors.assertTrue("Subscription errors: " + errors, CollectionUtils.isEmpty(errors));
return Flux.from((Publisher<ExecutionResult>) data).map(executionResult ->

View File

@@ -25,7 +25,7 @@ import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import org.springframework.graphql.GraphQlResponseError;
import org.springframework.graphql.ResponseError;
import org.springframework.graphql.client.AbstractGraphQlClientBuilder;
import org.springframework.graphql.client.GraphQlTransport;
import org.springframework.graphql.support.CachingDocumentSource;
@@ -57,7 +57,7 @@ public abstract class AbstractGraphQlTesterBuilder<B extends AbstractGraphQlTest
@Nullable
private Predicate<GraphQlResponseError> errorFilter;
private Predicate<ResponseError> errorFilter;
private DocumentSource documentSource = new CachingDocumentSource(new ResourceDocumentSource());
@@ -67,7 +67,7 @@ public abstract class AbstractGraphQlTesterBuilder<B extends AbstractGraphQlTest
@Override
public B errorFilter(Predicate<GraphQlResponseError> predicate) {
public B errorFilter(Predicate<ResponseError> predicate) {
this.errorFilter = (this.errorFilter != null ? errorFilter.and(predicate) : predicate);
return self();
}

View File

@@ -19,12 +19,12 @@ package org.springframework.graphql.test.tester;
import java.util.function.Consumer;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.ExecutionGraphQlService;
import org.springframework.util.Assert;
/**
* Default {@link GraphQlServiceTester} that uses a {@link GraphQlService} for
* Default {@link GraphQlServiceTester} that uses a {@link ExecutionGraphQlService} for
* request execution.
*
* @author Rossen Stoyanchev
@@ -64,9 +64,9 @@ final class DefaultGraphQlServiceTester extends AbstractDelegatingGraphQlTester
static class Builder<B extends Builder<B>> extends AbstractGraphQlTesterBuilder<B>
implements GraphQlServiceTester.Builder<B> {
private final GraphQlService service;
private final ExecutionGraphQlService service;
Builder(GraphQlService service) {
Builder(ExecutionGraphQlService service) {
Assert.notNull(service, "GraphQlService is required");
this.service = service;
}

View File

@@ -37,7 +37,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.graphql.support.DefaultGraphQlRequest;
import org.springframework.graphql.GraphQlRequest;
import org.springframework.graphql.GraphQlResponse;
import org.springframework.graphql.GraphQlResponseError;
import org.springframework.graphql.ResponseError;
import org.springframework.graphql.client.GraphQlTransport;
import org.springframework.graphql.support.DocumentSource;
import org.springframework.lang.Nullable;
@@ -62,7 +62,7 @@ final class DefaultGraphQlTester implements GraphQlTester {
private final GraphQlTransport transport;
@Nullable
private final Predicate<GraphQlResponseError> errorFilter;
private final Predicate<ResponseError> errorFilter;
private final Configuration jsonPathConfig;
@@ -77,7 +77,7 @@ final class DefaultGraphQlTester implements GraphQlTester {
* Package private constructor for use from {@link AbstractGraphQlTesterBuilder}.
*/
DefaultGraphQlTester(
GraphQlTransport transport, @Nullable Predicate<GraphQlResponseError> errorFilter,
GraphQlTransport transport, @Nullable Predicate<ResponseError> errorFilter,
Configuration jsonPathConfig, DocumentSource documentSource, Duration timeout,
Consumer<AbstractGraphQlTesterBuilder<?>> builderInitializer) {
@@ -210,15 +210,15 @@ final class DefaultGraphQlTester implements GraphQlTester {
private final Supplier<String> jsonContent;
private final List<GraphQlResponseError> errors;
private final List<ResponseError> errors;
private final List<GraphQlResponseError> unexpectedErrors;
private final List<ResponseError> unexpectedErrors;
private final Consumer<Runnable> assertDecorator;
private ResponseDelegate(
GraphQlResponse response, @Nullable Predicate<GraphQlResponseError> errorFilter,
GraphQlResponse response, @Nullable Predicate<ResponseError> errorFilter,
Consumer<Runnable> assertDecorator, Configuration jsonPathConfig) {
this.jsonDoc = JsonPath.parse(response.toMap(), jsonPathConfig);
@@ -254,9 +254,9 @@ final class DefaultGraphQlTester implements GraphQlTester {
this.assertDecorator.accept(task);
}
boolean filterErrors(Predicate<GraphQlResponseError> predicate) {
boolean filterErrors(Predicate<ResponseError> predicate) {
boolean filtered = false;
for (GraphQlResponseError error : this.errors) {
for (ResponseError error : this.errors) {
if (predicate.test(error)) {
this.unexpectedErrors.remove(error);
filtered = true;
@@ -265,12 +265,12 @@ final class DefaultGraphQlTester implements GraphQlTester {
return filtered;
}
void expectErrors(Predicate<GraphQlResponseError> predicate) {
void expectErrors(Predicate<ResponseError> predicate) {
boolean filtered = filterErrors(predicate);
this.assertDecorator.accept(() -> AssertionErrors.assertTrue("No matching errors.", filtered));
}
void consumeErrors(Consumer<List<GraphQlResponseError>> consumer) {
void consumeErrors(Consumer<List<ResponseError>> consumer) {
filterErrors(error -> true);
consumer.accept(this.errors);
}
@@ -294,7 +294,7 @@ final class DefaultGraphQlTester implements GraphQlTester {
private final ResponseDelegate delegate;
private DefaultResponse(
GraphQlResponse response, @Nullable Predicate<GraphQlResponseError> errorFilter,
GraphQlResponse response, @Nullable Predicate<ResponseError> errorFilter,
Consumer<Runnable> assertDecorator, Configuration jsonPathConfig) {
this.delegate = new ResponseDelegate(response, errorFilter, assertDecorator, jsonPathConfig);
@@ -312,13 +312,13 @@ final class DefaultGraphQlTester implements GraphQlTester {
}
@Override
public Errors filter(Predicate<GraphQlResponseError> predicate) {
public Errors filter(Predicate<ResponseError> predicate) {
this.delegate.filterErrors(predicate);
return this;
}
@Override
public Errors expect(Predicate<GraphQlResponseError> predicate) {
public Errors expect(Predicate<ResponseError> predicate) {
this.delegate.expectErrors(predicate);
return this;
}
@@ -330,7 +330,7 @@ final class DefaultGraphQlTester implements GraphQlTester {
}
@Override
public Traversable satisfy(Consumer<List<GraphQlResponseError>> consumer) {
public Traversable satisfy(Consumer<List<ResponseError>> consumer) {
this.delegate.consumeErrors(consumer);
return this;
}

View File

@@ -16,10 +16,10 @@
package org.springframework.graphql.test.tester;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.ExecutionGraphQlService;
/**
* {@link GraphQlTester} that executes requests through a {@link GraphQlService}
* {@link GraphQlTester} that executes requests through a {@link ExecutionGraphQlService}
* Use it for server-side tests, without a client.
*
* @author Rossen Stoyanchev
@@ -35,14 +35,14 @@ public interface GraphQlServiceTester extends GraphQlTester {
/**
* Create a {@link GraphQlServiceTester} instance.
*/
static GraphQlServiceTester create(GraphQlService service) {
static GraphQlServiceTester create(ExecutionGraphQlService service) {
return builder(service).build();
}
/**
* Return a builder for {@link GraphQlServiceTester}.
*/
static GraphQlServiceTester.Builder<?> builder(GraphQlService service) {
static GraphQlServiceTester.Builder<?> builder(ExecutionGraphQlService service) {
return new DefaultGraphQlServiceTester.Builder<>(service);
}

View File

@@ -21,28 +21,28 @@ import reactor.core.publisher.Mono;
import org.springframework.graphql.ExecutionGraphQlRequest;
import org.springframework.graphql.ExecutionGraphQlResponse;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.ExecutionGraphQlService;
import org.springframework.util.Assert;
/**
* {@code GraphQlTransport} that calls directly a {@link GraphQlService}.
* {@code GraphQlTransport} that calls directly a {@link ExecutionGraphQlService}.
*
* @author Rossen Stoyanchev
* @since 1.0.0
*/
final class GraphQlServiceTransport extends AbstractDirectTransport {
private final GraphQlService graphQlService;
private final ExecutionGraphQlService graphQlService;
GraphQlServiceTransport(GraphQlService graphQlService) {
GraphQlServiceTransport(ExecutionGraphQlService graphQlService) {
Assert.notNull(graphQlService, "GraphQlService is required");
this.graphQlService = graphQlService;
}
public GraphQlService getGraphQlService() {
public ExecutionGraphQlService getGraphQlService() {
return this.graphQlService;
}

View File

@@ -24,7 +24,7 @@ import java.util.function.Predicate;
import reactor.core.publisher.Flux;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.graphql.GraphQlResponseError;
import org.springframework.graphql.ResponseError;
import org.springframework.graphql.client.GraphQlTransport;
import org.springframework.graphql.support.DocumentSource;
import org.springframework.graphql.support.ResourceDocumentSource;
@@ -103,7 +103,7 @@ public interface GraphQlTester {
* @param predicate the error filter to add
* @return the same builder instance
*/
B errorFilter(Predicate<GraphQlResponseError> predicate);
B errorFilter(Predicate<ResponseError> predicate);
/**
* Configure a {@link DocumentSource} for use with
@@ -448,7 +448,7 @@ public interface GraphQlTester {
* @param errorPredicate the error filter to add
* @return the same spec to add more filters before {@link #verify()}
*/
Errors filter(Predicate<GraphQlResponseError> errorPredicate);
Errors filter(Predicate<ResponseError> errorPredicate);
/**
* Use this to declare errors that are expected.
@@ -461,7 +461,7 @@ public interface GraphQlTester {
* @param errorPredicate the predicate for the expected error
* @return the same spec to add more filters or expected errors
*/
Errors expect(Predicate<GraphQlResponseError> errorPredicate);
Errors expect(Predicate<ResponseError> errorPredicate);
/**
* Verify there are either no errors or that there no unexpected errors that have
@@ -477,7 +477,7 @@ public interface GraphQlTester {
* @param errorsConsumer to inspect errors with
* @return a spec to switch to a data path
*/
Traversable satisfy(Consumer<List<GraphQlResponseError>> errorsConsumer);
Traversable satisfy(Consumer<List<ResponseError>> errorsConsumer);
}

View File

@@ -20,13 +20,13 @@ import graphql.GraphqlErrorBuilder;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.ExecutionGraphQlService;
import org.springframework.graphql.support.DocumentSource;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link GraphQlTester} builder with a mock {@link GraphQlService}.
* Tests for {@link GraphQlTester} builder with a mock {@link ExecutionGraphQlService}.
*
* @author Rossen Stoyanchev
*/

View File

@@ -30,7 +30,7 @@ import org.mockito.ArgumentCaptor;
import reactor.core.publisher.Mono;
import org.springframework.graphql.ExecutionGraphQlRequest;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.ExecutionGraphQlService;
import org.springframework.graphql.support.DefaultExecutionGraphQlResponse;
import static org.mockito.BDDMockito.given;
@@ -48,7 +48,7 @@ public class GraphQlTesterTestSupport {
private final ArgumentCaptor<ExecutionGraphQlRequest> requestCaptor = ArgumentCaptor.forClass(ExecutionGraphQlRequest.class);
private final GraphQlService graphQlService = mock(GraphQlService.class);
private final ExecutionGraphQlService graphQlService = mock(ExecutionGraphQlService.class);
private final GraphQlTester.Builder<?> graphQlTesterBuilder = GraphQlServiceTester.builder(this.graphQlService);

View File

@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.graphql.ExecutionGraphQlRequest;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.ExecutionGraphQlService;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests for {@link GraphQlTester} with a mock {@link GraphQlService}.
* Tests for {@link GraphQlTester} with a mock {@link ExecutionGraphQlService}.
*
* @author Rossen Stoyanchev
*/