Search in sources :

Example 1 with SubscriptionTestParam

use of org.allGraphQLCases.client.SubscriptionTestParam in project graphql-maven-plugin-project by graphql-java-generator.

the class ExecSubscriptionIT method test_subscribeToADate_clientComplete.

/**
 * Tests that the graphql-transport-ws 'complete' message is properly propagated from the client to the server, if
 * it occurs
 *
 * @throws GraphQLRequestPreparationException
 * @throws GraphQLRequestExecutionException
 * @throws InterruptedException
 */
@Test
@Execution(ExecutionMode.CONCURRENT)
public void test_subscribeToADate_clientComplete() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException, InterruptedException {
    logger.info("------------------------------------------------------------------------------------------------");
    logger.info("Starting test_subscribeToADate_clientComplete");
    SubscriptionTestParam param = getSubscriptionTestParam();
    SubscriptionCallbackString callback = new SubscriptionCallbackString("test_subscribeToADate_clientComplete");
    SubscriptionClient sub = subscriptionExecutor.subscriptionTest("", callback, param);
    // Let's wait a max of 20 second, until we receive some notifications
    // (20s will never occur... unless using the debugger to undebug some stuff)
    boolean success = callback.latchForMessageReception.await(20, TimeUnit.SECONDS);
    // Let's wait for our first message
    logger.debug("latchForMessageReception has been freed for client with status {}", success);
    assertNotNull(callback.lastReceivedMessage, "we must have received a message");
    // Let's unsubscribe from this subscription
    sub.unsubscribe();
    // Now, we wait for 1s to be sure that the server has executed this unsubscription
    Thread.sleep(1000);
    callback.lastReceivedMessage = null;
    // /////////////// Now, we wait another second: no message should be sent by the server
    Thread.sleep(1000);
    assertNull(callback.lastReceivedMessage, "no more message should be sent by the server");
}
Also used : SubscriptionTestParam(org.allGraphQLCases.client.SubscriptionTestParam) SubscriptionClient(com.graphql_java_generator.client.SubscriptionClient) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SubscriptionTestParam

use of org.allGraphQLCases.client.SubscriptionTestParam in project graphql-maven-plugin-project by graphql-java-generator.

the class ExecSubscriptionIT method test_subscribeToADate_subscriptionError.

/**
 * Tests that an error in the subscription is properly sent back to the client, when it occurs during the
 * subscription
 *
 * @throws GraphQLRequestPreparationException
 * @throws GraphQLRequestExecutionException
 * @throws InterruptedException
 */
@Test
@Execution(ExecutionMode.CONCURRENT)
public void test_subscribeToADate_subscriptionError() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException, InterruptedException {
    logger.info("------------------------------------------------------------------------------------------------");
    logger.info("Starting test_subscribeToADate_subscriptionError");
    SubscriptionTestParam param = getSubscriptionTestParam();
    param.setErrorOnSubscription(true);
    SubscriptionCallbackString callback = new SubscriptionCallbackString("test_subscribeToADate_subscriptionError");
    SubscriptionClient sub = subscriptionExecutor.subscriptionTest("", callback, param);
    // Let's wait a max of 20 second, until we receive an exception
    // (20s will never occur... unless using the debugger to undebug some stuff)
    callback.latchForErrorReception.await(20, TimeUnit.SECONDS);
    // Let's test this exception
    assertNotNull(callback.lastExceptionReceived, "we should have received an exception");
    assertTrue(callback.lastExceptionReceived.getMessage().endsWith("Oups, the subscriber asked for an error during the subscription"), "The received error message is: " + callback.lastExceptionReceived.getMessage());
    // Let's unsubscribe from this subscription
    sub.unsubscribe();
}
Also used : SubscriptionTestParam(org.allGraphQLCases.client.SubscriptionTestParam) SubscriptionClient(com.graphql_java_generator.client.SubscriptionClient) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with SubscriptionTestParam

use of org.allGraphQLCases.client.SubscriptionTestParam in project graphql-maven-plugin-project by graphql-java-generator.

the class ExecSubscriptionIT method test_subscribeToADate_serverComplete.

