1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.json;
18
19 import static org.apache.juneau.commons.utils.CollectionUtils.*;
20 import static org.junit.jupiter.api.Assertions.*;
21
22 import java.util.function.*;
23
24 import org.apache.juneau.*;
25 import org.apache.juneau.commons.reflect.*;
26 import org.apache.juneau.json.annotation.*;
27 import org.apache.juneau.svl.*;
28 import org.junit.jupiter.api.*;
29
30
31
32
33 class JsonConfigAnnotationTest extends TestBase {
34
35 private static void check(String expected, Object o) {
36 assertEquals(expected, TO_STRING.apply(o));
37 }
38
39 private static final Function<Object,String> TO_STRING = Object::toString;
40
41 static VarResolverSession sr = VarResolver.create().vars(XVar.class).build().createSession();
42
43
44
45
46
47 @JsonConfig(
48 addBeanTypes="$X{true}",
49 escapeSolidus="$X{true}",
50 simpleAttrs="$X{true}",
51 validateEnd="$X{true}"
52 )
53 static class A {}
54 static ClassInfo a = ClassInfo.of(A.class);
55
56 @Test void basicSerializer() {
57 var al = AnnotationWorkList.of(sr, rstream(a.getAnnotations()));
58 var x = JsonSerializer.create().apply(al).build().getSession();
59 check("true", x.isAddBeanTypes());
60 check("true", x.isEscapeSolidus());
61 check("true", x.isSimpleAttrs());
62 }
63
64 @Test void basicParser() {
65 var al = AnnotationWorkList.of(sr, rstream(a.getAnnotations()));
66 var x = JsonParser.create().apply(al).build().getSession();
67 check("true", x.isValidateEnd());
68 }
69
70
71
72
73
74 @JsonConfig()
75 static class B {}
76 static ClassInfo b = ClassInfo.of(B.class);
77
78 @Test void noValuesSerializer() {
79 var al = AnnotationWorkList.of(sr, rstream(b.getAnnotations()));
80 var x = JsonSerializer.create().apply(al).build().getSession();
81 check("false", x.isAddBeanTypes());
82 check("false", x.isEscapeSolidus());
83 check("false", x.isSimpleAttrs());
84 }
85
86 @Test void noValuesParser() {
87 var al = AnnotationWorkList.of(sr, rstream(b.getAnnotations()));
88 var x = JsonParser.create().apply(al).build().getSession();
89 check("false", x.isValidateEnd());
90 }
91
92
93
94
95
96 static class C {}
97 static ClassInfo c = ClassInfo.of(C.class);
98
99 @Test void noAnnotationSerializer() {
100 var al = AnnotationWorkList.of(sr, rstream(c.getAnnotations()));
101 var x = JsonSerializer.create().apply(al).build().getSession();
102 check("false", x.isAddBeanTypes());
103 check("false", x.isEscapeSolidus());
104 check("false", x.isSimpleAttrs());
105 }
106
107 @Test void noAnnotationParser() {
108 var al = AnnotationWorkList.of(sr, rstream(c.getAnnotations()));
109 var x = JsonParser.create().apply(al).build().getSession();
110 check("false", x.isValidateEnd());
111 }
112 }