-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathValueExpressionImpl_test.dart
295 lines (226 loc) · 8.7 KB
/
ValueExpressionImpl_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//Copyright (C) 2012 Potix Corporation. All Rights Reserved.
//History: Mon, Sep 03, 2012 02:51:12 PM
// Author: hernichen
library ValueExpressionImpl_test;
import 'dart:mirrors';
import 'package:unittest/unittest.dart';
import 'package:rikulo_commons/mirrors.dart';
import 'package:rikulo_el/el.dart';
import 'TesterBeans.dart';
//@Test
void testGetValueReference() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
TesterBeanB beanB = new TesterBeanB();
beanB.name = "Tomcat";
ValueExpression var0 = elfactory.createVariable(beanB);
context.variableMapper.setVariable("beanB", var0);
ValueExpression ve = elfactory.createValueExpression(
context, "\${beanB.name}", STRING_MIRROR);
// First check the basics work
String result = ve.getValue(context);
expect(result, equals("Tomcat"));
// Now check the value reference
ValueReference vr = ve.getValueReference(context);
expect(vr, isNotNull);
expect(vr.base, equals(beanB));
expect(vr.property, equals("name"));
}
//@Test
void testGetValueReferenceVariable() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
TesterBeanB beanB = new TesterBeanB();
beanB.name = "Tomcat";
ValueExpression var0 = elfactory.createVariable(beanB);
context.variableMapper.setVariable("beanB", var0);
ValueExpression var2 = elfactory.createValueExpression(
context, "\${beanB.name}", STRING_MIRROR);
context.variableMapper.setVariable("foo", var2);
ValueExpression ve = elfactory.createValueExpression(
context, "\${foo}", reflect(var2).type);
// Now check the value reference
ValueReference vr = ve.getValueReference(context);
expect(vr, isNotNull);
expect(vr.base, equals(beanB));
expect(vr.property, equals("name"));
}
//@Test
void testBug49345() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
TesterBeanA beanA = new TesterBeanA();
TesterBeanB beanB = new TesterBeanB();
beanB.name = "Tomcat";
beanA.bean = beanB;
ValueExpression var0 = elfactory.createVariable(beanA);
context.variableMapper.setVariable("beanA", var0);
ValueExpression ve = elfactory.createValueExpression(
context, "\${beanA.bean.name}", STRING_MIRROR);
// First check the basics work
String result = ve.getValue(context);
expect(result, equals("Tomcat"));
// Now check the value reference
ValueReference vr = ve.getValueReference(context);
expect(vr, isNotNull);
expect(vr.base, equals(beanB));
expect(vr.property, equals("name"));
}
//@Test
//Enum is not supported yet
//void testBug50105() {
// ExpressionFactory elfactory = new ExpressionFactory();
// ELContext context = new ELContext();
//
// TesterEnum testEnum = TesterEnum.APPLE;
//
// ValueExpression var0 =
// elfactory.createValueExpression(testEnum, TesterEnum.class);
// context.variableMapper.setVariable("testEnum", var0);
//
// // When coercing an Enum to a String, name() should always be used.
// ValueExpression ve1 = elfactory.createValueExpression(
// context, "${testEnum}", String.class);
// String result1 = (String) ve1.getValue(context);
// assertEquals("APPLE", result1);
//
// ValueExpression ve2 = elfactory.createValueExpression(
// context, "foo${testEnum}bar", String.class);
// String result2 = (String) ve2.getValue(context);
// assertEquals("fooAPPLEbar", result2);
//}
//@Test
void testBug51177ObjectMap() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
Object o1 = "String value";
Object o2 = 32;
Map<Object,Object> map = new Map();
map["key1"] = o1;
map["key2"] = o2;
ValueExpression var0 = elfactory.createVariable(map);
context.variableMapper.setVariable("map", var0);
ValueExpression ve1 = elfactory.createValueExpression(
context, "\${map.key1}");
ve1.setValue(context, o2);
expect(ve1.getValue(context), equals(o2));
ValueExpression ve2 = elfactory.createValueExpression(
context, "\${map.key2}");
ve2.setValue(context, o1);
expect(ve2.getValue(context), equals(o1));
}
//@Test
void testBug51177ObjectList() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
Object o1 = "String value";
Object o2 = 32;
// List<Object> list = new List(2);
// list[0] = o1;
// list[1] = o2;
List<Object> list = new List();
list.add(o1);
list.add(o2);
ValueExpression var0 = elfactory.createVariable(list);
context.variableMapper.setVariable("list", var0);
ValueExpression ve1 = elfactory.createValueExpression(
context, "\${list[0]}");
ve1.setValue(context, o2);
expect(ve1.getValue(context), equals(o2));
ValueExpression ve2 = elfactory.createValueExpression(
context, "\${list[1]}");
ve2.setValue(context, o1);
expect(ve2.getValue(context), equals(o1));
}
/**
* Test returning an empty list as a bean property.
*/
//@Test
void testBug51544Bean() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
TesterBeanA beanA = new TesterBeanA();
beanA.valList = new List();
ValueExpression var0 = elfactory.createVariable(beanA);
context.variableMapper.setVariable("beanA", var0);
ValueExpression ve = elfactory.createValueExpression(
context, "\${beanA.valList.length}", INT_MIRROR);
int result = ve.getValue(context);
expect(result, equals(0));
}
/**
* Test using list directly as variable.
*/
//@Test
void testBug51544Direct() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
List list = new List();
ValueExpression var0 = elfactory.createVariable(list);
context.variableMapper.setVariable("list", var0);
ValueExpression ve = elfactory.createValueExpression(
context, "\${list.length}", INT_MIRROR);
int result = ve.getValue(context);
expect(result, 0);
}
//issue2
//@Test
void testMapExpression() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
Object o1 = "String value";
Object o2 = 32;
ValueExpression o1ve = elfactory.createVariable(o1);
context.variableMapper.setVariable("o1", o1ve);
ValueExpression o2ve = elfactory.createVariable(o2);
context.variableMapper.setVariable("o2", o2ve);
ValueExpression ve1 = elfactory.createValueExpression(
context, "#{{'key1':o1,'key2':o2}.key1}");
expect(ve1.getValue(context), equals(o1));
ValueExpression ve2 = elfactory.createValueExpression(
context, "#{{'key1':o1,'key2':o2}.key2}");
expect(ve2.getValue(context), equals(o2));
//map is temporary created for each evaluation (setValue once, getValue another)
ve1.setValue(context, o2);
expect(ve1.getValue(context) != o2, isTrue);
//map is temporary created for each evaluation (setValue once, getValue another)
ve2.setValue(context, o1);
expect(ve2.getValue(context) != o1, isTrue);
}
//issue1
//@Test
void testListExpression() {
ExpressionFactory elfactory = new ExpressionFactory();
ELContext context = new ELContext();
Object o1 = "String value";
Object o2 = 32;
ValueExpression o1ve = elfactory.createVariable(o1);
context.variableMapper.setVariable("o1", o1ve);
ValueExpression o2ve = elfactory.createVariable(o2);
context.variableMapper.setVariable("o2", o2ve);
ValueExpression ve1 = elfactory.createValueExpression(
context, "#{[o1, o2][0]}");
expect(ve1.getValue(context), equals(o1));
ValueExpression ve2 = elfactory.createValueExpression(
context, "\${[o1, o2][1]}");
expect(ve2.getValue(context), equals(o2));
//list is temporary created for each evaluation (setValue once, getValue another)
ve1.setValue(context, o2);
expect(ve1.getValue(context) != o2, isTrue);
//list is temporary created for each evaluation (setValue once, getValue another)
ve2.setValue(context, o1);
expect(ve2.getValue(context) != o1, isTrue);
}
//--------------------
void main() {
test('testGetValueReference', testGetValueReference);
test('testGetValueReferenceVariable', testGetValueReferenceVariable);
test('testBug49345', testBug49345);
//test('testBug50105', testBug50105); //enum test
test('testBug51177ObjectMap', testBug51177ObjectMap);
test('testBug51177ObjectList', testBug51177ObjectList);
test('testBug51544Bean', testBug51544Bean);
test('testBug51544Direct', testBug51544Direct);
test('testListExpression', testListExpression);
test('testMapExpression', testMapExpression);
}