Class GraphQLTestSubscription

java.lang.Object
com.graphql.spring.boot.test.GraphQLTestSubscription

public class GraphQLTestSubscription extends Object
Helper object to test GraphQL subscriptions.
  • Field Details

  • Constructor Details

    • GraphQLTestSubscription

      public GraphQLTestSubscription()
  • Method Details

    • isInitialized

      public boolean isInitialized()
    • isAcknowledged

      public boolean isAcknowledged()
    • isStarted

      public boolean isStarted()
    • isStopped

      public boolean isStopped()
    • isCompleted

      public boolean isCompleted()
    • init

      public GraphQLTestSubscription init()
      Sends the "connection_init" message to the GraphQL server without a payload.
      Returns:
      self reference
    • init

      public GraphQLTestSubscription init(@Nullable Object payload)
      Sends the "connection_init" message to the GraphQL server.
      Parameters:
      payload - The payload of the connection_init message. May be null, if not needed.
      Returns:
      self reference
    • start

      public GraphQLTestSubscription start(@NonNull @NonNull String graphQLResource)
      Sends the "start" message to the GraphQL server.
      Parameters:
      graphQLResource - the GraphQL resource, which contains the query for the subscription start payload. The start message will be sent without variables.
      Returns:
      self reference
    • start

      public GraphQLTestSubscription start(@NonNull @NonNull String graphQLResource, @Nullable Object variables)
      Sends the "start" message to the GraphQL Subscription.
      Parameters:
      graphQLResource - the GraphQL resource, which contains the query for the subscription start payload.
      variables - the variables needed for the query to be evaluated.
      Returns:
      self reference
    • stop

      public GraphQLTestSubscription stop()
      Sends the "stop" message to the server.
      Returns:
      self reference
    • reset

      public void reset()
      Stops (if needed) and resets this instance. This should be called in the "afterEach" method of the test class, to ensure that the bean is reusable between tests.
    • awaitAndGetNextResponse

      @Deprecated public GraphQLResponse awaitAndGetNextResponse(int timeout)
      Deprecated.
      since 12.0.0. Use awaitAndGetNextResponse(Duration) instead.
      Awaits and returns the next response received from the subscription. The subscription will be stopped after receiving the message (or timeout).
      Parameters:
      timeout - timeout in milliseconds. Test will fail if no message received from the subscription until the timeout expires.
      Returns:
      The received response.
      See Also:
    • awaitAndGetNextResponse

      public GraphQLResponse awaitAndGetNextResponse(Duration timeout)
      Awaits and returns the next response received from the subscription. The subscription will be stopped after receiving the message (or timeout).
      Parameters:
      timeout - Timeout duration. Test will fail if no message received from the subscription until the timeout expires.
      Returns:
      The received response.
    • awaitAndGetNextResponse

      @Deprecated public GraphQLResponse awaitAndGetNextResponse(int timeout, boolean stopAfter)
      Deprecated.
      Awaits and returns the next response received from the subscription.
      Parameters:
      timeout - timeout in milliseconds. Test will fail if no message received from the subscription until the timeout expires.
      stopAfter - if true, the subscription will be stopped after the message was received (or timeout).
      Returns:
      The received response.
      See Also:
    • awaitAndGetNextResponse

      public GraphQLResponse awaitAndGetNextResponse(Duration timeout, boolean stopAfter)
      Awaits and returns the next response received from the subscription.
      Parameters:
      timeout - Timeout duration. Test will fail if no message received from the subscription until the timeout expires.
      stopAfter - if true, the subscription will be stopped after the message was received (or timeout).
      Returns:
      The received response.
    • awaitAndGetAllResponses

      @Deprecated public List<GraphQLResponse> awaitAndGetAllResponses(int timeToWait)
      Deprecated.
      since 12.0.0. Use awaitAndGetAllResponses(Duration) instead.
      Waits a specified amount time and returns all responses received during that time. This method does not have any expectation regarding the number of messages. The subscription will be stopped after the time elapsed.
      Parameters:
      timeToWait - the time to wait, in milliseconds
      Returns:
      the list of responses received during that time.
      See Also:
    • awaitAndGetAllResponses

      public List<GraphQLResponse> awaitAndGetAllResponses(Duration timeToWait)
      Waits a specified amount time and returns all responses received during that time. This method does not have any expectation regarding the number of messages. The subscription will be stopped after the time elapsed.
      Parameters:
      timeToWait - the time to wait.
      Returns:
      the list of responses received during that time.
    • awaitAndGetAllResponses

      @Deprecated public List<GraphQLResponse> awaitAndGetAllResponses(int timeToWait, boolean stopAfter)
      Deprecated.
      Waits a specified amount time and returns all responses received during that time. This method does not have any expectation regarding the number of messages.
      Parameters:
      timeToWait - the time to wait, in milliseconds
      stopAfter - if true, the subscription will be stopped after the time elapsed.
      Returns:
      the list of responses received during that time.
      See Also:
    • awaitAndGetAllResponses

      public List<GraphQLResponse> awaitAndGetAllResponses(Duration timeToWait, boolean stopAfter)
      Waits a specified amount time and returns all responses received during that time. This method does not have any expectation regarding the number of messages.
      Parameters:
      timeToWait - the time to wait
      stopAfter - if true, the subscription will be stopped after the time elapsed.
      Returns:
      the list of responses received during that time.
    • awaitAndGetNextResponses

      @Deprecated public List<GraphQLResponse> awaitAndGetNextResponses(int timeout, int numExpectedResponses)
      Deprecated.
      since 12.0.0. Use awaitAndGetNextResponses(Duration,int) instead.
      Awaits and returns the specified number of responses. The subscription will be stopped after receiving the messages (or timeout).
      Parameters:
      timeout - timeout in milliseconds. Test will fail if the expected number of responses is not received.
      numExpectedResponses - the number of expected responses. If negative, the method will wait the timeout and return all responses received during that time. In this case, no assertion is made regarding the number of responses, and the returned list may be empty. If zero, it is expected that no responses are sent during the timeout period.
      Returns:
      The list containing the expected number of responses. The list contains the responses in the order they were received. If more responses are received than minimally expected, getRemainingResponses() can be used to retrieved them.
      See Also:
    • awaitAndGetNextResponses

      public List<GraphQLResponse> awaitAndGetNextResponses(Duration timeout, int numExpectedResponses)
      Awaits and returns the specified number of responses. The subscription will be stopped after receiving the messages (or timeout).
      Parameters:
      timeout - timeout duration. Test will fail if the expected number of responses is not received.
      numExpectedResponses - the number of expected responses. If negative, the method will wait the timeout and return all responses received during that time. In this case, no assertion is made regarding the number of responses, and the returned list may be empty. If zero, it is expected that no responses are sent during the timeout period.
      Returns:
      The list containing the expected number of responses. The list contains the responses in the order they were received. If more responses are received than minimally expected, getRemainingResponses() can be used to retrieved them.
    • awaitAndGetNextResponses

      @Deprecated public List<GraphQLResponse> awaitAndGetNextResponses(int timeout, int numExpectedResponses, boolean stopAfter)
      Deprecated.
      Awaits and returns the specified number of responses.
      Parameters:
      timeout - timeout in milliseconds. Test will fail if the expected number of responses is not received.
      numExpectedResponses - the number of expected responses. If negative, the method will wait the timeout and return all responses received during that time. In this case, no assertion is made regarding the number of responses, and the returned list may be empty. If zero, it is expected that no responses are sent during the timeout period.
      stopAfter - if true, the subscription will be stopped after the messages were received (or timeout).
      Returns:
      The list containing the expected number of responses. The list contains the responses in the order they were received. If more responses are received than minimally expected, getRemainingResponses() can be used to retrieved them.
      See Also:
    • awaitAndGetNextResponses

      public List<GraphQLResponse> awaitAndGetNextResponses(Duration timeout, int numExpectedResponses, boolean stopAfter)
      Awaits and returns the specified number of responses.
      Parameters:
      timeout - timeout duration. Test will fail if the expected number of responses is not received.
      numExpectedResponses - the number of expected responses. If negative, the method will wait the timeout and return all responses received during that time. In this case, no assertion is made regarding the number of responses, and the returned list may be empty. If zero, it is expected that no responses are sent during the timeout period.
      stopAfter - if true, the subscription will be stopped after the messages were received (or timeout).
      Returns:
      The list containing the expected number of responses. The list contains the responses in the order they were received. If more responses are received than minimally expected, getRemainingResponses() can be used to retrieved them.
    • waitAndExpectNoResponse

      @Deprecated public GraphQLTestSubscription waitAndExpectNoResponse(int timeToWait, boolean stopAfter)
      Deprecated.
      Waits a specified amount of time and asserts that no responses were received during that time.
      Parameters:
      timeToWait - time to wait, in milliseconds.
      stopAfter - if true, the subscription will be stopped afterwards.
      See Also:
    • waitAndExpectNoResponse

      public GraphQLTestSubscription waitAndExpectNoResponse(Duration timeToWait, boolean stopAfter)
      Waits a specified amount of time and asserts that no responses were received during that time.
      Parameters:
      timeToWait - time to wait.
      stopAfter - if true, the subscription will be stopped afterwards.
    • waitAndExpectNoResponse

      @Deprecated public GraphQLTestSubscription waitAndExpectNoResponse(int timeToWait)
      Deprecated.
      since 12.0.0. Use waitAndExpectNoResponse(Duration) instead.
      Waits a specified amount of time and asserts that no responses were received during that time. The subscription will be stopped afterwards.
      Parameters:
      timeToWait - time to wait, in milliseconds.
      See Also:
    • waitAndExpectNoResponse

      public GraphQLTestSubscription waitAndExpectNoResponse(Duration timeToWait)
      Waits a specified amount of time and asserts that no responses were received during that time. The subscription will be stopped afterwards.
      Parameters:
      timeToWait - time to wait.
    • getRemainingResponses

      public List<GraphQLResponse> getRemainingResponses()
      Returns the remaining responses that were not returned so far. This method should only be called after the subscription was stopped.
      Returns:
      the remaining responses.