-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMethodExpressionImpl_test.dart
532 lines (437 loc) · 17.2 KB
/
MethodExpressionImpl_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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
//Copyright (C) 2012 Potix Corporation. All Rights Reserved.
//History: Tue, Sep 25, 2012 11:53:01 AM
// Author: hernichen
library MethodExpressionImpl_test;
import 'dart:mirrors';
import 'package:unittest/unittest.dart';
import 'package:rikulo_commons/mirrors.dart';
import 'package:rikulo_el/el.dart';
import 'TesterBeans.dart';
final String _BUG53792 = "TEST_PASS";
ExpressionFactory _elfactory;
ELContext _context;
TesterBeanB _beanB;
//@Before
void setUp() {
_elfactory = new ExpressionFactory();
_context = new ELContext();
TesterBeanA beanA = new TesterBeanA();
beanA.setName("A");
_context.variableMapper.setVariable("beanA",
_elfactory.createVariable(beanA));
TesterBeanAA beanAA = new TesterBeanAA();
beanAA.setName("AA");
_context.variableMapper.setVariable("beanAA",
_elfactory.createVariable(beanAA));
TesterBeanAAA beanAAA = new TesterBeanAAA();
beanAAA.setName("AAA");
_context.variableMapper.setVariable("beanAAA",
_elfactory.createVariable(beanAAA));
_beanB = new TesterBeanB();
_beanB.setName("B");
_context.variableMapper.setVariable("_beanB",
_elfactory.createVariable(_beanB));
TesterBeanBB beanBB = new TesterBeanBB();
beanBB.setName("BB");
_context.variableMapper.setVariable("beanBB",
_elfactory.createVariable(beanBB));
TesterBeanBBB beanBBB = new TesterBeanBBB();
beanBBB.setName("BBB");
_context.variableMapper.setVariable("beanBBB",
_elfactory.createVariable(beanBBB));
TesterBeanC beanC = new TesterBeanC();
_context.variableMapper.setVariable("beanC",
_elfactory.createVariable(beanC));
// TesterBeanEnum beanEnum = new TesterBeanEnum();
// _context.variableMapper.setVariable("beanEnum",
// _elfactory.createVariable(type));
}
//@Test
void testIsParametersProvided() {
setUp();
TesterBeanB _beanB = new TesterBeanB();
_beanB.setName("Tomcat");
ValueExpression var0 = _elfactory.createVariable(_beanB);
_context.variableMapper.setVariable("_beanB", var0);
MethodExpression me1 = _elfactory.createMethodExpression(
_context, "\${_beanB.getName}", STRING_MIRROR);
MethodExpression me2 = _elfactory.createMethodExpression(
_context, "\${_beanB.sayHello('JUnit')}", STRING_MIRROR);
expect(me1.isParametersProvided, isFalse);
expect(me2.isParametersProvided, isTrue);
}
//@Test
void testInvoke() {
setUp();
TesterBeanB _beanB = new TesterBeanB();
_beanB.setName("B");
_context.variableMapper.setVariable("_beanB",
_elfactory.createVariable(_beanB));
MethodExpression me1 = _elfactory.createMethodExpression(
_context, "\${_beanB.getName}", STRING_MIRROR);
MethodExpression me2 = _elfactory.createMethodExpression(
_context, "\${_beanB.sayHello('JUnit')}", STRING_MIRROR);
MethodExpression me3 = _elfactory.createMethodExpression(
_context, "\${_beanB.sayHello}", STRING_MIRROR);
expect(me1.invoke(_context, null), equals("B"));
expect(me2.invoke(_context, null), equals("Hello JUnit from B"));
expect(me2.invoke(_context, ["JUnit2"]), equals("Hello JUnit from B"));
expect(me3.invoke(_context, ["JUnit2"]), equals("Hello JUnit2 from B"));
expect(me2.invoke(_context, [null]), equals("Hello JUnit from B"));
expect(me3.invoke(_context, [null]), equals("Hello from B"));
}
//@Test
void testInvokeWithSuper() {
setUp();
MethodExpression me = _elfactory.createMethodExpression(_context,
"\${beanA.setBean(beanBB)}", null );
me.invoke(_context, null);
ValueExpression ve = _elfactory.createValueExpression(_context,
"\${beanA.bean.name}", STRING_MIRROR);
Object r = ve.getValue(_context);
expect(r, equals("BB"));
}
//@Test
void testInvokeWithSuperABNoReturnTypeNoParamTypes() {
setUp();
MethodExpression me2 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2B(beanA,_beanB)}", null);
Object r2 = me2.invoke(_context, null);
expect(r2.toString(), equals("AB: Hello A from B"));
}
//@Test
void testInvokeWithSuperABReturnTypeNoParamTypes() {
setUp();
MethodExpression me3 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2B(beanA,_beanB)}", STRING_MIRROR);
Object r3 = me3.invoke(_context, null);
expect(r3.toString(), equals("AB: Hello A from B"));
}
//@Test
void testInvokeWithSuperABNoReturnTypeParamTypes() {
setUp();
MethodExpression me4 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2B(beanA,_beanB)}", null);
Object r4 = me4.invoke(_context, null);
expect(r4.toString(), equals("AB: Hello A from B"));
}
//@Test
void testInvokeWithSuperABReturnTypeParamTypes() {
setUp();
MethodExpression me5 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2B(beanA,_beanB)}", STRING_MIRROR);
Object r5 = me5.invoke(_context, null);
expect(r5.toString(), equals("AB: Hello A from B"));
}
//@Test
void testInvokeWithSuperABB() {
setUp();
MethodExpression me6 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BB(beanA,beanBB)}", null);
Object r6 = me6.invoke(_context, null);
expect(r6.toString(), equals("ABB: Hello A from BB"));
}
//@Test
void testInvokeWithSuperABBB() {
setUp();
MethodExpression me7 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BB(beanA,beanBBB)}", null);
Object r7 = me7.invoke(_context, null);
expect(r7.toString(), equals("ABB: Hello A from BBB"));
}
//@Test
void testInvokeWithSuperAAB() {
setUp();
MethodExpression me8 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloAA2B(beanAA,_beanB)}", null);
Object r8 = me8.invoke(_context, null);
expect(r8.toString(), equals("AAB: Hello AA from B"));
}
//@Test
void testInvokeWithSuperAABB() {
setUp();
MethodExpression me9 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloAA2BB(beanAA,beanBB)}", null);
Exception e = null;
try {
me9.invoke(_context, null);
} on Exception catch (e1) {
e = e1;
}
// Expected to fail
expect(e, isNotNull);
}
//@Test
void testInvokeWithSuperAABBB() {
setUp();
// The Java compiler reports this as ambiguous. Using the parameter that
// matches exactly seems reasonable to limit the scope of the method
// search so the EL will find a match.
MethodExpression me10 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloAA2B(beanAA,beanBBB)}", null);
Object r10 = me10.invoke(_context, null);
expect(r10.toString(), equals("AAB: Hello AA from BBB"));
}
//@Test
void testInvokeWithSuperAAAB() {
setUp();
MethodExpression me11 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloAA2B(beanAAA,_beanB)}", null);
Object r11 = me11.invoke(_context, null);
expect(r11.toString(), equals("AAB: Hello AAA from B"));
}
//@Test
void testInvokeWithSuperAAABB() {
setUp();
// The Java compiler reports this as ambiguous. Using the parameter that
// matches exactly seems reasonable to limit the scope of the method
// search so the EL will find a match.
MethodExpression me12 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BB(beanAAA,beanBB)}", null);
Object r12 = me12.invoke(_context, null);
expect(r12.toString(), equals("ABB: Hello AAA from BB"));
}
//@Test
void testInvokeWithSuperAAABBB() {
setUp();
MethodExpression me13 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloAA2BB(beanAAA,beanBBB)}", null);
Exception e = null;
try {
me13.invoke(_context, null);
} on Exception catch (e1) {
e = e1;
}
// Expected to fail
expect(e, isNotNull);
}
//@Test
void testInvokeWithVarArgsAB() {
setUp();
MethodExpression me1 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanA,[_beanB,_beanB])}", null);
Object r = me1.invoke(_context, null);
expect(r.toString(), equals("ABB[]: Hello A from B, B"));
}
//@Test
void testInvokeWithVarArgsABB() {
setUp();
MethodExpression me2 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanA,[beanBB,beanBB])}", null);
Object r2 = me2.invoke(_context, null);
expect(r2.toString(), equals("ABB[]: Hello A from BB, BB"));
}
//@Test
void testInvokeWithVarArgsABBB() {
setUp();
MethodExpression me3 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanA,[beanBBB,beanBBB])}", null);
Object r3 = me3.invoke(_context, null);
expect(r3.toString(), equals("ABB[]: Hello A from BBB, BBB"));
}
//@Test
void testInvokeWithVarArgsAAB() {
setUp();
MethodExpression me4 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanAA,[_beanB,_beanB])}", null);
Object r = me4.invoke(_context, null);
expect(r.toString(), equals('ABB[]: Hello AA from B, B'));
}
//@Test
void testInvokeWithVarArgsAABB() {
setUp();
MethodExpression me5 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanAA,[beanBB,beanBB])}", null);
Object r5 = me5.invoke(_context, null);
expect(r5.toString(), equals("ABB[]: Hello AA from BB, BB"));
}
//@Test
void testInvokeWithVarArgsAABBB() {
setUp();
MethodExpression me6 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanAA,[beanBBB,beanBBB])}", null);
Object r6 = me6.invoke(_context, null);
expect(r6.toString(), equals("ABB[]: Hello AA from BBB, BBB"));
}
//@Test
void testInvokeWithVarArgsAAAB() {
setUp();
MethodExpression me7 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanAAA,[_beanB,_beanB])}", null);
Object r = me7.invoke(_context, null);
expect(r.toString(), equals('ABB[]: Hello AAA from B, B'));
}
//@Test
void testInvokeWithVarArgsAAABB() {
setUp();
MethodExpression me8 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanAAA,[beanBB,beanBB])}", null);
Object r8 = me8.invoke(_context, null);
expect(r8.toString(), equals("ABB[]: Hello AAA from BB, BB"));
}
//@Test
void testInvokeWithVarArgsAAABBB() {
setUp();
MethodExpression me9 = _elfactory.createMethodExpression(_context,
"\${beanC.sayHelloA2BBs(beanAAA,[beanBBB,beanBBB])}", null);
Object r9 = me9.invoke(_context, null);
expect(r9.toString(), equals("ABB[]: Hello AAA from BBB, BBB"));
}
/*
* This is also tested implicitly in numerous places elsewhere in this
* class.
*/
//@Test
void testBug49655() {
setUp();
// This is the call the failed
MethodExpression me = _elfactory.createMethodExpression(_context,
"#{beanA.setName('New value')}", null);
// The rest is to check it worked correctly
me.invoke(_context, null);
ValueExpression ve = _elfactory.createValueExpression(_context,
"#{beanA.name}", STRING_MIRROR);
expect(ve.getValue(_context), equals("New value"));
}
//@Test
void testBugPrimitives() {
setUp();
MethodExpression me = _elfactory.createMethodExpression(_context,
"\${beanA.setValLong(5)}", null);
me.invoke(_context, null);
ValueExpression ve = _elfactory.createValueExpression(_context,
"#{beanA.valLong}", STRING_MIRROR);
expect(ve.getValue(_context), equals("5"));
}
//@Test
void testBug50449a() {
setUp();
MethodExpression me1 = _elfactory.createMethodExpression(_context,
"\${_beanB.sayHello()}", null);
String actual = me1.invoke(_context, null);
expect(actual, equals("Hello from B"));
}
//@Test
void testBug50449b() {
setUp();
MethodExpression me1 = _elfactory.createMethodExpression(_context,
"\${_beanB.sayHello('Tomcat')}", null);
String actual = me1.invoke(_context, null);
expect(actual, equals("Hello Tomcat from B"));
}
//@Test
void testBug50790a() {
setUp();
ValueExpression ve = _elfactory.createValueExpression(_context,
"#{beanAA.name.contains(beanA.name)}", BOOL_MIRROR);
bool actual = ve.getValue(_context);
expect(actual, equals(true));
}
//@Test
void testBug50790b() {
setUp();
ValueExpression ve = _elfactory.createValueExpression(_context,
"#{beanA.name.contains(beanAA.name)}", BOOL_MIRROR);
bool actual = ve.getValue(_context);
expect(actual, equals(false));
}
//@Test
void testBug52445a() {
setUp();
MethodExpression me = _elfactory.createMethodExpression(_context,
"\${beanA.setBean(beanBB)}", null);
me.invoke(_context, null);
MethodExpression me1 = _elfactory.createMethodExpression(_context,
"\${beanA.bean.sayHello()}", null);
String actual = me1.invoke(_context, null);
expect(actual, equals("Hello from BB"));
}
//TODO(henri): Enum is not supported yet
//@Test
//void testBug52970() {
// setUp();
//
// MethodExpression me = _elfactory.createMethodExpression(_context,
// "\${beanEnum.submit('APPLE')}", null);
// me.invoke(_context, null);
//
// ValueExpression ve = _elfactory.createValueExpression(_context,
// "#{beanEnum.lastSubmitted}", reflect(beanEnum).type);
// TesterEnum actual = ve.getValue(_context);
// expect(actual, equals(TesterEnum.APPLE));
//
//}
//@Test
void testBug53792a() {
setUp();
MethodExpression me = _elfactory.createMethodExpression(_context,
"\${beanA.setBean(_beanB)}", null);
me.invoke(_context, null);
me = _elfactory.createMethodExpression(_context,
"\${_beanB.setName('$_BUG53792')}", null);
me.invoke(_context, null);
ValueExpression ve = _elfactory.createValueExpression(_context,
"#{beanA.getBean().name}", STRING_MIRROR);
String actual = ve.getValue(_context);
expect(actual, equals(_BUG53792));
}
//@Test
void testBug53792b() {
setUp();
MethodExpression me = _elfactory.createMethodExpression(_context,
"\${beanA.setBean(_beanB)}", null);
me.invoke(_context, null);
me = _elfactory.createMethodExpression(_context,
"\${_beanB.setName('$_BUG53792')}", null);
me.invoke(_context, null);
ValueExpression ve = _elfactory.createValueExpression(_context,
"#{beanA.getBean().name.length}", INT_MIRROR);
int actual = ve.getValue(_context);
expect(actual, equals(_BUG53792.length));
}
//@Test
void testBug53792c() {
setUp();
MethodExpression me = _elfactory.createMethodExpression(_context,
"#{_beanB.sayHello().length}", null);
int result = me.invoke(_context, null);
expect(result, equals(_beanB.sayHello().length));
}
//--------------------
void main() {
// test('testIsParametersProvided', testIsParametersProvided);
// test('testInvoke', testInvoke);
// test('testInvokeWithSuper', testInvokeWithSuper);
// test('testInvokeWithSuperABNoReturnTypeNoParamTypes', testInvokeWithSuperABNoReturnTypeNoParamTypes);
// test('testInvokeWithSuperABReturnTypeNoParamTypes', testInvokeWithSuperABReturnTypeNoParamTypes);
// test('testInvokeWithSuperABNoReturnTypeParamTypes', testInvokeWithSuperABNoReturnTypeParamTypes);
// test('testInvokeWithSuperABReturnTypeParamTypes', testInvokeWithSuperABReturnTypeParamTypes);
// test('testInvokeWithSuperABB', testInvokeWithSuperABB);
// test('testInvokeWithSuperABBB', testInvokeWithSuperABBB);
// test('testInvokeWithSuperAAB', testInvokeWithSuperAAB);
// test('testInvokeWithSuperAABB', testInvokeWithSuperAABB);
// test('testInvokeWithSuperAABBB', testInvokeWithSuperAABBB);
// test('testInvokeWithSuperAAAB', testInvokeWithSuperAAAB);
// test('testInvokeWithSuperAAABB', testInvokeWithSuperAAABB);
// test('testInvokeWithSuperAAABBB', testInvokeWithSuperAAABBB);
test('testInvokeWithVarArgsAB', testInvokeWithVarArgsAB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsABB', testInvokeWithVarArgsABB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsABBB', testInvokeWithVarArgsABBB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsAAB', testInvokeWithVarArgsAAB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsAABB', testInvokeWithVarArgsAABB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsAABBB', testInvokeWithVarArgsAABBB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsAAAB', testInvokeWithVarArgsAAAB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsAAABB', testInvokeWithVarArgsAAABB); //TODO(henri): not support [a1,a2,a3] expression yet
test('testInvokeWithVarArgsAAABBB', testInvokeWithVarArgsAAABBB); //TODO(henri): not support [a1,a2,a3] expression yet
// test('testBug49655', testBug49655);
// test('testBugPrimitives', testBugPrimitives);
// test('testBug50449a', testBug50449a);
// test('testBug50449b', testBug50449b);
// test('testBug50790a', testBug50790a);
// test('testBug50790b', testBug50790b);
// test('testBug52445a', testBug52445a);
// //test('testBug52970', testBug52970); //TODO(henri): not support Enum yet
// test('testBug53792a', testBug53792a);
// test('testBug53792b', testBug53792b);
// test('testBug53792c', testBug53792c);
}