1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau;
18
19 import java.lang.reflect.*;
20
21 import org.apache.juneau.BeanTraverseContext.*;
22
23
24
25
26 class BeanTraverseProperties_ComboRoundTripTest extends ComboRoundTripTest_Base {
27
28 private static <T> ComboRoundTrip_Tester.Builder<T> tester(int index, String label, Type type, T bean) {
29 return ComboRoundTrip_Tester.create(index, label, type, ()->bean);
30 }
31
32 private static ComboRoundTrip_Tester<?>[] TESTERS = {
33 tester(1, "BEANTRAVERSE_initialDepth", A.class, new A().init())
34 .json("{f:1}")
35 .jsonT("{f:1}")
36 .jsonR("\t\t{\n\t\t\tf: 1\n\t\t}")
37 .xml("<object><f>1</f></object>")
38 .xmlT("<object><f>1</f></object>")
39 .xmlR("\t\t<object>\n\t\t\t<f>1</f>\n\t\t</object>\n")
40 .xmlNs("<object><f>1</f></object>")
41 .html("<table><tr><td>f</td><td>1</td></tr></table>")
42 .htmlT("<table><tr><td>f</td><td>1</td></tr></table>")
43 .htmlR("\t\t\t\t<table>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>f</td>\n\t\t\t\t\t\t<td>1</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n")
44 .uon("(f=1)")
45 .uonT("(f=1)")
46 .uonR("\t\t(\n\t\t\tf=1\n\t\t)")
47 .urlEnc("f=1")
48 .urlEncT("f=1")
49 .urlEncR("\t\tf=1")
50 .msgPack("81A16601")
51 .msgPackT("81A16601")
52 .rdfXml("<rdf:RDF>\n<rdf:Description>\n<jp:f>1</jp:f>\n</rdf:Description>\n</rdf:RDF>\n")
53 .rdfXmlT("<rdf:RDF>\n<rdf:Description>\n<jp:f>1</jp:f>\n</rdf:Description>\n</rdf:RDF>\n")
54 .rdfXmlR("<rdf:RDF>\n <rdf:Description>\n <jp:f>1</jp:f>\n </rdf:Description>\n</rdf:RDF>\n")
55 .apply(BeanTraverseContext.Builder.class, x -> x.initialDepth(2))
56 .build(),
57 tester(2, "BEANTRAVERSE_detectRecursions", B.class, new B().initRecursion())
58 .json("x")
59 .jsonT("x")
60 .jsonR("x")
61 .xml("x")
62 .xmlT("x")
63 .xmlR("x")
64 .xmlNs("x")
65 .html("x")
66 .htmlT("x")
67 .htmlR("x")
68 .uon("x")
69 .uonT("x")
70 .uonR("x")
71 .urlEnc("x")
72 .urlEncT("x")
73 .urlEncR("x")
74 .msgPack("x")
75 .msgPackT("x")
76 .rdfXml("x")
77 .rdfXmlT("x")
78 .rdfXmlR("x")
79 .apply(BeanTraverseContext.Builder.class, Builder::detectRecursions)
80 .exceptionMsg("Recursion occurred")
81 .build(),
82 tester(3, "BEANTRAVERSE_ignoreRecursions", B.class, new B().initRecursion())
83 .json("{}")
84 .jsonT("{}")
85 .jsonR("{\n}")
86 .xml("<object/>")
87 .xmlT("<object/>")
88 .xmlR("<object/>\n")
89 .xmlNs("<object/>")
90 .html("<table></table>")
91 .htmlT("<table></table>")
92 .htmlR("<table>\n</table>\n")
93 .uon("()")
94 .uonT("()")
95 .uonR("(\n)")
96 .urlEnc("")
97 .urlEncT("")
98 .urlEncR("")
99 .msgPack("80")
100 .msgPackT("80")
101 .rdfXml("<rdf:RDF>\n</rdf:RDF>\n")
102 .rdfXmlT("<rdf:RDF>\n</rdf:RDF>\n")
103 .rdfXmlR("<rdf:RDF>\n</rdf:RDF>\n")
104 .apply(BeanTraverseContext.Builder.class, Builder::ignoreRecursions)
105 .build(),
106 tester(4, "BEANTRAVERSE_maxDepth", B.class, new B().initA())
107 .json("{}")
108 .jsonT("{}")
109 .jsonR("{\n}")
110 .xml("<object/>")
111 .xmlT("<object/>")
112 .xmlR("<object/>\n")
113 .xmlNs("<object/>")
114 .html("<table></table>")
115 .htmlT("<table></table>")
116 .htmlR("<table>\n</table>\n")
117 .uon("()")
118 .uonT("()")
119 .uonR("(\n)")
120 .urlEnc("")
121 .urlEncT("")
122 .urlEncR("")
123 .msgPack("80")
124 .msgPackT("80")
125 .rdfXml("<rdf:RDF>\n</rdf:RDF>\n")
126 .rdfXmlT("<rdf:RDF>\n</rdf:RDF>\n")
127 .rdfXmlR("<rdf:RDF>\n</rdf:RDF>\n")
128 .apply(BeanTraverseContext.Builder.class, x -> x.maxDepth(1))
129 .build()
130 };
131
132 static ComboRoundTrip_Tester<?>[] testers() {
133 return TESTERS;
134 }
135
136 public static class A {
137 public int f;
138
139 public A init() {
140 f = 1;
141 return this;
142 }
143 }
144
145 public static class B {
146 public Object f;
147
148 public B initRecursion() {
149 f = this;
150 return this;
151 }
152
153 public B initA() {
154 f = new A().init();
155 return this;
156 }
157 }
158 }