01: /*
02: * Copyright 2006, 2007 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.el;
17:
18: import de.odysseus.el.util.SimpleContext;
19: import de.odysseus.el.util.SimpleResolver;
20:
21: public class ExpressionFactoryImplTest extends TestCase {
22:
23: public static long bar() {
24: return 1;
25: }
26:
27: private ExpressionFactoryImpl factory = new ExpressionFactoryImpl();
28:
29: public void testCoerceToType() {
30: assertEquals("1", factory.coerceToType(1l, String.class));
31: }
32:
33: public void testCreateTreeValueExpression() {
34: SimpleContext context = new SimpleContext(new SimpleResolver());
35: assertEquals(1l, factory.createValueExpression(context, "${1}",
36: Object.class).getValue(context));
37: }
38:
39: public void testCreateObjectValueExpression() {
40: SimpleContext context = new SimpleContext(new SimpleResolver());
41: assertEquals("1", factory.createValueExpression("1",
42: Object.class).getValue(context));
43: }
44:
45: public void testCreateMethodExpression()
46: throws NoSuchMethodException {
47: SimpleContext context = new SimpleContext(new SimpleResolver());
48: context.getELResolver().setValue(context, null, "foo", this );
49: assertEquals(bar(), factory.createMethodExpression(context,
50: "${foo.bar}", null, new Class[0]).invoke(context, null));
51: }
52: }
|