1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils.bugs;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23 import org.apache.commons.beanutils.PropertyUtils;
24 import org.apache.commons.beanutils.bugs.other.Jira18BeanFactory;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28
29
30
31
32
33
34
35
36 public class Jira18TestCase extends TestCase {
37
38 private final Log log = LogFactory.getLog(Jira18TestCase.class);
39 private Object bean;
40
41
42
43
44
45
46 public Jira18TestCase(final String name) {
47 super(name);
48 }
49
50
51
52
53
54
55 public static void main(final String[] args) {
56 junit.textui.TestRunner.run(suite());
57 }
58
59
60
61
62
63
64 public static Test suite() {
65 return (new TestSuite(Jira18TestCase.class));
66 }
67
68
69
70
71
72
73 @Override
74 protected void setUp() throws Exception {
75 super.setUp();
76 bean = Jira18BeanFactory.createBean();
77 }
78
79
80
81
82
83
84 @Override
85 protected void tearDown() throws Exception {
86 super.tearDown();
87 }
88
89
90
91
92
93 public void testIssue_BEANUTILS_18_PropertyUtils_isReadable() {
94 boolean result = false;
95 try {
96 result = PropertyUtils.isReadable(bean, "simple");
97 } catch (final Throwable t) {
98 log.error("ERROR " + t, t);
99 fail("Threw exception: " + t);
100 }
101 assertFalse("PropertyUtils.isReadable(bean, \"simple\") returned true", result);
102 }
103
104
105
106
107
108 public void testIssue_BEANUTILS_18_PropertyUtils_isWriteable() {
109 boolean result = false;
110 try {
111 result = PropertyUtils.isWriteable(bean, "simple");
112 } catch (final Throwable t) {
113 log.error("ERROR " + t, t);
114 fail("Threw exception: " + t);
115 }
116 assertFalse("PropertyUtils.isWriteable(bean, \"simple\") returned true", result);
117 }
118
119
120
121
122
123 public void testIssue_BEANUTILS_18_PropertyUtils_isReadable_Indexed() {
124 boolean result = false;
125 try {
126 result = PropertyUtils.isReadable(bean, "indexed");
127 } catch (final Throwable t) {
128 log.error("ERROR " + t, t);
129 fail("Threw exception: " + t);
130 }
131 assertFalse("PropertyUtils.isReadable(bean, \"indexed\") returned true", result);
132 }
133
134
135
136
137
138 public void testIssue_BEANUTILS_18_PropertyUtils_isWriteable_Indexed() {
139 boolean result = false;
140 try {
141 result = PropertyUtils.isWriteable(bean, "indexed");
142 } catch (final Throwable t) {
143 log.error("ERROR " + t, t);
144 fail("Threw exception: " + t);
145 }
146 assertFalse("PropertyUtils.isWriteable(bean, \"indexed\") returned true", result);
147 }
148
149
150
151
152
153 public void testIssue_BEANUTILS_18_PropertyUtils_isReadable_Mapped() {
154 boolean result = false;
155 try {
156 result = PropertyUtils.isReadable(bean, "mapped");
157 } catch (final Throwable t) {
158 log.error("ERROR " + t, t);
159 fail("Threw exception: " + t);
160 }
161 assertFalse("PropertyUtils.isReadable(bean, \"mapped\") returned true", result);
162 }
163
164
165
166
167
168 public void testIssue_BEANUTILS_18_PropertyUtils_isWriteable_Mapped() {
169 boolean result = false;
170 try {
171 result = PropertyUtils.isWriteable(bean, "mapped");
172 } catch (final Throwable t) {
173 log.error("ERROR " + t, t);
174 fail("Threw exception: " + t);
175 }
176 assertFalse("PropertyUtils.isWriteable(bean, \"mapped\") returned true", result);
177 }
178
179
180
181
182
183 public void testIssue_BEANUTILS_18_PropertyUtils_getProperty() {
184 boolean threwNoSuchMethodException = false;
185 Object result = null;
186 try {
187 result = PropertyUtils.getProperty(bean, "simple");
188 } catch (final NoSuchMethodException ex) {
189 threwNoSuchMethodException = true;
190 } catch (final Throwable t) {
191 log.error("ERROR " + t, t);
192 fail("Threw exception: " + t);
193 }
194 assertTrue("Expected NoSuchMethodException but returned '" + result + "'", threwNoSuchMethodException);
195 }
196
197
198
199
200
201 public void testIssue_BEANUTILS_18_PropertyUtils_setProperty() {
202 boolean threwNoSuchMethodException = false;
203 try {
204 PropertyUtils.setProperty(bean, "simple", "BAR");
205 } catch (final NoSuchMethodException ex) {
206 threwNoSuchMethodException = true;
207 } catch (final Throwable t) {
208 log.error("ERROR " + t, t);
209 fail("Threw exception: " + t);
210 }
211 assertTrue("Expected NoSuchMethodException", threwNoSuchMethodException);
212 }
213
214
215
216
217
218 public void testIssue_BEANUTILS_18_PropertyUtils_getProperty_Indexed() {
219 boolean threwNoSuchMethodException = false;
220 Object result = null;
221 try {
222 result = PropertyUtils.getProperty(bean, "indexed[0]");
223 } catch (final NoSuchMethodException ex) {
224 threwNoSuchMethodException = true;
225 } catch (final Throwable t) {
226 log.error("ERROR " + t, t);
227 fail("Threw exception: " + t);
228 }
229 assertTrue("Expected NoSuchMethodException but returned '" + result + "'", threwNoSuchMethodException);
230 }
231
232
233
234
235
236 public void testIssue_BEANUTILS_18_PropertyUtils_setProperty_Indexed() {
237 boolean threwNoSuchMethodException = false;
238 try {
239 PropertyUtils.setProperty(bean, "indexed[0]", "BAR");
240 } catch (final NoSuchMethodException ex) {
241 threwNoSuchMethodException = true;
242 } catch (final Throwable t) {
243 log.error("ERROR " + t, t);
244 fail("Threw exception: " + t);
245 }
246 assertTrue("Expected NoSuchMethodException", threwNoSuchMethodException);
247 }
248
249
250
251
252
253 public void testIssue_BEANUTILS_18_PropertyUtils_getProperty_Mapped() {
254 boolean threwNoSuchMethodException = false;
255 Object result = null;
256 try {
257 result = PropertyUtils.getProperty(bean, "mapped(foo-key)");
258 } catch (final NoSuchMethodException ex) {
259 threwNoSuchMethodException = true;
260 } catch (final Throwable t) {
261 log.error("ERROR " + t, t);
262 fail("Threw exception: " + t);
263 }
264 assertTrue("Expected NoSuchMethodException but returned '" + result + "'", threwNoSuchMethodException);
265 }
266
267
268
269
270
271 public void testIssue_BEANUTILS_18_PropertyUtils_setProperty_Mapped() {
272 boolean threwNoSuchMethodException = false;
273 try {
274 PropertyUtils.setProperty(bean, "mapped(foo-key)", "BAR");
275 } catch (final NoSuchMethodException ex) {
276 threwNoSuchMethodException = true;
277 } catch (final Throwable t) {
278 log.error("ERROR " + t, t);
279 fail("Threw exception: " + t);
280 }
281 assertTrue("Expected NoSuchMethodException", threwNoSuchMethodException);
282 }
283 }