/**
 * Tests that the graphql-transport-ws 'complete' message is properly propagated from the server to the client, if
 * it occurs
 *
 * @throws GraphQLRequestPreparationException
 * @throws GraphQLRequestExecutionException
 * @throws InterruptedException
 */
@Test
@Execution(ExecutionMode.CONCURRENT)
public void test_subscribeToADate_serverComplete() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException, InterruptedException {
    logger.info("------------------------------------------------------------------------------------------------");
    logger.info("Starting test_subscribeToADate_serverComplete");
    SubscriptionTestParam param = getSubscriptionTestParam();
    param.setCompleteAfterFirstNotification(true);
    SubscriptionCallbackString callback = new SubscriptionCallbackString("test_subscribeToADate_serverComplete");
    subscriptionExecutor.subscriptionTest("", callback, param);
    // Let's wait a max of 20 second, until we receive some notifications
    // (20s will never occur... unless using the debugger to undebug some stuff)
    callback.latchForMessageReception.await(20, TimeUnit.SECONDS);
    // Let's wait for our first message
    assertNotNull(callback.lastReceivedMessage, "we must have received a message");
    // Then we wait for the subscription completion, which should be sent by the server
    callback.latchForCompleteReception.await(20, TimeUnit.SECONDS);
    // The subscription should be closed
    assertTrue(callback.closedHasBeenReceived, "The subscription should have received a 'complete' message from the server");
}
Also used : SubscriptionTestParam(org.allGraphQLCases.client.SubscriptionTestParam) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SubscriptionTestParam

use of org.allGraphQLCases.client.SubscriptionTestParam in project graphql-maven-plugin-project by graphql-java-generator.

the class ExecSubscriptionIT method test_subscribeToADate_nextError.

/**
 * Tests that an error in the subscription is properly sent back to the client, when it occurs after the
 * subscription is active (typically when notifications are coming).
 *
 * @throws GraphQLRequestPreparationException
 * @throws GraphQLRequestExecutionException
 * @throws InterruptedException
 */
@Test
@Execution(ExecutionMode.CONCURRENT)
public void test_subscribeToADate_nextError() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException, InterruptedException {
    logger.info("------------------------------------------------------------------------------------------------");
    logger.info("Starting test_subscribeToADate_nextError");
    SubscriptionTestParam param = getSubscriptionTestParam();
    param.setErrorOnNext(true);
    SubscriptionCallbackString callback = new SubscriptionCallbackString("test_subscribeToADate_nextError");
    SubscriptionClient sub = subscriptionExecutor.subscriptionTest("", callback, param);
    // Let's wait a max of 20 second, until we receive an exception
    // (20s will never occur... unless using the debugger to undebug some stuff)
    callback.latchForErrorReception.await(20, TimeUnit.SECONDS);
    // Let's test this exception
    assertNotNull(callback.lastExceptionReceived, "we must have received an exception");
    assertTrue(callback.lastExceptionReceived.getMessage().endsWith("Oups, the subscriber asked for an error for each next message"), "The received error message is: " + callback.lastExceptionReceived.getMessage());
    // Let's unsubscribe from this subscription
    sub.unsubscribe();
}
Also used : SubscriptionTestParam(org.allGraphQLCases.client.SubscriptionTestParam) SubscriptionClient(com.graphql_java_generator.client.SubscriptionClient) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with SubscriptionTestParam

use of org.allGraphQLCases.client.SubscriptionTestParam in project graphql-maven-plugin-project by graphql-java-generator.

the class ExecSubscriptionIT method getSubscriptionTestParam.

private SubscriptionTestParam getSubscriptionTestParam() {
    SubscriptionTestParam param = new SubscriptionTestParam();
    param.setCloseWebSocketBeforeFirstNotification(false);
    param.setCompleteAfterFirstNotification(false);
    param.setErrorOnNext(false);
    param.setErrorOnSubscription(false);
    return param;
}
Also used : SubscriptionTestParam(org.allGraphQLCases.client.SubscriptionTestParam)

Aggregations

SubscriptionTestParam (org.allGraphQLCases.client.SubscriptionTestParam)6 Test (org.junit.jupiter.api.Test)5 Execution (org.junit.jupiter.api.parallel.Execution)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 SubscriptionClient (com.graphql_java_generator.client.SubscriptionClient)4