1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.a.rttests;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.junit.jupiter.api.Assertions.*;
21
22 import java.util.*;
23
24 import org.apache.juneau.annotation.*;
25 import org.junit.jupiter.params.*;
26 import org.junit.jupiter.params.provider.*;
27
28
29
30
31
32 class ObjectsWithSpecialMethods_RoundTripTest extends RoundTripTest_Base {
33
34
35
36
37
38 @ParameterizedTest
39 @MethodSource("testers")
40 void a01_nameProperty(RoundTrip_Tester t) throws Exception {
41 var x = new A().init();
42 x = t.roundTrip(x);
43 assertBean(x, "a2{f2},m{k1{f2}}", "{2},{{2}}");
44 if (t.isValidationOnly())
45 return;
46 assertBean(x, "a2{name}", "{a2}");
47 assertBean(x, "m{k1{name}}", "{{k1}}");
48 }
49
50 public static class A {
51 public A2 a2;
52 public Map<String,A2> m;
53
54 A init() {
55 a2 = new A2().init();
56 m = new LinkedHashMap<>();
57 m.put("k1", new A2().init());
58 return this;
59 }
60
61 }
62 public static class A2 {
63 String name;
64 public int f2;
65
66 @NameProperty
67 protected void setName(String name) {
68 this.name = name;
69 }
70
71 A2 init() {
72 f2 = 2;
73 return this;
74 }
75 }
76
77
78
79
80
81 @ParameterizedTest
82 @MethodSource("testers")
83 void a02_parentProperty(RoundTrip_Tester t) throws Exception {
84 var x = new B().init();
85 x = t.roundTrip(x);
86 if (t.isValidationOnly())
87 return;
88 assertEquals(x.f1, x.b2.parent.f1);
89 }
90
91 public static class B {
92 public int f1;
93 public B2 b2;
94
95 B init() {
96 f1 = 1;
97 b2 = new B2().init();
98 return this;
99 }
100
101 }
102 public static class B2 {
103 B parent;
104 public int f2;
105
106 @ParentProperty
107 protected void setParent(B v) {
108 parent = v;
109 }
110
111 B2 init() {
112 f2 = 2;
113 return this;
114 }
115 }
116 }