Search in sources :

Example 1 with SubscriptionClientReactiveImpl

use of com.graphql_java_generator.client.SubscriptionClientReactiveImpl in project graphql-maven-plugin-project by graphql-java-generator.

the class AbstractGraphQLRepositoryInvocationHandlerTest method testInvoke_fullRequest_subscription.

@SuppressWarnings("unchecked")
@Test
@Disabled
void testInvoke_fullRequest_subscription() throws GraphQLRequestExecutionException, NoSuchMethodException, SecurityException {
    // Preparation
    Date date = new Calendar.Builder().setDate(2021, 6 - 1, 18).build().getTime();
    // This would be invalid in real use. Null is just for this test
    SubscriptionCallback<Date> callback = null;
    SubscriptionClient client = new SubscriptionClientReactiveImpl(null, null);
    doReturn(client).when(spySubscriptionExecutor).execWithBindValues(any(ObjectResponse.class), any(SubscriptionCallback.class), any(Map.class));
    // Go, go, go
    graphQLRepository.fullSubscription(callback, date);
    // Verification
    assertNotNull(client);
    ArgumentCaptor<Map<String, Object>> bindParamsCaptor = ArgumentCaptor.forClass(Map.class);
    verify(spySubscriptionExecutor).execWithBindValues(any(ObjectResponse.class), any(SubscriptionCallback.class), bindParamsCaptor.capture());
    List<Map<String, Object>> params = bindParamsCaptor.getAllValues();
    assertEquals(1, params.size(), "one invocation");
    assertEquals(1, params.get(0).keySet().size(), "one parameter");
    // 
    assertTrue(params.get(0).keySet().contains("date"));
    // Mockito changes the List<Object[]> objects to a List<String> at runtime:
    assertEquals(date, params.get(0).get("date"));
    assertEquals("subscription {issue53(date: &date) {}}", GraphQLRepositoryTestHelper.getRegisteredGraphQLRequest(invocationHandler, GraphQLRepositoryTestCase.class, "fullSubscription", SubscriptionCallback.class, Date.class));
}
Also used : SubscriptionClientReactiveImpl(com.graphql_java_generator.client.SubscriptionClientReactiveImpl) Calendar(java.util.Calendar) SubscriptionClient(com.graphql_java_generator.client.SubscriptionClient) SubscriptionCallback(com.graphql_java_generator.client.SubscriptionCallback) ObjectResponse(com.graphql_java_generator.client.request.ObjectResponse) Map(java.util.Map) Date(java.util.Date) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with SubscriptionClientReactiveImpl

use of com.graphql_java_generator.client.SubscriptionClientReactiveImpl in project graphql-maven-plugin-project by graphql-java-generator.

the class AbstractGraphQLRepositoryInvocationHandlerTest method testInvoke_partialRequest_subscription.

@SuppressWarnings("unchecked")
@Test
void testInvoke_partialRequest_subscription() throws GraphQLRequestExecutionException, NoSuchMethodException, SecurityException {
    // Preparation
    SubscriptionCallback<Human> callback = new SubscriptionCallback<Human>() {

        @Override
        public void onConnect() {
        }

        @Override
        public void onMessage(Human t) {
        }

        @Override
        public void onClose(int statusCode, String reason) {
        }

        @Override
        public void onError(Throwable cause) {
        }
    };
    Episode episode = Episode.JEDI;
    SubscriptionClient subscriptionClient = new SubscriptionClientReactiveImpl(null, null);
    doReturn(subscriptionClient).when(spySubscriptionExecutor).subscribeNewHumanForEpisodeWithBindValues(any(ObjectResponse.class), any(SubscriptionCallback.class), any(Episode.class), any(Map.class));
    // Go, go, go
    SubscriptionClient verif = graphQLRepository.subscribeNewHumanForEpisode(callback, episode);
    // Verification
    assertEquals(subscriptionClient, verif);
    assertEquals("{ id   appearsIn }", GraphQLRepositoryTestHelper.getRegisteredGraphQLRequest(invocationHandler, GraphQLRepositoryTestCase.class, "subscribeNewHumanForEpisode", SubscriptionCallback.class, Episode.class));
}
Also used : Human(com.graphql_java_generator.domain.client.allGraphQLCases.Human) Episode(com.graphql_java_generator.domain.client.allGraphQLCases.Episode) SubscriptionClientReactiveImpl(com.graphql_java_generator.client.SubscriptionClientReactiveImpl) SubscriptionClient(com.graphql_java_generator.client.SubscriptionClient) SubscriptionCallback(com.graphql_java_generator.client.SubscriptionCallback) ObjectResponse(com.graphql_java_generator.client.request.ObjectResponse) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

SubscriptionCallback (com.graphql_java_generator.client.SubscriptionCallback)2 SubscriptionClient (com.graphql_java_generator.client.SubscriptionClient)2 SubscriptionClientReactiveImpl (com.graphql_java_generator.client.SubscriptionClientReactiveImpl)2 ObjectResponse (com.graphql_java_generator.client.request.ObjectResponse)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 Episode (com.graphql_java_generator.domain.client.allGraphQLCases.Episode)1 Human (com.graphql_java_generator.domain.client.allGraphQLCases.Human)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Disabled (org.junit.jupiter.api.Disabled)1