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