diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java index 10be6907..93102315 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java @@ -99,6 +99,21 @@ class GraphQlArgumentBinderTests { .hasSize(2).extracting("name").containsExactly("first", "second"); } + @Test // gh-394 + void dataBindingWithNestedBeanSetProperty() throws Exception { + + String items = IntStream.range(0, 5) + .mapToObj(value -> "{\"name\":\"test" + value + "\"}") + .collect(Collectors.joining(",")); + + Object result = this.binder.bind( + environment("{\"key\":{\"items\":[" + items + "]}}"), "key", + ResolvableType.forClass(ItemSetHolder.class)); + + assertThat(result).isNotNull().isInstanceOf(ItemSetHolder.class); + assertThat(((ItemSetHolder) result).getItems()).hasSize(5); + } + @Test // gh-301 void dataBindingWithNestedBeanListEmpty() throws Exception { @@ -247,6 +262,28 @@ class GraphQlArgumentBinderTests { .hasSize(2).extracting("name").containsExactly("first", "second"); } + @Test // gh-410 + void primaryConstructorWithNestedBeanSingletonList() throws Exception { + + Map itemMap = new HashMap<>(); + itemMap.put("name", "Joe"); + itemMap.put("age", "37"); + + Map arguments = new HashMap<>(); + arguments.put("key", Collections.singletonMap("items", Collections.singletonList(itemMap))); + + Object result = this.binder.bind( + DataFetchingEnvironmentImpl.newDataFetchingEnvironment().arguments(arguments).build(), "key", + ResolvableType.forClass(PrimaryConstructorItemListBean.class)); + + assertThat(result).isNotNull().isInstanceOf(PrimaryConstructorItemListBean.class); + List items = ((PrimaryConstructorItemListBean) result).getItems(); + + assertThat(items).hasSize(1); + assertThat(items.get(0).getName()).isEqualTo("Joe"); + assertThat(items.get(0).getAge()).isEqualTo(37); + } + @Test void primaryConstructorNotFound() { assertThatThrownBy( @@ -353,51 +390,6 @@ class GraphQlArgumentBinderTests { Collections.singletonMap("name", "second")); } - @Test // gh-410 - @SuppressWarnings("unchecked") - void coercionWithSingletonList() throws Exception { - - Map itemMap = new HashMap<>(); - itemMap.put("name", "Joe"); - itemMap.put("age", "37"); - - Map arguments = new HashMap<>(); - arguments.put("key", Collections.singletonList(itemMap)); - - DataFetchingEnvironment environment = - DataFetchingEnvironmentImpl.newDataFetchingEnvironment().arguments(arguments).build(); - - Object result = this.binder.bind(environment, "key", - ResolvableType.forClassWithGenerics(List.class, Item.class)); - - assertThat(result).isNotNull().isInstanceOf(List.class); - List items = (List) result; - - assertThat(items).hasSize(1); - assertThat(items.get(0).getName()).isEqualTo("Joe"); - assertThat(items.get(0).getAge()).isEqualTo(37); - } - - @Test // gh-392 - void shouldHaveHigherDefaultAutoGrowLimit() throws Exception { - String items = IntStream.range(0, 260).mapToObj(value -> "{\"name\":\"test\"}").collect(Collectors.joining(",")); - Object result = this.binder.bind( - environment("{\"key\":{\"items\":[" + items + "]}}"), "key", - ResolvableType.forClass(ItemListHolder.class)); - assertThat(result).isNotNull().isInstanceOf(ItemListHolder.class); - assertThat(((ItemListHolder) result).getItems()).hasSize(260); - } - - @Test - void shouldUseTargetCollectionType() throws Exception { - String items = IntStream.range(0, 5).mapToObj(value -> "{\"name\":\"test" + value + "\"}").collect(Collectors.joining(",")); - Object result = this.binder.bind( - environment("{\"key\":{\"items\":[" + items + "]}}"), "key", - ResolvableType.forClass(ItemSetHolder.class)); - assertThat(result).isNotNull().isInstanceOf(ItemSetHolder.class); - assertThat(((ItemSetHolder) result).getItems()).hasSize(5); - } - @SuppressWarnings("unchecked") private DataFetchingEnvironment environment(String jsonPayload) throws JsonProcessingException { Map arguments = this.mapper.readValue(jsonPayload, Map.class); @@ -574,10 +566,6 @@ class GraphQlArgumentBinderTests { private Set items; - public ItemSetHolder(Set items) { - this.items = items; - } - public Set getItems() { return items; }