Search in sources :

Example 1 with AnotherMutationTypeResponse

use of com.graphql_java_generator.domain.client.allGraphQLCases.AnotherMutationTypeResponse in project graphql-maven-plugin-project by graphql-java-generator.

the class AbstractGraphQLRepositoryInvocationHandlerTest method testInvoke_fullRequest_mutation.

@SuppressWarnings("unchecked")
@Test
void testInvoke_fullRequest_mutation() throws GraphQLRequestExecutionException, NoSuchMethodException, SecurityException {
    // Preparation
    AnotherMutationTypeResponse mutation = new AnotherMutationTypeResponse();
    HumanInput input = HumanInput.builder().withName("the name").withAppearsIn(Arrays.asList(Episode.JEDI, Episode.NEWHOPE)).build();
    doReturn(mutation).when(spyMutationExecutor).execWithBindValues(any(ObjectResponse.class), any(Map.class));
    // Go, go, go
    AnotherMutationType verif = graphQLRepository.fullRequestMutation(input);
    // Verification
    assertEquals(mutation, verif);
    ArgumentCaptor<Map<String, Object>> bindParamsCaptor = ArgumentCaptor.forClass(Map.class);
    verify(spyMutationExecutor).execWithBindValues(any(ObjectResponse.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("input"));
    // Mockito changes the List<Object[]> objects to a List<String> at runtime:
    assertEquals(input, params.get(0).get("input"));
    assertEquals("mutation($input: HumanInput!) {createHuman(human: $input) {id name }}", GraphQLRepositoryTestHelper.getRegisteredGraphQLRequest(invocationHandler, GraphQLRepositoryTestCase.class, "fullRequestMutation", HumanInput.class));
}
Also used : HumanInput(com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput) AnotherMutationType(com.graphql_java_generator.domain.client.allGraphQLCases.AnotherMutationType) AnotherMutationTypeResponse(com.graphql_java_generator.domain.client.allGraphQLCases.AnotherMutationTypeResponse) ObjectResponse(com.graphql_java_generator.client.request.ObjectResponse) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectResponse (com.graphql_java_generator.client.request.ObjectResponse)1 AnotherMutationType (com.graphql_java_generator.domain.client.allGraphQLCases.AnotherMutationType)1 AnotherMutationTypeResponse (com.graphql_java_generator.domain.client.allGraphQLCases.AnotherMutationTypeResponse)1 HumanInput (com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1