1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.form.pojo;
17
18 import org.apache.commons.beanutils.NestedNullException;
19 import org.apache.commons.beanutils.PropertyUtils;
20 import org.junit.Test;
21 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
22 import org.kuali.rice.krad.util.ObjectUtils;
23
24 import java.util.Collection;
25 import java.util.Collections;
26
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
29
30 public class PojoPluginTest {
31
32
33
34
35
36
37
38 @Test
39 public void testGetChildCollectionThrowsNestedNullException() throws Exception {
40
41
42 new PojoPlugin().init(null, null);
43
44 TestCollectionHolderHolder tchh = new TestCollectionHolderHolder();
45 tchh.setTch(new TestCollectionHolder());
46
47
48
49
50 Object result = ObjectUtils.getPropertyValue(tchh, "tch.collection");
51
52
53 assertFalse("".equals(result));
54
55
56 assertTrue(null == result);
57 }
58
59
60
61
62
63
64
65 @Test
66 public void testNestedNullIsWriteable() throws Exception {
67
68
69 new PojoPlugin().init(null, null);
70
71 TestCollectionHolderHolder tchh = new TestCollectionHolderHolder();
72 assertTrue(PropertyUtils.isWriteable(tchh, "tch2.collection"));
73
74
75 }
76
77
78
79
80 public static class TestCollectionHolderHolder extends PersistableBusinessObjectBase {
81 private TestCollectionHolder tch = null;
82 private TestCollectionHolder2 tch2;
83
84 public TestCollectionHolder getTch() {
85 return tch;
86 }
87
88 public void setTch(TestCollectionHolder tch) {
89 this.tch = tch;
90 }
91
92 public TestCollectionHolder2 getTch2() {
93 return tch2;
94 }
95
96 public void setTch2(TestCollectionHolder2 tch2) {
97 this.tch2 = tch2;
98 }
99 }
100
101
102
103
104
105
106 public static class TestCollectionHolder extends PersistableBusinessObjectBase {
107 private Collection collection = Collections.emptyList();
108
109 public Collection getCollection() {
110 throw new NestedNullException();
111 }
112
113 public void setCollection(Collection collection) {
114 this.collection = collection;
115 }
116 }
117
118
119
120
121
122
123 public static class TestCollectionHolder2 extends PersistableBusinessObjectBase {
124 private Collection collection = Collections.emptyList();
125
126 public Collection getCollection() {
127 return collection;
128 }
129
130 public void setCollection(Collection collection) {
131 this.collection = collection;
132 }
133 }
134
135
136 }