1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif;
17
18 import org.junit.Test;
19 import org.kuali.rice.krad.test.TestDictionaryBean;
20 import org.kuali.rice.krad.uif.field.DataField;
21 import org.kuali.rice.krad.uif.field.InputField;
22 import org.kuali.rice.krad.uif.view.InquiryView;
23 import org.kuali.rice.krad.test.KRADTestCase;
24 import org.kuali.rice.krad.test.TestDictionaryConfig;
25
26 import java.util.List;
27 import java.util.Map;
28
29 import static org.junit.Assert.*;
30
31
32
33
34
35
36 @TestDictionaryConfig(
37 namespaceCode = "KR-NS",
38 dataDictionaryFiles = "classpath:org/kuali/rice/krad/uif/UifBeanFactoryPostProcessorTestBeans.xml")
39 public class UifBeanFactoryPostProcessorTest extends KRADTestCase {
40
41
42
43
44
45
46
47
48
49
50
51
52
53 @Test
54 public void testOverrideOfNestedBeanExpression() throws Exception {
55
56 InputField inputField = (InputField) getTestDictionaryObject("testNestedExpressionOverride2");
57 assertNotNull("No bean exists with id: testNestedExpressionOverride2", inputField);
58
59 assertNotNull("Expression not in graph", inputField.getExpressionGraph().get("inquiry.render"));
60
61
62 inputField = (InputField) getTestDictionaryObject("testNestedExpressionOverride");
63 assertNotNull("No bean exists with id: testNestedExpressionOverride", inputField);
64
65 assertFalse("Child property did not override", inputField.getInquiry().isRender());
66 assertNull("Parent nested bean expression still in expression graph", inputField.getExpressionGraph().get(
67 "inquiry.render"));
68
69
70 inputField = (InputField) getTestDictionaryObject("testNestedExpressionOverride3");
71 assertNotNull("No bean exists with id: testNestedExpressionOverride3", inputField);
72
73 assertTrue("Child property did not override", inputField.getInquiry().isRender());
74 assertNull("Parent nested bean expression still in expression graph", inputField.getExpressionGraph().get(
75 "inquiry.render"));
76
77
78 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testNestedExpressionOverride5");
79 assertNotNull("No bean exists with id: testNestedExpressionOverride5", testBean);
80
81 assertEquals("Child property did not override", "old school",
82 testBean.getReference1().getReference1().getProperty1());
83 assertNull("Parent nested bean expression still in expression graph", inputField.getExpressionGraph().get(
84 "reference1.reference1.property1"));
85 }
86
87
88
89
90
91
92 @Test
93 public void testMergingOfMapExpressions() throws Exception {
94 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testExpressionMapMerging2");
95 assertNotNull("No bean exists with id: testExpressionMapMerging2", testBean);
96
97 assertTrue("Merged map is not correct size (2)", testBean.getMap1().size() == 2);
98 assertTrue("Merged map does not contain key2", testBean.getMap1().containsKey("key2"));
99 assertTrue("Merged map does not contain key3)", testBean.getMap1().containsKey("key3"));
100
101 assertTrue("Expression count not correct for merged map", testBean.getExpressionGraph().size() == 2);
102 assertEquals("Bean does not contain expression for property key1", "@{expr1}",
103 testBean.getExpressionGraph().get("map1['key1']"));
104 assertEquals("Bean does not contain expression for property key4", "@{expr4}",
105 testBean.getExpressionGraph().get("map1['key4']"));
106 }
107
108
109
110
111
112
113 @Test
114 public void testNonMergingOfMapExpressions() throws Exception {
115 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testExpressionMapNonMerging");
116 assertNotNull("No bean exists with id: testExpressionMapNonMerging", testBean);
117
118 assertTrue("Non-Merged map is not correct size (1)", testBean.getMap1().size() == 1);
119 assertTrue("Non-Merged map does not contain key3)", testBean.getMap1().containsKey("key3"));
120
121 assertTrue("Expression count not correct for non-merged map", testBean.getExpressionGraph().size() == 1);
122 assertEquals("Bean does not contain expression for property key4", "@{expr4}",
123 testBean.getExpressionGraph().get("map1['key4']"));
124 }
125
126
127
128
129
130
131
132
133 public void testNestedListExpressions() throws Exception {
134 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testListBeanExpressionMerging");
135 assertNotNull("No bean exists with id: testListBeanExpressionMerging", testBean);
136
137 Map<String, String> mergedMap = testBean.getListReference1().get(0).getReference1().getMap1();
138
139 assertTrue("Merged map is not correct size (2)", mergedMap.size() == 2);
140 assertTrue("Merged map does not contain key2", mergedMap.containsKey("key2"));
141 assertTrue("Merged map does not contain key3)", mergedMap.containsKey("key3"));
142
143 TestDictionaryBean rootListBean = testBean.getListReference1().get(0);
144
145 assertTrue("Expression count not correct for merged map", rootListBean.getExpressionGraph().size() == 2);
146 assertEquals("Bean does not contain expression for property key1", "@{expr1}",
147 rootListBean.getExpressionGraph().get("reference1.map1['key1']"));
148 assertEquals("Bean does not contain expression for property key1", "@{expr4}",
149 rootListBean.getExpressionGraph().get("reference1.map1['key4']"));
150 }
151
152
153
154
155
156
157 @Test
158 public void testListExpressions() throws Exception {
159
160 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testListExpressionMerging");
161 assertNotNull("No bean exists with id: testListExpressionMerging", testBean);
162
163 List<String> list1 = testBean.getList1();
164 assertTrue("List with expressions is not correct size", list1.size() == 6);
165 assertEquals("Second value in list is not correct", "val1", list1.get(0));
166 assertEquals("Fifth value in list is not correct", "val5", list1.get(4));
167
168 assertTrue("Expression graph for inheritance list not correct size", testBean.getExpressionGraph().size() == 4);
169 assertEquals("First expression in expression graph not correct", "@{expr2} before val",
170 testBean.getExpressionGraph().get("list1[1]"));
171 assertEquals("Second expression in expression graph not correct", "@{expr3}", testBean.getExpressionGraph().get(
172 "list1[2]"));
173 assertEquals("Third expression in expression graph not correct", "@{expr4}", testBean.getExpressionGraph().get(
174 "list1[3]"));
175 assertEquals("Fourth expression in expression graph not correct", "@{expr6}", testBean.getExpressionGraph().get(
176 "list1[5]"));
177 }
178
179
180
181
182
183
184 public void testNestedListMerging() throws Exception {
185 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testListMerging2");
186 assertNotNull("No bean exists with id: testListMerging2", testBean);
187
188 List<String> list1 = testBean.getReference1().getList1();
189 assertTrue("List with expressions is not correct size", list1.size() == 4);
190 assertEquals("First value in list not correct", "val1", list1.get(0));
191 assertEquals("Second value in list not correct", "val2", list1.get(0));
192 assertEquals("Third value in list not correct", "val3", list1.get(0));
193 assertEquals("Fourth value in list not correct", "val4", list1.get(0));
194 }
195
196
197
198
199
200
201 @Test
202 public void testPostProcessBeanFactoryWithSimpleInheritanceSucceeds() throws Exception {
203 TestDictionaryBean simpleBean1 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean1");
204 TestDictionaryBean simpleBean2 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean2");
205
206 assertEquals("Bean does not have the correct property3 value", simpleBean1.getExpressionGraph().get(
207 "property3"), "@{1 eq 1}");
208 assertNull("Bean should not have a property3 value", simpleBean2.getExpressionGraph().get("property3"));
209 }
210
211
212
213
214
215
216 @Test
217 public void testPostProcessBeanFactoryWithSimpleNestingSucceeds() throws Exception {
218 TestDictionaryBean simpleBean1 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean1");
219 TestDictionaryBean simpleBean4 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean4");
220
221 assertEquals("Bean does not have the correct property3 value", simpleBean1.getExpressionGraph().get(
222 "property3"), "@{1 eq 1}");
223 assertNull("Bean should not have a property3 value", simpleBean4.getExpressionGraph().get("property3"));
224 }
225
226
227
228
229
230
231 @Test
232 public void testPostProcessBeanFactoryWithPeopleFlowSucceeds() throws Exception {
233 InquiryView inquiryView = (InquiryView) getTestDictionaryObject("testPeopleFlow-InquiryView");
234
235 assertNotNull("Bean should have an inquiry property value", ((DataField) inquiryView.getItems().get(0)
236 .getItems().get(0)).getInquiry());
237 assertFalse("Bean should have an inquiry render value of false", ((DataField) inquiryView.getItems().get(0)
238 .getItems().get(0)).getInquiry().isRender());
239 }
240
241
242
243
244
245 @Test
246 public void testBeanDefinitionNaming() {
247 TestDictionaryBean testListBeanDefinitionNaming = (TestDictionaryBean) getTestDictionaryObject(
248 "testListBeanDefinitionNaming");
249
250 TestDictionaryBean uifTestBeanObject = testListBeanDefinitionNaming.getListReference1().get(0);
251 assertTrue("expression graph should have a property1", uifTestBeanObject.getExpressionGraph().containsKey(
252 "property1"));
253
254 TestDictionaryBean uifTestBeanObject1 = testListBeanDefinitionNaming.getListReference1().get(1);
255 assertTrue("expression graph should have a property1", uifTestBeanObject1.getExpressionGraph().containsKey(
256 "property1"));
257 }
258
259 }