1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import org.junit.Test;
19 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import static junit.framework.Assert.*;
25
26
27
28
29
30
31 public class ExpressionUtilsTest {
32
33
34
35
36
37
38
39
40 @Test
41 public void testPopulatePropertyExpressionsFromGraph() {
42 Map<String, String> expressionGraph = new HashMap<String, String>();
43
44 expressionGraph.put("property1", "@{expr1}");
45 expressionGraph.put("property2", "@{expr2}");
46 expressionGraph.put("property3['key1']", "@{key1expr}");
47 expressionGraph.put("property4.property1", "@{nexpr1}");
48 expressionGraph.put("property4.property4.property3['key2']", "@{nkey2expr}");
49
50 MockConfigurable configurable = new MockConfigurable();
51 MockConfigurable configurable2 = new MockConfigurable();
52 MockConfigurable configurable3 = new MockConfigurable();
53
54 configurable2.setProperty4(configurable3);
55 configurable.setProperty4(configurable2);
56
57 configurable.setExpressionGraph(expressionGraph);
58
59 ExpressionUtils.populatePropertyExpressionsFromGraph(configurable, false);
60
61 assertEquals("Expression count not correct in root configurable", 3,
62 configurable.getPropertyExpressions().size());
63 assertEquals("Expression not correct for property1", "@{expr1}", configurable.getPropertyExpression(
64 "property1"));
65 assertEquals("Expression not correct for property2", "@{expr2}", configurable.getPropertyExpression(
66 "property2"));
67 assertEquals("Expression not correct for map property3", "@{key1expr}", configurable.getPropertyExpression(
68 "property3['key1']"));
69
70 assertEquals("Expression count not correct in nested configurable", 1,
71 configurable.getProperty4().getPropertyExpressions().size());
72 assertEquals("Expression not correct for nested property1", "@{nexpr1}",
73 configurable.getProperty4().getPropertyExpression("property1"));
74
75 assertEquals("Expression count not correct in two level nested configurable", 1,
76 configurable.getProperty4().getProperty4().getPropertyExpressions().size());
77 assertEquals("Expression not correct for nested map property3", "@{nkey2expr}",
78 configurable.getProperty4().getProperty4().getPropertyExpression("property3['key2']"));
79 }
80
81
82
83
84 @Test
85 public void testPopulatePropertyExpressionsFromGraph_RefreshGraphs() {
86 Map<String, String> expressionGraph = new HashMap<String, String>();
87
88 expressionGraph.put("property1", "@{expr1}");
89 expressionGraph.put("property2", "@{expr2}");
90 expressionGraph.put("property3['key1']", "@{key1expr}");
91 expressionGraph.put("property4.property1", "@{nexpr1}");
92 expressionGraph.put("property4.property4.property3['key2']", "@{nkey2expr}");
93
94 MockConfigurable configurable = new MockConfigurable();
95 MockConfigurable configurable2 = new MockConfigurable();
96 MockConfigurable configurable3 = new MockConfigurable();
97
98 configurable2.setProperty4(configurable3);
99 configurable.setProperty4(configurable2);
100
101 configurable.setExpressionGraph(expressionGraph);
102
103 ExpressionUtils.populatePropertyExpressionsFromGraph(configurable, true);
104
105 assertEquals("Refresh expression count not correct in root configurable", 5,
106 configurable.getRefreshExpressionGraph().size());
107 assertEquals("Refresh expression count not correct in nested configurable", 2,
108 configurable.getProperty4().getRefreshExpressionGraph().size());
109 assertEquals("Refresh expression count not correct in two level nested configurable", 1,
110 configurable.getProperty4().getProperty4().getRefreshExpressionGraph().size());
111 }
112
113
114
115
116 public class MockConfigurable extends UifDictionaryBeanBase {
117 private String property1;
118 private String property2;
119
120 private Map<String, String> property3;
121 private MockConfigurable property4;
122
123 public MockConfigurable() {
124 property3 = new HashMap<String, String>();
125 }
126
127 public String getProperty1() {
128 return property1;
129 }
130
131 public void setProperty1(String property1) {
132 this.property1 = property1;
133 }
134
135 public String getProperty2() {
136 return property2;
137 }
138
139 public void setProperty2(String property2) {
140 this.property2 = property2;
141 }
142
143 public Map<String, String> getProperty3() {
144 return property3;
145 }
146
147 public void setProperty3(Map<String, String> property3) {
148 this.property3 = property3;
149 }
150
151 public MockConfigurable getProperty4() {
152 return property4;
153 }
154
155 public void setProperty4(MockConfigurable property4) {
156 this.property4 = property4;
157 }
158 }
159 }