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.junit.jupiter.api.Assertions.*;
20
21 import org.apache.juneau.annotation.*;
22 import org.junit.jupiter.params.*;
23 import org.junit.jupiter.params.provider.*;
24
25
26
27
28
29 class ParentProperty_RoundTripTest extends RoundTripTest_Base {
30
31
32
33
34
35 @ParameterizedTest
36 @MethodSource("testers")
37 void a01_parentProperty(RoundTrip_Tester t) throws Exception {
38 var x = new ParentPropertyMethodContainer().init();
39 x = t.roundTrip(x);
40 if (t.isValidationOnly())
41 return;
42 assertEquals(x.f1, x.bean.parent.f1);
43 }
44
45 public static class ParentPropertyMethodContainer {
46 public int f1;
47 public ParentPropertyMethodBean bean;
48
49 ParentPropertyMethodContainer init() {
50 f1 = 1;
51 bean = new ParentPropertyMethodBean().init();
52 return this;
53 }
54
55 }
56 public static class ParentPropertyMethodBean {
57 ParentPropertyMethodContainer parent;
58 public int f2;
59
60 @ParentProperty
61 protected void setParent(ParentPropertyMethodContainer v) {
62 parent = v;
63 }
64
65 ParentPropertyMethodBean init() {
66 f2 = 2;
67 return this;
68 }
69 }
70
71
72
73
74
75 @ParameterizedTest
76 @MethodSource("testers")
77 void a02_parentPropertyField(RoundTrip_Tester t) throws Exception {
78 var x = new ParentPropertyFieldContainer().init();
79 x = t.roundTrip(x);
80 if (t.isValidationOnly())
81 return;
82 assertEquals(x.f1, x.bean.parent.f1);
83 }
84
85 public static class ParentPropertyFieldContainer {
86 public int f1;
87 public ParentPropertyFieldBean bean;
88
89 ParentPropertyFieldContainer init() {
90 f1 = 1;
91 bean = new ParentPropertyFieldBean().init();
92 return this;
93 }
94 }
95 public static class ParentPropertyFieldBean {
96 @ParentProperty
97 public ParentPropertyFieldContainer parent;
98 public int f2;
99
100 ParentPropertyFieldBean init() {
101 f2 = 2;
102 return this;
103 }
104 }
105
106
107
108
109
110 @ParameterizedTest
111 @MethodSource("testers")
112 void a03_readOnlyParentProperty(RoundTrip_Tester t) throws Exception {
113 var x = new ReadOnlyParentPropertyContainer().init();
114
115 assertNull(x.bean.getParent(), "Read-only parent property should initially be null");
116 x = t.roundTrip(x);
117 if (t.isValidationOnly())
118 return;
119
120 assertNull(x.bean.getParent(), "Read-only parent property should not be set by parser");
121
122 assertEquals(1, x.f1);
123 assertEquals(2, x.bean.f2);
124 }
125
126 public static class ReadOnlyParentPropertyContainer {
127 public int f1;
128 public ReadOnlyParentPropertyBean bean;
129
130 ReadOnlyParentPropertyContainer init() {
131 f1 = 1;
132 bean = new ReadOnlyParentPropertyBean().init();
133 return this;
134 }
135 }
136 public static class ReadOnlyParentPropertyBean {
137 private ReadOnlyParentPropertyContainer parent;
138 public int f2;
139
140 @ParentProperty
141 public ReadOnlyParentPropertyContainer getParent() {
142 return parent;
143 }
144
145 ReadOnlyParentPropertyBean init() {
146 f2 = 2;
147 return this;
148 }
149 }
150 }
151