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("testNestedExpressionOverride3");
63 assertNotNull("No bean exists with id: testNestedExpressionOverride3", inputField);
64
65 assertTrue("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 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testNestedExpressionOverride5");
71 assertNotNull("No bean exists with id: testNestedExpressionOverride5", testBean);
72
73 assertEquals("Child property did not override", "old school",
74 testBean.getReference1().getReference1().getProperty1());
75 assertNull("Parent nested bean expression still in expression graph", testBean.getExpressionGraph().get(
76 "reference1.reference1.property1"));
77 }
78
79
80
81
82
83
84 @Test
85 public void testMergingOfMapExpressions() throws Exception {
86 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testExpressionMapMerging2");
87 assertNotNull("No bean exists with id: testExpressionMapMerging2", testBean);
88
89 assertTrue("Merged map is not correct size (2)", testBean.getMap1().size() == 2);
90 assertTrue("Merged map does not contain key2", testBean.getMap1().containsKey("key2"));
91 assertTrue("Merged map does not contain key3)", testBean.getMap1().containsKey("key3"));
92
93 assertTrue("Expression count not correct for merged map", testBean.getExpressionGraph().size() == 2);
94 assertEquals("Bean does not contain expression for property key1", "@{expr1}",
95 testBean.getExpressionGraph().get("map1['key1']"));
96 assertEquals("Bean does not contain expression for property key4", "@{expr4}",
97 testBean.getExpressionGraph().get("map1['key4']"));
98 }
99
100
101
102
103
104
105 @Test
106 public void testNonMergingOfMapExpressions() throws Exception {
107 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testExpressionMapNonMerging");
108 assertNotNull("No bean exists with id: testExpressionMapNonMerging", testBean);
109
110 assertTrue("Non-Merged map is not correct size (1)", testBean.getMap1().size() == 1);
111 assertTrue("Non-Merged map does not contain key3)", testBean.getMap1().containsKey("key3"));
112
113 assertTrue("Expression count not correct for non-merged map", testBean.getExpressionGraph().size() == 1);
114 assertEquals("Bean does not contain expression for property key4", "@{expr4}",
115 testBean.getExpressionGraph().get("map1['key4']"));
116 }
117
118
119
120
121
122
123
124
125 public void testNestedListExpressions() throws Exception {
126 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testListBeanExpressionMerging");
127 assertNotNull("No bean exists with id: testListBeanExpressionMerging", testBean);
128
129 Map<String, String> mergedMap = testBean.getListReference1().get(0).getReference1().getMap1();
130
131 assertTrue("Merged map is not correct size (2)", mergedMap.size() == 2);
132 assertTrue("Merged map does not contain key2", mergedMap.containsKey("key2"));
133 assertTrue("Merged map does not contain key3)", mergedMap.containsKey("key3"));
134
135 TestDictionaryBean rootListBean = testBean.getListReference1().get(0);
136
137 assertTrue("Expression count not correct for merged map", rootListBean.getExpressionGraph().size() == 2);
138 assertEquals("Bean does not contain expression for property key1", "@{expr1}",
139 rootListBean.getExpressionGraph().get("reference1.map1['key1']"));
140 assertEquals("Bean does not contain expression for property key1", "@{expr4}",
141 rootListBean.getExpressionGraph().get("reference1.map1['key4']"));
142 }
143
144
145
146
147
148
149 @Test
150 public void testListExpressions() throws Exception {
151
152 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testListExpressionMerging");
153 assertNotNull("No bean exists with id: testListExpressionMerging", testBean);
154
155 List<String> list1 = testBean.getList1();
156 assertTrue("List with expressions is not correct size", list1.size() == 6);
157 assertEquals("Second value in list is not correct", "val1", list1.get(0));
158 assertEquals("Fifth value in list is not correct", "val5", list1.get(4));
159
160 assertTrue("Expression graph for inheritance list not correct size", testBean.getExpressionGraph().size() == 4);
161 assertEquals("First expression in expression graph not correct", "@{expr2} before val",
162 testBean.getExpressionGraph().get("list1[1]"));
163 assertEquals("Second expression in expression graph not correct", "@{expr3}", testBean.getExpressionGraph().get(
164 "list1[2]"));
165 assertEquals("Third expression in expression graph not correct", "@{expr4}", testBean.getExpressionGraph().get(
166 "list1[3]"));
167 assertEquals("Fourth expression in expression graph not correct", "@{expr6}", testBean.getExpressionGraph().get(
168 "list1[5]"));
169 }
170
171
172
173
174
175
176 public void testNestedListMerging() throws Exception {
177 TestDictionaryBean testBean = (TestDictionaryBean) getTestDictionaryObject("testListMerging2");
178 assertNotNull("No bean exists with id: testListMerging2", testBean);
179
180 List<String> list1 = testBean.getReference1().getList1();
181 assertTrue("List with expressions is not correct size", list1.size() == 4);
182 assertEquals("First value in list not correct", "val1", list1.get(0));
183 assertEquals("Second value in list not correct", "val2", list1.get(0));
184 assertEquals("Third value in list not correct", "val3", list1.get(0));
185 assertEquals("Fourth value in list not correct", "val4", list1.get(0));
186 }
187
188
189
190
191
192
193 @Test
194 public void testPostProcessBeanFactoryWithSimpleInheritanceSucceeds() throws Exception {
195 TestDictionaryBean simpleBean1 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean1");
196 TestDictionaryBean simpleBean2 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean2");
197
198 assertEquals("Bean does not have the correct property3 value", simpleBean1.getExpressionGraph().get(
199 "property3"), "@{1 eq 1}");
200 assertNull("Bean should not have a property3 value", simpleBean2.getExpressionGraph().get("property3"));
201 }
202
203
204
205
206
207
208 @Test
209 public void testPostProcessBeanFactoryWithSimpleNestingSucceeds() throws Exception {
210 TestDictionaryBean simpleBean1 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean1");
211 TestDictionaryBean simpleBean4 = (TestDictionaryBean) getTestDictionaryObject("testSimpleBean4");
212
213 assertEquals("Bean does not have the correct property3 value", simpleBean1.getExpressionGraph().get(
214 "property3"), "@{1 eq 1}");
215 assertNull("Bean should not have a property3 value", simpleBean4.getExpressionGraph().get("property3"));
216 }
217
218
219
220
221
222 @Test
223 public void testBeanDefinitionNaming() {
224 TestDictionaryBean testListBeanDefinitionNaming = (TestDictionaryBean) getTestDictionaryObject(
225 "testListBeanDefinitionNaming");
226
227 TestDictionaryBean uifTestBeanObject = testListBeanDefinitionNaming.getListReference1().get(0);
228 assertTrue("expression graph should have a property1", uifTestBeanObject.getExpressionGraph().containsKey(
229 "property1"));
230
231 TestDictionaryBean uifTestBeanObject1 = testListBeanDefinitionNaming.getListReference1().get(1);
232 assertTrue("expression graph should have a property1", uifTestBeanObject1.getExpressionGraph().containsKey(
233 "property1"));
234 }
235
236 }