KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > configuration > condition > JexlConditionParserTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.system.configuration.condition;
18
19 import org.apache.geronimo.testsupport.TestSupport;
20
21 /**
22  * Unit tests for the {@link JexlConditionParser} class.
23  *
24  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
25  */

26 public class JexlConditionParserTest
27     extends TestSupport
28 {
29     private JexlConditionParser parser;
30
31     protected void setUp() throws Exception JavaDoc {
32         parser = new JexlConditionParser();
33     }
34
35     protected void tearDown() throws Exception JavaDoc {
36         parser = null;
37     }
38
39     public void testTrue() throws Exception JavaDoc {
40         boolean result = parser.evaluate("true");
41         assertTrue(result);
42     }
43
44     public void testFalse() throws Exception JavaDoc {
45         boolean result = parser.evaluate("false");
46         assertTrue(!result);
47     }
48
49     public void testJavaIs1_1() throws Exception JavaDoc {
50         //
51
// Assume we never run in a 1.1 jvm
52
//
53
assertTrue(!SystemUtils.IS_JAVA_1_1);
54         boolean result = parser.evaluate("!java.is1_1");
55         assertTrue(result);
56     }
57
58     public void testJavaIs1_5() throws Exception JavaDoc {
59         boolean result = parser.evaluate("java.is1_5 " + (SystemUtils.IS_JAVA_1_5 ? "==" : "!=") + " true");
60         assertTrue(result);
61     }
62
63     public void testNonBooleanResult() throws Exception JavaDoc {
64         try {
65             parser.evaluate("java");
66             fail();
67         }
68         catch (ConditionParserException e) {
69             // expected
70
}
71     }
72
73     public void testBadSyntax() throws Exception JavaDoc {
74         try {
75             parser.evaluate("a b c d e f");
76             fail();
77         }
78         catch (ConditionParserException e) {
79             // expected
80
}
81     }
82
83     public void testInvalidVariableRef() throws Exception JavaDoc {
84         try {
85             parser.evaluate("nosuchvar");
86             fail();
87         }
88         catch (ConditionParserException e) {
89             // expected
90
}
91     }
92 }
93
Popular Tags