KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > TestParsingInheritanceFilter


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo;
19
20 import org.objectweb.medor.expression.api.Expression;
21 import org.objectweb.medor.expression.lib.BasicOperand;
22 import org.objectweb.medor.expression.lib.BasicVariableOperand;
23 import org.objectweb.medor.expression.lib.ConditionalAnd;
24 import org.objectweb.medor.expression.lib.Equal;
25 import org.objectweb.medor.expression.lib.Greater;
26 import org.objectweb.medor.expression.lib.GreaterEqual;
27 import org.objectweb.medor.expression.lib.Lower;
28 import org.objectweb.medor.expression.lib.LowerEqual;
29 import org.objectweb.medor.expression.lib.NotEqual;
30 import org.objectweb.medor.filter.TestExpressionHelper;
31 import org.objectweb.speedo.api.ExceptionHelper;
32 import org.objectweb.speedo.generation.jorm.rdb.FilterManager;
33 import org.objectweb.util.monolog.Monolog;
34 import org.objectweb.util.monolog.api.BasicLevel;
35 import org.objectweb.util.monolog.api.Logger;
36
37 import junit.framework.TestCase;
38
39 /**
40  *
41  * @author S.Chassande-Barrioz
42  */

43 public class TestParsingInheritanceFilter extends TestCase {
44
45     private static final String JavaDoc[] filters = {
46         "(col1 == 12)",
47         "(col1 == \"AZERTY\")",
48         "(col1 != 12)",
49         "(col1 > 12)",
50         "(col1 >= 12)",
51         "(col1 < 12)",
52         "(col1 <= 12)",
53         "((col1 <= 12) && (col1 >= 3))",
54         "((col1 <= 12) && (col1 >= 3) && (col2 == 3)) ",
55     };
56
57     private static final Expression[] expressions = {
58         new Equal(new BasicVariableOperand("col1"), new BasicOperand(12)),
59         new Equal(new BasicVariableOperand("col1"), new BasicOperand("AZERTY")),
60         new NotEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
61         new Greater(new BasicVariableOperand("col1"), new BasicOperand(12)),
62         new GreaterEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
63         new Lower(new BasicVariableOperand("col1"), new BasicOperand(12)),
64         new LowerEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
65         new ConditionalAnd(
66             new LowerEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
67             new GreaterEqual(new BasicVariableOperand("col1"), new BasicOperand(3))),
68         new ConditionalAnd(
69             new LowerEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
70             new ConditionalAnd(
71                 new GreaterEqual(new BasicVariableOperand("col1"), new BasicOperand(3)),
72                 new Equal(new BasicVariableOperand("col2"), new BasicOperand(3))))
73     };
74
75     private static Logger logger = null;
76
77
78     public TestParsingInheritanceFilter(String JavaDoc s) {
79         super(s);
80         if (logger == null) {
81             logger = Monolog.initialize().getLogger(getClass().getName());
82         }
83     }
84
85     public void testA() {
86         FilterManager parser = new FilterManager(logger);
87         for(int i=0; i<filters.length; i++) {
88             logger.log(BasicLevel.DEBUG, "Parsing of filter: " + filters[i]);
89             try {
90                 Expression exp = parser.getParser().parse(filters[i]);
91                 TestExpressionHelper.equals("", expressions[i], exp, logger);
92             } catch (Error JavaDoc e) {
93                 fail(e.getMessage());
94             } catch (Exception JavaDoc e) {
95                 Exception JavaDoc ie = ExceptionHelper.getNested(e);
96                 logger.log(BasicLevel.ERROR, "Error during the parsing of filter: " + filters[i], ie);
97                 fail(e.getMessage());
98             }
99         }
100     }
101 }
102
Popular Tags