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.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.msgpack.annotation.*;
27 import org.apache.juneau.svl.*;
28 import org.junit.jupiter.api.*;
29
30
31
32
33 class MsgPackConfigAnnotationTest 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 @MsgPackConfig(
48 addBeanTypes="$X{true}"
49 )
50 static class A {}
51 static ClassInfo a = ClassInfo.of(A.class);
52
53 @Test void basicSerializer() {
54 var al = AnnotationWorkList.of(sr, rstream(a.getAnnotations()));
55 var x = MsgPackSerializer.create().apply(al).build().getSession();
56 check("true", x.isAddBeanTypes());
57 }
58
59 @Test void basicParser() {
60 var al = AnnotationWorkList.of(sr, rstream(a.getAnnotations()));
61 assertDoesNotThrow(()->MsgPackParser.create().apply(al).build().createSession());
62 }
63
64
65
66
67
68 @MsgPackConfig()
69 static class B {}
70 static ClassInfo b = ClassInfo.of(B.class);
71
72 @Test void noValuesSerializer() {
73 var al = AnnotationWorkList.of(sr, rstream(b.getAnnotations()));
74 var x = MsgPackSerializer.create().apply(al).build().getSession();
75 check("false", x.isAddBeanTypes());
76 }
77
78 @Test void noValuesParser() {
79 var al = AnnotationWorkList.of(sr, rstream(b.getAnnotations()));
80 assertDoesNotThrow(()->MsgPackParser.create().apply(al).build().createSession());
81 }
82
83
84
85
86
87 static class C {}
88 static ClassInfo c = ClassInfo.of(C.class);
89
90 @Test void noAnnotationSerializer() {
91 var al = AnnotationWorkList.of(sr, rstream(c.getAnnotations()));
92 var x = MsgPackSerializer.create().apply(al).build().getSession();
93 check("false", x.isAddBeanTypes());
94 }
95
96 @Test void noAnnotationParser() {
97 var al = AnnotationWorkList.of(sr, rstream(c.getAnnotations()));
98 assertDoesNotThrow(()->MsgPackParser.create().apply(al).build().createSession());
99 }
100 }