Skip to content

Commit 9f35bf3

Browse files
committed
Add test for a record
1 parent 62d8450 commit 9f35bf3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

graphql-builder/src/test/java/com/phocassoftware/graphql/builder/JakartaValidationDirectiveTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ void testJakartaSizeAnnotationAddedAsDirective() {
2727
assertEquals(3, min);
2828
}
2929

30+
@Test
31+
void testJakartaSizeAnnotationAddedAsDirectiveOnARecord() {
32+
GraphQL schema = GraphQL.newGraphQL(SchemaBuilder.build("com.phocassoftware.graphql.builder.type.directive.record")).build();
33+
var name = schema.getGraphQLSchema().getFieldDefinition(FieldCoordinates.coordinates(schema.getGraphQLSchema().getMutationType(), "setName"));
34+
var directive = name.getArgument("name").getAppliedDirective("Size");
35+
var argument = directive.getArgument("min");
36+
var min = argument.getValue();
37+
assertEquals(3, min);
38+
}
39+
3040
@Test
3141
void testJakartaSizeDirectiveArgumentDefinition() {
3242
Map<String, Object> response = execute("query IntrospectionQuery { __schema { directives { name locations args { name } } } }", null).getData();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
3+
* in compliance with the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License
8+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
9+
* or implied. See the License for the specific language governing permissions and limitations under
10+
* the License.
11+
*/
12+
package com.phocassoftware.graphql.builder.type.directive.record;
13+
14+
import com.phocassoftware.graphql.builder.annotations.Entity;
15+
import com.phocassoftware.graphql.builder.annotations.Mutation;
16+
import com.phocassoftware.graphql.builder.annotations.Query;
17+
import jakarta.validation.constraints.Max;
18+
import jakarta.validation.constraints.Min;
19+
import jakarta.validation.constraints.Size;
20+
21+
@Entity
22+
public record CatRecord(int age, String name) {
23+
@Mutation
24+
public static String setName(@Size(min = 3) String name) {
25+
return name;
26+
}
27+
28+
@Mutation
29+
public static int setAge(@Min(value = 3) @Max(value = 99) int age) {
30+
return age;
31+
}
32+
33+
@Query
34+
public static String getName(String name) {
35+
return name;
36+
}
37+
}

0 commit comments

Comments
 (0)