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.tree.impl.ast;
17:
18: import javax.el.ELException;
19:
20: import de.odysseus.el.TestCase;
21:
22: public class AstChoiceTest extends TestCase {
23: AstChoice parseNode(String expression) {
24: return (AstChoice) parse(expression).getRoot().getChild(0);
25: }
26:
27: public void testEval() {
28: assertEquals(1l, parseNode("${true?1:2}").eval(null, null));
29: assertEquals(2l, parseNode("${false?1:2}").eval(null, null));
30: }
31:
32: public void testAppendStructure() {
33: StringBuilder s = new StringBuilder();
34: parseNode("${a?b:c}").appendStructure(s, null);
35: assertEquals("a ? b : c", s.toString());
36: }
37:
38: public void testIsLiteralText() {
39: assertFalse(parseNode("${a?b:c}").isLiteralText());
40: }
41:
42: public void testIsLeftValue() {
43: assertFalse(parseNode("${a?b:c}").isLeftValue());
44: }
45:
46: public void testGetType() {
47: assertNull(parseNode("${a?b:c}").getType(null, null));
48: }
49:
50: public void testIsReadOnly() {
51: assertTrue(parseNode("${a?b:c}").isReadOnly(null, null));
52: }
53:
54: public void testSetValue() {
55: try {
56: parseNode("${a?b:c}").setValue(null, null, null);
57: fail();
58: } catch (ELException e) {
59: }
60: }
61:
62: public void testGetValue() {
63: assertEquals(1l, parseNode("${true?1:2}").getValue(null, null,
64: null));
65: assertEquals("1", parseNode("${true?1:2}").getValue(null, null,
66: String.class));
67: }
68: }
|