01: /**
02: *
03: * Copyright 2004 Protique Ltd
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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.activemq.mockrunner.test;
18:
19: import junit.framework.TestCase;
20:
21: import org.activemq.filter.mockrunner.ComparisonExpression;
22: import org.activemq.filter.mockrunner.Expression;
23: import org.activemq.filter.mockrunner.ExpressionFilter;
24: import org.activemq.filter.mockrunner.Filter;
25: import org.activemq.filter.mockrunner.LogicExpression;
26: import org.activemq.filter.mockrunner.PropertyExpression;
27: import org.activemq.selector.mockrunner.SelectorParser;
28:
29: /**
30: * Alwin Ibba: Changed package
31: *
32: * @version $Revision: 1.3 $
33: */
34: public class SelectorParserTest extends TestCase {
35:
36: public void testParseWithParensAround() throws Exception {
37: String[] values = { "x = 1 and y = 2", "(x = 1) and (y = 2)",
38: "((x = 1) and (y = 2))" };
39:
40: for (int i = 0; i < values.length; i++) {
41: String value = values[i];
42: System.out.println("Parsing: " + value);
43:
44: Filter filter = parse(value);
45: assertTrue("Created ExpressionFilter filter",
46: filter instanceof ExpressionFilter);
47: Expression andExpression = ((ExpressionFilter) filter)
48: .getExpression();
49: assertTrue("Created LogicExpression expression",
50: andExpression instanceof LogicExpression);
51: LogicExpression logicExpression = (LogicExpression) andExpression;
52: Expression left = logicExpression.getLeft();
53: Expression right = logicExpression.getRight();
54:
55: assertTrue("Left is a binary filter",
56: left instanceof ComparisonExpression);
57: assertTrue("Right is a binary filter",
58: right instanceof ComparisonExpression);
59: ComparisonExpression leftCompare = (ComparisonExpression) left;
60: ComparisonExpression rightCompare = (ComparisonExpression) right;
61: assertPropertyExpression("left", leftCompare.getLeft(), "x");
62: assertPropertyExpression("right", rightCompare.getLeft(),
63: "y");
64: }
65: }
66:
67: protected void assertPropertyExpression(String message,
68: Expression expression, String expected) {
69: assertTrue(message + ". Must be PropertyExpression",
70: expression instanceof PropertyExpression);
71: PropertyExpression propExp = (PropertyExpression) expression;
72: assertEquals(message + ". Property name", expected, propExp
73: .getName());
74: }
75:
76: protected Filter parse(String text) throws Exception {
77: return new SelectorParser().parse(text);
78: }
79: }
|