1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.html;
18
19 import static org.junit.jupiter.api.Assertions.*;
20
21 import java.util.*;
22 import java.util.function.*;
23
24 import org.apache.juneau.*;
25 import org.apache.juneau.html.annotation.*;
26 import org.apache.juneau.reflect.*;
27 import org.apache.juneau.svl.*;
28 import org.junit.jupiter.api.*;
29
30
31
32
33 class HtmlConfigAnnotation_Test 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 = t -> Objects.toString(t, null);
40
41
42 static VarResolverSession sr = VarResolver.create().vars(XVar.class).build().createSession();
43
44
45
46
47
48 @HtmlConfig(
49 addBeanTypes="$X{true}",
50 addKeyValueTableHeaders="$X{true}",
51 disableDetectLabelParameters="$X{true}",
52 disableDetectLinksInStrings="$X{true}",
53 labelParameter="$X{foo}",
54 uriAnchorText="$X{TO_STRING}"
55 )
56 static class A {}
57 static ClassInfo a = ClassInfo.of(A.class);
58
59 @Test void basicSerializer() {
60 var al = AnnotationWorkList.of(sr, a.getAnnotationList());
61 var x = HtmlSerializer.create().apply(al).build().getSession();
62 check("true", x.isAddBeanTypes());
63 check("true", x.isAddKeyValueTableHeaders());
64 check("false", x.isDetectLabelParameters());
65 check("false", x.isDetectLinksInStrings());
66 check("foo", x.getLabelParameter());
67 check("TO_STRING", x.getUriAnchorText());
68 }
69
70 @Test void basicParser() {
71 var al = AnnotationWorkList.of(sr, a.getAnnotationList());
72 assertDoesNotThrow(()->HtmlParser.create().apply(al).build().createSession());
73 }
74
75
76
77
78
79 @HtmlConfig()
80 static class B {}
81 static ClassInfo b = ClassInfo.of(B.class);
82
83 @Test void defaultsSerializer() {
84 var al = AnnotationWorkList.of(sr, b.getAnnotationList());
85 var x = HtmlSerializer.create().apply(al).build().getSession();
86 check("false", x.isAddBeanTypes());
87 check("false", x.isAddKeyValueTableHeaders());
88 check("true", x.isDetectLabelParameters());
89 check("true", x.isDetectLinksInStrings());
90 check("label", x.getLabelParameter());
91 check("TO_STRING", x.getUriAnchorText());
92 }
93
94 @Test void defaultsParser() {
95 var al = AnnotationWorkList.of(sr, b.getAnnotationList());
96 assertDoesNotThrow(()->HtmlParser.create().apply(al).build().createSession());
97 }
98
99
100
101
102
103 static class C {}
104 static ClassInfo c = ClassInfo.of(C.class);
105
106 @Test void noAnnotationSerializer() {
107 var al = AnnotationWorkList.of(sr, c.getAnnotationList());
108 var x = HtmlSerializer.create().apply(al).build().getSession();
109 check("false", x.isAddBeanTypes());
110 check("false", x.isAddKeyValueTableHeaders());
111 check("true", x.isDetectLabelParameters());
112 check("true", x.isDetectLinksInStrings());
113 check("label", x.getLabelParameter());
114 check("TO_STRING", x.getUriAnchorText());
115 }
116
117 @Test void noAnnotationParser() {
118 var al = AnnotationWorkList.of(sr, c.getAnnotationList());
119 assertDoesNotThrow(()->HtmlParser.create().apply(al).build().createSession());
120 }
121 }