Search in sources :

Example 1 with HumanInput

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

the class AbstractGraphQLRepositoryInvocationHandlerTest method testInvoke_partialRequest_mutation_withRequestName.

@SuppressWarnings("unchecked")
@Test
void testInvoke_partialRequest_mutation_withRequestName() throws NoSuchMethodException, SecurityException, GraphQLRequestExecutionException {
    // Preparation
    HumanInput input = new HumanInput();
    Human h = Human.builder().withId("1").withHomePlanet("home planet").withName(" a name ").build();
    doReturn(h).when(spyMutationExecutor).createHumanWithBindValues(any(ObjectResponse.class), any(HumanInput.class), any(Map.class));
    // Go, go, go
    Character verif = graphQLRepository.thisIsAMutation(input);
    // Verification
    assertEquals(h, verif);
    assertEquals("{id name}", GraphQLRepositoryTestHelper.getRegisteredGraphQLRequest(invocationHandler, GraphQLRepositoryTestCase.class, "thisIsAMutation", HumanInput.class));
}
Also used : Human(com.graphql_java_generator.domain.client.allGraphQLCases.Human) Character(com.graphql_java_generator.domain.client.allGraphQLCases.Character) HumanInput(com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput) ObjectResponse(com.graphql_java_generator.client.request.ObjectResponse) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with HumanInput

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

the class AbstractGraphQLRequest_fragmentTest method setup.

@BeforeEach
void setup() {
    // Default configuration for GraphQLRequest
    GraphQLRequest.setStaticConfiguration(new GraphQLConfiguration("http://localhost"));
    // A useful init for some tests
    input = new HumanInput();
    input.setName("a new name");
    List<Episode> episodes = new ArrayList<>();
    episodes.add(Episode.JEDI);
    episodes.add(Episode.EMPIRE);
    episodes.add(Episode.NEWHOPE);
    input.setAppearsIn(episodes);
    params.put("humanInput", input);
    params.put("value", "the mutation value");
    params.put("anotherValue", "the other mutation value");
    params.put("uppercaseFalse", false);
    params.put("uppercaseTrue", true);
}
Also used : Episode(com.graphql_java_generator.domain.client.allGraphQLCases.Episode) HumanInput(com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput) ArrayList(java.util.ArrayList) GraphQLConfiguration(com.graphql_java_generator.client.GraphQLConfiguration) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with HumanInput

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

the class AbstractGraphQLRequest_allGraphQLCasesTest method setup.

@BeforeEach
void setup() {
    input = new HumanInput();
    input.setName("a new name");
    List<Episode> episodes = new ArrayList<>();
    episodes.add(Episode.JEDI);
    episodes.add(Episode.EMPIRE);
    episodes.add(Episode.NEWHOPE);
    input.setAppearsIn(episodes);
    params.put("humanInput", input);
    params.put("value", "the mutation value");
    params.put("anotherValue", "the other mutation value");
}
Also used : Episode(com.graphql_java_generator.domain.client.allGraphQLCases.Episode) HumanInput(com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput) ArrayList(java.util.ArrayList) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with HumanInput

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

the class AbstractGraphQLRepositoryInvocationHandlerTest method testInvoke_partialRequest_mutation_withoutRequestName.

@SuppressWarnings("unchecked")
@Test
void testInvoke_partialRequest_mutation_withoutRequestName() throws NoSuchMethodException, SecurityException, GraphQLRequestExecutionException {
    // Preparation
    HumanInput input = new HumanInput();
    Human h = Human.builder().withId("1").withHomePlanet("home planet").withName(" a name ").build();
    doReturn(h).when(spyMutationExecutor).createHumanWithBindValues(any(ObjectResponse.class), any(HumanInput.class), any(Map.class));
    // Go, go, go
    Character verif = graphQLRepository.createHuman(input);
    // Verification
    assertEquals(h, verif);
    assertEquals("{id}", GraphQLRepositoryTestHelper.getRegisteredGraphQLRequest(invocationHandler, GraphQLRepositoryTestCase.class, "createHuman", HumanInput.class));
}
Also used : Human(com.graphql_java_generator.domain.client.allGraphQLCases.Human) Character(com.graphql_java_generator.domain.client.allGraphQLCases.Character) HumanInput(com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput) ObjectResponse(com.graphql_java_generator.client.request.ObjectResponse) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with HumanInput

use of com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput 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

HumanInput (com.graphql_java_generator.domain.client.allGraphQLCases.HumanInput)6 ObjectResponse (com.graphql_java_generator.client.request.ObjectResponse)3 Episode (com.graphql_java_generator.domain.client.allGraphQLCases.Episode)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Test (org.junit.jupiter.api.Test)3 Character (com.graphql_java_generator.domain.client.allGraphQLCases.Character)2 Human (com.graphql_java_generator.domain.client.allGraphQLCases.Human)2 GraphQLConfiguration (com.graphql_java_generator.client.GraphQLConfiguration)1 AnotherMutationType (com.graphql_java_generator.domain.client.allGraphQLCases.AnotherMutationType)1 AnotherMutationTypeResponse (com.graphql_java_generator.domain.client.allGraphQLCases.AnotherMutationTypeResponse)1