Package com.graphql.spring.boot.test
Class GraphQLTestSubscription
java.lang.Object
com.graphql.spring.boot.test.GraphQLTestSubscription
Helper object to test GraphQL subscriptions.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionawaitAndGetAllResponses
(int timeToWait) Deprecated.since 12.0.0.awaitAndGetAllResponses
(int timeToWait, boolean stopAfter) Deprecated.since 12.0.0.awaitAndGetAllResponses
(Duration timeToWait) Waits a specified amount time and returns all responses received during that time.awaitAndGetAllResponses
(Duration timeToWait, boolean stopAfter) Waits a specified amount time and returns all responses received during that time.awaitAndGetNextResponse
(int timeout) Deprecated.since 12.0.0.awaitAndGetNextResponse
(int timeout, boolean stopAfter) Deprecated.since 12.0.0.awaitAndGetNextResponse
(Duration timeout) Awaits and returns the next response received from the subscription.awaitAndGetNextResponse
(Duration timeout, boolean stopAfter) Awaits and returns the next response received from the subscription.awaitAndGetNextResponses
(int timeout, int numExpectedResponses) Deprecated.since 12.0.0.awaitAndGetNextResponses
(int timeout, int numExpectedResponses, boolean stopAfter) Deprecated.since 12.0.0.awaitAndGetNextResponses
(Duration timeout, int numExpectedResponses) Awaits and returns the specified number of responses.awaitAndGetNextResponses
(Duration timeout, int numExpectedResponses, boolean stopAfter) Awaits and returns the specified number of responses.Returns the remaining responses that were not returned so far.init()
Sends the "connection_init" message to the GraphQL server without a payload.Sends the "connection_init" message to the GraphQL server.boolean
boolean
boolean
boolean
boolean
void
reset()
Stops (if needed) and resets this instance.Sends the "start" message to the GraphQL server.Sends the "start" message to the GraphQL Subscription.stop()
Sends the "stop" message to the server.waitAndExpectNoResponse
(int timeToWait) Deprecated.since 12.0.0.waitAndExpectNoResponse
(int timeToWait, boolean stopAfter) Deprecated.since 12.0.0.waitAndExpectNoResponse
(Duration timeToWait) Waits a specified amount of time and asserts that no responses were received during that time.waitAndExpectNoResponse
(Duration timeToWait, boolean stopAfter) Waits a specified amount of time and asserts that no responses were received during that time.
-
Field Details
-
PAYLOAD
- See Also:
-
-
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
Sends the "connection_init" message to the GraphQL server without a payload.- Returns:
- self reference
-
init
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
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
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.since 12.0.0. UseawaitAndGetNextResponse(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
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.since 12.0.0. UseawaitAndGetNextResponse(Duration,boolean)
instead.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
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.since 12.0.0. UseawaitAndGetAllResponses(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
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.since 12.0.0. UseawaitAndGetAllResponses(Duration,boolean)
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.- Parameters:
timeToWait
- the time to wait, in millisecondsstopAfter
- if true, the subscription will be stopped after the time elapsed.- Returns:
- the list of responses received during that time.
- See Also:
-
awaitAndGetAllResponses
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 waitstopAfter
- 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. UseawaitAndGetNextResponses(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
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.since 12.0.0. UseawaitAndGetNextResponses(Duration,int,boolean)
instead.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.since 12.0.0. UsewaitAndExpectNoResponse(Duration,boolean)
instead.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
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.since 12.0.0. UsewaitAndExpectNoResponse(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
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
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.
-