diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 47d25d97..7cba5d2e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,8 +1,5 @@ name: "Pull request" on: - push: - branches-ignore: - - master pull_request: types: [ opened, synchronize, reopened ] diff --git a/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/SimpleListConnection.java b/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/SimpleListConnection.java index 401592a2..bde31747 100644 --- a/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/SimpleListConnection.java +++ b/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/SimpleListConnection.java @@ -3,39 +3,32 @@ import com.oembedler.moon.graphql.engine.relay.ConnectionObjectType; import com.oembedler.moon.graphql.engine.relay.EdgeObjectType; import com.oembedler.moon.graphql.engine.relay.PageInfoObjectType; -import graphql.relay.ConnectionCursor; -import graphql.relay.DefaultConnectionCursor; import graphql.schema.DataFetchingEnvironment; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.List; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; /** * @author oEmbedler Inc. */ -public class SimpleListConnection { +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public abstract class SimpleListConnection { private static final String DUMMY_CURSOR_PREFIX = "simple-cursor"; - private final List data; + private final List data; - public SimpleListConnection(List data) { - this.data = data; - } - - public E createEdgeObject() { - return (E) new EdgeObjectType(); - } + public abstract > E createEdgeObject(); - public E createConnectionObject() { - return (E) new ConnectionObjectType(); - } + public abstract , ? extends PageInfoObjectType>> C createConnectionObject(); - private List buildEdges() { - List edges = new ArrayList<>(); + private List> buildEdges() { + List> edges = new ArrayList<>(); int ix = 0; - for (Object object : data) { - EdgeObjectType edge = createEdgeObject(); + for (T object : data) { + EdgeObjectType edge = createEdgeObject(); edge.setNode(object); edge.setCursor(createCursor(ix++)); edges.add(edge); @@ -43,13 +36,13 @@ private List buildEdges() { return edges; } - public C get(DataFetchingEnvironment environment) { + public , ? extends PageInfoObjectType>> C get( + DataFetchingEnvironment environment) { + List> edges = buildEdges(); - List edges = buildEdges(); - - int afterOffset = getOffsetFromCursor(environment.getArgument("after"), -1); + int afterOffset = getOffsetFromCursor(environment.getArgument("after"), -1); int begin = Math.max(afterOffset, -1) + 1; - int beforeOffset = getOffsetFromCursor(environment.getArgument("before"), edges.size()); + int beforeOffset = getOffsetFromCursor(environment.getArgument("before"), edges.size()); int end = Math.min(beforeOffset, edges.size()); edges = edges.subList(begin, end); @@ -74,8 +67,8 @@ public C get(DataFetchingEnvironment environmen return emptyConnection(); } - EdgeObjectType firstEdge = edges.get(0); - EdgeObjectType lastEdge = edges.get(edges.size() - 1); + EdgeObjectType firstEdge = edges.get(0); + EdgeObjectType lastEdge = edges.get(edges.size() - 1); PageInfoObjectType pageInfo = new PageInfoObjectType(); pageInfo.setStartCursor(firstEdge.getCursor()); @@ -83,25 +76,21 @@ public C get(DataFetchingEnvironment environmen pageInfo.setHasPreviousPage(!firstEdge.getCursor().equals(firstPresliceCursor)); pageInfo.setHasNextPage(!lastEdge.getCursor().equals(lastPresliceCursor)); - ConnectionObjectType connection = createConnectionObject(); + ConnectionObjectType, PageInfoObjectType> connection = createConnectionObject(); connection.setEdges(edges); connection.setPageInfo(pageInfo); + //noinspection unchecked return (C) connection; } - private E emptyConnection() { - ConnectionObjectType connection = createConnectionObject(); + private , ? extends PageInfoObjectType>> E emptyConnection() { + ConnectionObjectType, PageInfoObjectType> connection = createConnectionObject(); connection.setPageInfo(new PageInfoObjectType()); + //noinspection unchecked return (E) connection; } - public ConnectionCursor cursorForObjectInConnection(Object object) { - int index = data.indexOf(object); - String cursor = createCursor(index); - return new DefaultConnectionCursor(cursor); - } - private int getOffsetFromCursor(String cursor, int defaultValue) { if (cursor == null) { return defaultValue; diff --git a/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/TodoSimpleListConnection.java b/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/TodoSimpleListConnection.java index d677351d..a25397f8 100644 --- a/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/TodoSimpleListConnection.java +++ b/example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/TodoSimpleListConnection.java @@ -1,27 +1,28 @@ package graphql.kickstart.spring.web.boot.sample; -import com.oembedler.moon.graphql.engine.relay.ConnectionObjectType; -import com.oembedler.moon.graphql.engine.relay.EdgeObjectType; import graphql.kickstart.spring.web.boot.sample.schema.objecttype.TodoObjectType; +import graphql.kickstart.spring.web.boot.sample.schema.objecttype.TodoObjectType.TodoConnectionObjectType; +import graphql.kickstart.spring.web.boot.sample.schema.objecttype.TodoObjectType.TodoEdgeObjectType; import java.util.List; /** * @author oEmbedler Inc. */ -public class TodoSimpleListConnection extends SimpleListConnection { +@SuppressWarnings("unchecked") +public class TodoSimpleListConnection extends SimpleListConnection { - public TodoSimpleListConnection(List data) { + public TodoSimpleListConnection(List data) { super(data); } @Override - public T createEdgeObject() { - return (T) new TodoObjectType.TodoEdgeObjectType(); + public TodoEdgeObjectType createEdgeObject() { + return new TodoObjectType.TodoEdgeObjectType(); } @Override - public T createConnectionObject() { - return (T) new TodoObjectType.TodoConnectionObjectType(); + public TodoConnectionObjectType createConnectionObject() { + return new TodoObjectType.TodoConnectionObjectType(); } } diff --git a/graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/error/ReflectiveGraphQLErrorFactory.java b/graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/error/ReflectiveGraphQLErrorFactory.java index d6875b2b..451c92ff 100644 --- a/graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/error/ReflectiveGraphQLErrorFactory.java +++ b/graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/error/ReflectiveGraphQLErrorFactory.java @@ -36,10 +36,10 @@ public Optional> mostConcrete(Throwable t) { @Override public Collection create(Throwable t, ErrorContext errorContext) { try { - method.setAccessible(true); if (singularReturnType) { return singletonList((GraphQLError) invoke(t, errorContext)); } + //noinspection unchecked return (Collection) invoke(t, errorContext); } catch (IllegalAccessException | InvocationTargetException e) { log.error("Cannot create GraphQLError from throwable {}", t.getClass().getSimpleName(), e); diff --git a/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/spring/web/boot/GraphQLErrorHandlerTest.java b/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/spring/web/boot/GraphQLErrorHandlerTest.java index 62fde233..82ddf106 100644 --- a/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/spring/web/boot/GraphQLErrorHandlerTest.java +++ b/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/spring/web/boot/GraphQLErrorHandlerTest.java @@ -43,8 +43,8 @@ void illegalArgumentExceptionShouldBeHandledConcretely() { TestUtils.assertGraphQLError( gql, "query { illegalArgumentException }", - new ThrowableGraphQLError(new IllegalArgumentException("Illegal argument"), - "Illegal argument"), + new ThrowableGraphQLError(new IllegalArgumentException("Some argument"), + "Custom illegal argument"), objectMapper ); } @@ -70,12 +70,12 @@ boolean illegalStateException() { } @ExceptionHandler(IllegalArgumentException.class) - ThrowableGraphQLError handle(IllegalArgumentException e) { - return new ThrowableGraphQLError(e, "Illegal argument"); + public ThrowableGraphQLError handle(IllegalArgumentException e) { + return new ThrowableGraphQLError(e, "Custom illegal argument"); } @ExceptionHandler(Throwable.class) - GraphQLError handle(Throwable e) { + public GraphQLError handle(Throwable e) { return new ThrowableGraphQLError(e, "Catch all handler"); } diff --git a/graphql-spring-boot-test/build.gradle b/graphql-spring-boot-test/build.gradle index 15ee4785..a3504f4e 100644 --- a/graphql-spring-boot-test/build.gradle +++ b/graphql-spring-boot-test/build.gradle @@ -21,6 +21,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-test") implementation("com.fasterxml.jackson.core:jackson-databind") implementation("com.jayway.jsonpath:json-path") + implementation 'org.awaitility:awaitility:4.0.3' compileOnly("com.graphql-java:graphql-java:$LIB_GRAPHQL_JAVA_VER") compileOnly("com.graphql-java-kickstart:graphql-java-servlet:$LIB_GRAPHQL_SERVLET_VER") testImplementation("org.springframework.boot:spring-boot-starter-web") diff --git a/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java b/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java index fc555ed0..b47c50e3 100644 --- a/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java +++ b/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java @@ -1,6 +1,7 @@ package com.graphql.spring.boot.test; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.fail; import com.fasterxml.jackson.core.JsonProcessingException; @@ -18,6 +19,7 @@ import java.util.Map; import java.util.Optional; import java.util.Queue; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import javax.websocket.ClientEndpointConfig; @@ -49,7 +51,6 @@ public class GraphQLTestSubscription { private static final WebSocketContainer WEB_SOCKET_CONTAINER = ContainerProvider .getWebSocketContainer(); - private static final int SLEEP_INTERVAL_MS = 100; private static final int ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT = 60000; private static final AtomicInteger ID_COUNTER = new AtomicInteger(1); private static final UriBuilderFactory URI_BUILDER_FACTORY = new DefaultUriBuilderFactory(); @@ -115,7 +116,7 @@ public GraphQLTestSubscription init(@Nullable final Object payload) { sendMessage(message); state.setInitialized(true); awaitAcknowledgement(); - log.debug("Subscription successfully initialized."); + log.debug("Subscription successfully initialized"); return this; } @@ -134,12 +135,12 @@ public GraphQLTestSubscription start(@NonNull final String graphQLResource) { /** * Sends the "start" message to the GraphQL Subscription. * - * @param graphGLResource the GraphQL resource, which contains the query for the subscription + * @param graphQLResource the GraphQL resource, which contains the query for the subscription * start payload. * @param variables the variables needed for the query to be evaluated. * @return self reference */ - public GraphQLTestSubscription start(@NonNull final String graphGLResource, + public GraphQLTestSubscription start(@NonNull final String graphQLResource, @Nullable final Object variables) { if (!isInitialized()) { init(); @@ -149,7 +150,7 @@ public GraphQLTestSubscription start(@NonNull final String graphGLResource, } state.setStarted(true); ObjectNode payload = objectMapper.createObjectNode(); - payload.put("query", loadQuery(graphGLResource)); + payload.put("query", loadQuery(graphQLResource)); payload.set("variables", getFinalPayload(variables)); ObjectNode message = objectMapper.createObjectNode(); message.put("type", "start"); @@ -298,18 +299,11 @@ public List awaitAndGetNextResponses( if (isStopped()) { fail("Subscription already stopped. Forgot to call reset after test case?"); } - int elapsedTime = 0; - while ( - ((state.getResponses().size() < numExpectedResponses) || numExpectedResponses <= 0) - && elapsedTime < timeout - ) { - try { - Thread.sleep(SLEEP_INTERVAL_MS); - elapsedTime += SLEEP_INTERVAL_MS; - } catch (InterruptedException e) { - fail("Test execution error - Thread.sleep failed.", e); - } - } + + await() + .atMost(timeout, TimeUnit.MILLISECONDS) + .until(() -> state.getResponses().size() >= numExpectedResponses); + if (stopAfter) { stop(); } @@ -420,29 +414,21 @@ private void sendMessage(final Object message) { } private void awaitAcknowledgement() { - await(GraphQLTestSubscription::isAcknowledged, - "Connection was not acknowledged by the GraphQL server."); + awaitAcknowledgementOrConnection(GraphQLTestSubscription::isAcknowledged, + "Connection was acknowledged by the GraphQL server."); } private void awaitStop() { - await(GraphQLTestSubscription::isStopped, "Connection was not stopped in time."); + awaitAcknowledgementOrConnection(GraphQLTestSubscription::isStopped, + "Connection was stopped in time."); } - private void await(final Predicate condition, + private void awaitAcknowledgementOrConnection(final Predicate condition, final String timeoutDescription) { - int elapsedTime = 0; - while (!condition.test(this) && elapsedTime < ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT) { - try { - Thread.sleep(SLEEP_INTERVAL_MS); - elapsedTime += SLEEP_INTERVAL_MS; - } catch (InterruptedException e) { - fail("Test execution error - Thread.sleep failed.", e); - } - } + await(timeoutDescription) + .atMost(ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS) + .until(() -> condition.test(this)); - if (!condition.test(this)) { - fail("Timeout: " + timeoutDescription); - } } @RequiredArgsConstructor @@ -460,28 +446,35 @@ public void onMessage(final String message) { assertThat(typeNode).as("GraphQL messages should have a type field.").isNotNull(); assertThat(typeNode.isNull()).as("GraphQL messages type should not be null.").isFalse(); final String type = typeNode.asText(); - if (type.equals("complete")) { - state.setCompleted(true); - log.debug("Subscription completed."); - } else if (type.equals("connection_ack")) { - state.setAcknowledged(true); - log.debug("WebSocket connection acknowledged by the GraphQL Server."); - } else if (type.equals("data") || type.equals("error")) { - final JsonNode payload = jsonNode.get(PAYLOAD); - assertThat(payload).as("Data/error messages must have a payload.").isNotNull(); - final String payloadString = objectMapper.writeValueAsString(payload); - final GraphQLResponse graphQLResponse = new GraphQLResponse( - ResponseEntity.ok(payloadString), - objectMapper); - if (state.isStopped() || state.isCompleted()) { - log.debug( - "Response discarded because subscription was stopped or completed in the meanwhile."); - } else { - synchronized (STATE_LOCK) { - state.getResponses().add(graphQLResponse); + switch (type) { + case "complete": + state.setCompleted(true); + log.debug("Subscription completed."); + break; + case "connection_ack": + state.setAcknowledged(true); + log.debug("WebSocket connection acknowledged by the GraphQL Server."); + break; + case "data": + case "error": + final JsonNode payload = jsonNode.get(PAYLOAD); + assertThat(payload).as("Data/error messages must have a payload.").isNotNull(); + final String payloadString = objectMapper.writeValueAsString(payload); + final GraphQLResponse graphQLResponse = new GraphQLResponse( + ResponseEntity.ok(payloadString), + objectMapper); + if (state.isStopped() || state.isCompleted()) { + log.debug( + "Response discarded because subscription was stopped or completed in the meanwhile."); + } else { + synchronized (STATE_LOCK) { + state.getResponses().add(graphQLResponse); + } + log.debug("New response recorded."); } - log.debug("New response recorded."); - } + break; + default: + break; } } catch (JsonProcessingException e) { fail("Exception while parsing server response. Response is not a valid GraphQL response.", diff --git a/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestTemplate.java b/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestTemplate.java index 3eb1d508..50f02844 100644 --- a/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestTemplate.java +++ b/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestTemplate.java @@ -73,17 +73,6 @@ private String loadResource(Resource resource) throws IOException { } } - /** - * @param name Name (key) of HTTP header to add. - * @param value Value of HTTP header to add. - * @deprecated use {{@link #withAdditionalHeader(String, String...)}} instead Add an HTTP header - * that will be sent with each request this sends. - */ - @Deprecated - public void addHeader(final String name, final String value) { - withAdditionalHeader(name, value); - } - /** * Add an HTTP header that will be sent with each request this sends. * @@ -160,16 +149,6 @@ public GraphQLTestTemplate withBasicAuth(@NonNull final String encodedCredential return this; } - /** - * @param newHeaders Headers to use. - * @deprecated use {{@link #withHeaders(HttpHeaders)}} instead. Replace any associated HTTP - * headers with the provided headers. - */ - @Deprecated - public void setHeaders(HttpHeaders newHeaders) { - withHeaders(newHeaders); - } - /** * Replace any associated HTTP headers with the provided headers. * @@ -180,14 +159,6 @@ public GraphQLTestTemplate withHeaders(final HttpHeaders newHeaders) { return withClearHeaders().withAdditionalHeaders(newHeaders); } - /** - * @deprecated use {{@link #withClearHeaders()}} instead Clear all associated HTTP headers. - */ - @Deprecated - public void clearHeaders() { - withClearHeaders(); - } - /** * Clear all associated HTTP headers. * @@ -198,20 +169,6 @@ public GraphQLTestTemplate withClearHeaders() { return this; } - /** - * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL - * server. - * - * @param graphqlResource path to the classpath resource containing the GraphQL query - * @return {@link GraphQLResponse} containing the result of query execution - * @throws IOException if the resource cannot be loaded from the classpath - * @deprecated Use {@link #postForResource(String)} instead - */ - @Deprecated - public GraphQLResponse perform(String graphqlResource) throws IOException { - return postForResource(graphqlResource); - } - /** * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL * server. diff --git a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLSubscriptionTestAwaitNoAnswerTest.java b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLSubscriptionTestAwaitNoAnswerTest.java index b2eafdc2..5959c8c8 100644 --- a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLSubscriptionTestAwaitNoAnswerTest.java +++ b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLSubscriptionTestAwaitNoAnswerTest.java @@ -37,8 +37,8 @@ void shouldAwaitNoResponseSucceedIfNoResponsesArrived( @DisplayName("Should raise assertion error if any response arrived / default stop after.") void shouldRaiseAssertionErrorIfResponseArrivedDefaultStopAfter() { // WHEN - THEN + graphQLTestSubscription.start(TIMER_SUBSCRIPTION_RESOURCE); assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> graphQLTestSubscription - .start(TIMER_SUBSCRIPTION_RESOURCE) .waitAndExpectNoResponse(TIMEOUT)); assertThatSubscriptionWasStopped(); } @@ -50,8 +50,8 @@ void shouldRaiseAssertionErrorIfResponseArrived( final boolean stopAfter ) { // WHEN - THEN + graphQLTestSubscription.start(TIMER_SUBSCRIPTION_RESOURCE); assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> graphQLTestSubscription - .start(TIMER_SUBSCRIPTION_RESOURCE) .waitAndExpectNoResponse(TIMEOUT, stopAfter)); assertThatSubscriptionStoppedStatusIs(stopAfter); } diff --git a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java index d027aaf6..47c50fad 100644 --- a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java +++ b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java @@ -1,7 +1,9 @@ package com.graphql.spring.boot.test; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.awaitility.Awaitility.await; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -12,11 +14,11 @@ class GraphQLTestSubscriptionGetRemainingResponsesTest extends @Test @DisplayName("Should properly return remaining responses after the Subscription was stopped.") - void shouldGetRemainingResponses() throws InterruptedException { + void shouldGetRemainingResponses() { // WHEN graphQLTestSubscription.start(TIMER_SUBSCRIPTION_RESOURCE) .awaitAndGetNextResponse(TIMEOUT, false); - Thread.sleep(TIMEOUT); + await().atMost(TIMEOUT, MILLISECONDS); graphQLTestSubscription.stop(); // THEN assertThatSubscriptionWasStopped(); diff --git a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java index 4273f626..210ff109 100644 --- a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java +++ b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.awaitility.core.ConditionTimeoutException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,24 +12,27 @@ class GraphQLTestSubscriptionUsageErrorHandlingTest extends GraphQLTestSubscript @Test @DisplayName("Should raise an assertion error if init is called after init.") void shouldRaiseAssertionErrorIfInitAfterInit() { + graphQLTestSubscription.init(); assertThatExceptionOfType(AssertionError.class) - .isThrownBy(() -> graphQLTestSubscription.init().init()); + .isThrownBy(() -> graphQLTestSubscription.init()); } @Test @DisplayName("Should raise an assertion error if awaitAndGet times out.") void shouldRaiseAssertionErrorIfAwaitAndGetTimesOut() { - assertThatExceptionOfType(AssertionError.class) + graphQLTestSubscription + .start(SUBSCRIPTION_THAT_TIMES_OUT_RESOURCE); + assertThatExceptionOfType(ConditionTimeoutException.class) .isThrownBy(() -> graphQLTestSubscription - .start(SUBSCRIPTION_THAT_TIMES_OUT_RESOURCE) - .awaitAndGetNextResponse(TIMEOUT)); + .awaitAndGetNextResponse(110)); } @Test @DisplayName("Should raise an assertion error if awaitAndGet methods are called before start.") void shouldRaiseAssertionErrorIfGettingResponseWithoutStart() { + graphQLTestSubscription.init(); assertThatExceptionOfType(AssertionError.class) - .isThrownBy(() -> graphQLTestSubscription.init().awaitAndGetNextResponse(TIMEOUT)); + .isThrownBy(() -> graphQLTestSubscription.awaitAndGetNextResponse(TIMEOUT)); } @Test @@ -41,18 +45,19 @@ void shouldRaiseAssertionErrorIfStopWithoutStart() { @Test @DisplayName("Should raise an assertion error if stop is called after stop.") void shouldRaiseAssertionErrorIfStopAfterStop() { + graphQLTestSubscription.start(TIMER_SUBSCRIPTION_RESOURCE).stop(); assertThatExceptionOfType(AssertionError.class) - .isThrownBy(() -> graphQLTestSubscription.start(TIMER_SUBSCRIPTION_RESOURCE).stop().stop()); + .isThrownBy(() -> graphQLTestSubscription.stop()); } @Test @DisplayName("Should raise an assertion error if awaitAndGet methods are called after stop.") void shouldRaiseAssertionErrorIfGettingResponseAfterStop() { + graphQLTestSubscription + .start(TIMER_SUBSCRIPTION_RESOURCE) + .stop(); assertThatExceptionOfType(AssertionError.class) - .isThrownBy(() -> graphQLTestSubscription - .start(TIMER_SUBSCRIPTION_RESOURCE) - .stop() - .awaitAndGetNextResponse(TIMEOUT)); + .isThrownBy(() -> graphQLTestSubscription.awaitAndGetNextResponse(TIMEOUT)); } @Test diff --git a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestTemplateTest.java b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestTemplateTest.java index 9cbca931..540f0baa 100644 --- a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestTemplateTest.java +++ b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestTemplateTest.java @@ -44,15 +44,6 @@ void setUp() { new ObjectMapper()); } - @Test - void testAddHeader() { - // WHEN - graphQLTestTemplate.addHeader(HEADER_NAME_1, HEADER_VALUE_1); - graphQLTestTemplate.addHeader(HEADER_NAME_2, HEADER_VALUE_2); - // THEN - assertThatContainsAllHeaders(); - } - @Test void testWithAdditionalHeader() { // WHEN @@ -93,19 +84,6 @@ void testWithHeaders() { assertThatContainsSecondHeader(); } - @Test - void testSetHeaders() { - // GIVEN - graphQLTestTemplate.getHeaders().add(HEADER_NAME_1, HEADER_VALUE_1); - final HttpHeaders newHeaders = new HttpHeaders(); - newHeaders.add(HEADER_NAME_2, HEADER_VALUE_2); - // WHEN - graphQLTestTemplate.setHeaders(newHeaders); - // THEN - assertThat(graphQLTestTemplate.getHeaders()).hasSize(1); - assertThatContainsSecondHeader(); - } - @Test void testWithClearHeaders() { // GIVEN @@ -117,16 +95,6 @@ void testWithClearHeaders() { assertThat(graphQLTestTemplate.getHeaders()).isEmpty(); } - @Test - void testClearHeaders() { - // GIVEN - graphQLTestTemplate.getHeaders().add(HEADER_NAME_1, HEADER_VALUE_1); - // WHEN - graphQLTestTemplate.clearHeaders(); - // THEN - assertThat(graphQLTestTemplate.getHeaders()).isEmpty(); - } - @Test void testWithBearerAuth() { // WHEN