Search in sources :

Example 1 with AllFieldCases

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

the class GraphQLObjectMapperTest method testListOneString.

@Test
void testListOneString() throws JsonMappingException, JsonProcessingException, NoSuchFieldException {
    // Preparation
    GraphQLObjectMapper objectMapper = new GraphQLObjectMapper(AllFieldCases.class.getPackage().getName(), getAliasFields(AllFieldCases.class, "commentsAlias", "comments"));
    // Go, go, go
    AllFieldCases test = objectMapper.readValue("{\"commentsAlias\":[\"my str\"], \"__typename\":\"AllFieldCases\"}", AllFieldCases.class);
    // Verification
    assertEquals(1, test.aliasValues.keySet().size());
    assertTrue(test.aliasValues.get("commentsAlias") instanceof List);
    assertEquals(1, ((List<?>) test.aliasValues.get("commentsAlias")).size());
    assertTrue(((List<?>) test.aliasValues.get("commentsAlias")).get(0) instanceof String);
    assertEquals("my str", ((List<?>) test.aliasValues.get("commentsAlias")).get(0));
}
Also used : AllFieldCases(com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCases) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 2 with AllFieldCases

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

the class GraphQLObjectMapperTest method testObject.

@Test
void testObject() throws JsonMappingException, JsonProcessingException, NoSuchFieldException {
    // Preparation
    GraphQLObjectMapper objectMapper = new GraphQLObjectMapper(AllFieldCases.class.getPackage().getName(), getAliasFields(AllFieldCases.class, "oneWithIdSubTypeAlias", "oneWithIdSubType"));
    // Go, go, go
    AllFieldCases test = objectMapper.readValue(// 
    "" + // 
    "{" + // 
    "  \"forname\":\"the root str value\", " + "  \"oneWithIdSubTypeAlias\": {\"name\":\"the alias's str value\", \"__typename\":\"AllFieldCasesWithIdSubtype\"}," + // 
    "  \"__typename\":\"AllFieldCases\" " + "}", AllFieldCases.class);
    // Verification
    assertEquals("the root str value", test.getForname());
    assertEquals(1, test.aliasValues.keySet().size());
    assertTrue(test.aliasValues.get("oneWithIdSubTypeAlias") instanceof AllFieldCasesWithIdSubtype);
    AllFieldCasesWithIdSubtype verif = (AllFieldCasesWithIdSubtype) test.aliasValues.get("oneWithIdSubTypeAlias");
    assertEquals("the alias's str value", verif.getName());
}
Also used : AllFieldCasesWithIdSubtype(com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCasesWithIdSubtype) AllFieldCases(com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCases) Test(org.junit.jupiter.api.Test)

Example 3 with AllFieldCases

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

the class GraphQLObjectMapperTest method testListTwoStrings.

@Test
void testListTwoStrings() throws JsonMappingException, JsonProcessingException, NoSuchFieldException {
    // Preparation
    GraphQLObjectMapper objectMapper = new GraphQLObjectMapper(AllFieldCases.class.getPackage().getName(), getAliasFields(AllFieldCases.class, "commentsAlias", "comments"));
    // Go, go, go
    AllFieldCases test = objectMapper.readValue("{\"commentsAlias\":[\"my str1\", \"my str2\"], \"__typename\":\"AllFieldCases\"}", AllFieldCases.class);
    // Verification
    assertEquals(1, test.aliasValues.keySet().size());
    assertTrue(test.aliasValues.get("commentsAlias") instanceof List);
    // 
    assertEquals(2, ((List<?>) test.aliasValues.get("commentsAlias")).size());
    // 
    assertTrue(((List<?>) test.aliasValues.get("commentsAlias")).get(0) instanceof String);
    assertEquals("my str1", ((List<?>) test.aliasValues.get("commentsAlias")).get(0));
    // 
    assertTrue(((List<?>) test.aliasValues.get("commentsAlias")).get(1) instanceof String);
    assertEquals("my str2", ((List<?>) test.aliasValues.get("commentsAlias")).get(1));
}
Also used : AllFieldCases(com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCases) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 4 with AllFieldCases

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

the class AbstractGraphQLRepositoryInvocationHandlerTest method testInvoke_partialRequest_withListParam.

@SuppressWarnings("unchecked")
@Test
void testInvoke_partialRequest_withListParam() throws GraphQLRequestExecutionException, NoSuchMethodException, SecurityException {
    // Preparation
    AllFieldCases expected = new AllFieldCases();
    doReturn(expected).when(spyQueryExecutor).withListOfListWithBindValues(any(ObjectResponse.class), any(List.class), any(Map.class));
    // Go, go, go
    AllFieldCases verif = graphQLRepository.withListParam(Arrays.asList(Arrays.asList((float) 1.1)));
    // Verification
    assertEquals(expected, verif);
    assertEquals("", GraphQLRepositoryTestHelper.getRegisteredGraphQLRequest(invocationHandler, GraphQLRepositoryTestCase.class, "withListParam", List.class));
}
Also used : AllFieldCases(com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCases) List(java.util.List) ObjectResponse(com.graphql_java_generator.client.request.ObjectResponse) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with AllFieldCases

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

the class GraphQLObjectMapperTest method testListListList.

@SuppressWarnings("unchecked")
@Test
void testListListList() throws JsonMappingException, JsonProcessingException, NoSuchFieldException {
    // Preparation
    GraphQLObjectMapper objectMapper = new GraphQLObjectMapper(AllFieldCases.class.getPackage().getName(), getAliasFields(AllFieldCases.class, "matrixAlias", "matrix"));
    // Go, go, go
    AllFieldCases test = objectMapper.readValue("{\"matrixAlias\":[[11.11, 222.222],[],[3333.3333]], \"__typename\":\"AllFieldCases\"}", AllFieldCases.class);
    // Verification
    assertEquals(1, test.aliasValues.keySet().size());
    assertTrue(test.aliasValues.get("matrixAlias") instanceof List);
    List<?> mainList = (List<?>) test.aliasValues.get("matrixAlias");
    // 
    assertEquals(3, mainList.size(), "3 subsublists");
    // 
    List<Double> list = (List<Double>) mainList.get(0);
    assertEquals(2, list.size());
    assertEquals(11.11, list.get(0));
    assertEquals(222.222, list.get(1));
    // 
    list = (List<Double>) mainList.get(1);
    assertEquals(0, list.size());
    // 
    list = (List<Double>) mainList.get(2);
    assertEquals(1, list.size());
    assertEquals(3333.3333, list.get(0));
}
Also used : AllFieldCases(com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCases) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

AllFieldCases (com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCases)10 Test (org.junit.jupiter.api.Test)10 List (java.util.List)7 ObjectResponse (com.graphql_java_generator.client.request.ObjectResponse)2 Map (java.util.Map)2 AllFieldCasesInput (com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCasesInput)1 AllFieldCasesWithIdSubtype (com.graphql_java_generator.domain.client.allGraphQLCases.AllFieldCasesWithIdSubtype)1 FieldParameterInput (com.graphql_java_generator.domain.client.allGraphQLCases.FieldParameterInput)1 Human (com.graphql_java_generator.domain.client.allGraphQLCases.Human)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1