|
| 1 | +/** |
| 2 | + * Copyright 2016 Yurii Rashkovskii |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + */ |
| 15 | +package graphql.annotations; |
| 16 | + |
| 17 | +import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; |
| 18 | +import static org.hamcrest.CoreMatchers.is; |
| 19 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 20 | +import static org.hamcrest.CoreMatchers.nullValue; |
| 21 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 22 | + |
| 23 | +import graphql.annotations.annotationTypes.GraphQLField; |
| 24 | +import graphql.annotations.annotationTypes.GraphQLIgnore; |
| 25 | +import graphql.annotations.annotationTypes.GraphQLName; |
| 26 | +import graphql.annotations.processor.GraphQLAnnotations; |
| 27 | +import graphql.schema.GraphQLObjectType; |
| 28 | +import graphql.schema.GraphQLSchema; |
| 29 | +import org.testng.annotations.BeforeMethod; |
| 30 | +import org.testng.annotations.Test; |
| 31 | + |
| 32 | +public class GraphQLIgnoredFieldParameterTest { |
| 33 | + private AnnotationsSchemaCreator.Builder builder; |
| 34 | + private GraphQLAnnotations graphQLAnnotations; |
| 35 | + |
| 36 | + @BeforeMethod |
| 37 | + public void setUp() { |
| 38 | + graphQLAnnotations = new GraphQLAnnotations(); |
| 39 | + builder = newAnnotationsSchema().setAnnotationsProcessor(graphQLAnnotations); |
| 40 | + } |
| 41 | + |
| 42 | + public static class QueryTest1 { |
| 43 | + @GraphQLField |
| 44 | + public int foo(@GraphQLIgnore int bar) { |
| 45 | + return 5; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void build_Query1IsProvided_SchemaIsCreatedWithoutIgnoredFieldParameters() { |
| 51 | + // arrange + act |
| 52 | + GraphQLSchema schema = builder.query(QueryTest1.class).build(); |
| 53 | + |
| 54 | + // assert |
| 55 | + GraphQLObjectType queryType = schema.getQueryType(); |
| 56 | + assertThat(queryType.getFieldDefinition("foo"), notNullValue()); |
| 57 | + assertThat(queryType.getFieldDefinition("foo").getArguments().size(), is(0)); |
| 58 | + } |
| 59 | + |
| 60 | + public static class QueryTest2 { |
| 61 | + @GraphQLField |
| 62 | + public int foo(int bar, @GraphQLIgnore String baz, @GraphQLName("quuxAlias") long quux) { |
| 63 | + return 5; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void build_Query2IsProvided_SchemaIsCreatedWithoutIgnoredFieldParameters() { |
| 69 | + // arrange + act |
| 70 | + GraphQLSchema schema = builder.query(QueryTest2.class).build(); |
| 71 | + |
| 72 | + // assert |
| 73 | + GraphQLObjectType queryType = schema.getQueryType(); |
| 74 | + assertThat(queryType.getFieldDefinition("foo"), notNullValue()); |
| 75 | + assertThat(queryType.getFieldDefinition("foo").getArguments().size(), is(2)); |
| 76 | + assertThat(queryType.getFieldDefinition("foo").getArgument("arg0"), notNullValue()); |
| 77 | + assertThat(queryType.getFieldDefinition("foo").getArgument("baz"), nullValue()); |
| 78 | + assertThat(queryType.getFieldDefinition("foo").getArgument("quuxAlias"), notNullValue()); |
| 79 | + } |
| 80 | + |
| 81 | + public static class MutationTest1 { |
| 82 | + @GraphQLField |
| 83 | + public int foo(@GraphQLIgnore int bar) { |
| 84 | + return 4; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void build_Mutation1IsProvided_SchemaIsCreatedWithoutIgnoredFieldParameters() { |
| 90 | + // arrange + act |
| 91 | + GraphQLSchema schema = builder.query(QueryTest1.class).mutation(MutationTest1.class).build(); |
| 92 | + |
| 93 | + /// assert |
| 94 | + GraphQLObjectType mutation = schema.getMutationType(); |
| 95 | + assertThat(mutation.getFieldDefinition("foo"), notNullValue()); |
| 96 | + assertThat(mutation.getFieldDefinition("foo").getArguments().size(), is(0)); |
| 97 | + } |
| 98 | + |
| 99 | + public static class MutationTest2 { |
| 100 | + @GraphQLField |
| 101 | + public int foo(int bar, @GraphQLIgnore String baz, @GraphQLName("quuxAlias") long quux) { |
| 102 | + return 4; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + public void build_Mutation2IsProvided_SchemaIsCreatedWithoutIgnoredFieldParameters() { |
| 108 | + // arrange + act |
| 109 | + GraphQLSchema schema = builder.query(QueryTest1.class).mutation(MutationTest2.class).build(); |
| 110 | + |
| 111 | + /// assert |
| 112 | + GraphQLObjectType mutation = schema.getMutationType(); |
| 113 | + assertThat(mutation.getFieldDefinition("foo"), notNullValue()); |
| 114 | + assertThat(mutation.getFieldDefinition("foo").getArguments().size(), is(2)); |
| 115 | + assertThat(mutation.getFieldDefinition("foo").getArgument("arg0"), notNullValue()); |
| 116 | + assertThat(mutation.getFieldDefinition("foo").getArgument("baz"), nullValue()); |
| 117 | + assertThat(mutation.getFieldDefinition("foo").getArgument("quuxAlias"), notNullValue()); |
| 118 | + } |
| 119 | +} |
0 commit comments