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