001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo;
018:
019: import org.objectweb.medor.expression.api.Expression;
020: import org.objectweb.medor.expression.lib.BasicOperand;
021: import org.objectweb.medor.expression.lib.BasicVariableOperand;
022: import org.objectweb.medor.expression.lib.ConditionalAnd;
023: import org.objectweb.medor.expression.lib.Equal;
024: import org.objectweb.medor.expression.lib.Greater;
025: import org.objectweb.medor.expression.lib.GreaterEqual;
026: import org.objectweb.medor.expression.lib.Lower;
027: import org.objectweb.medor.expression.lib.LowerEqual;
028: import org.objectweb.medor.expression.lib.NotEqual;
029: import org.objectweb.medor.filter.TestExpressionHelper;
030: import org.objectweb.speedo.api.ExceptionHelper;
031: import org.objectweb.speedo.generation.jorm.rdb.FilterManager;
032: import org.objectweb.util.monolog.Monolog;
033: import org.objectweb.util.monolog.api.BasicLevel;
034: import org.objectweb.util.monolog.api.Logger;
035:
036: import junit.framework.TestCase;
037:
038: /**
039: *
040: * @author S.Chassande-Barrioz
041: */
042: public class TestParsingInheritanceFilter extends TestCase {
043:
044: private static final String[] filters = { "(col1 == 12)",
045: "(col1 == \"AZERTY\")", "(col1 != 12)", "(col1 > 12)",
046: "(col1 >= 12)", "(col1 < 12)", "(col1 <= 12)",
047: "((col1 <= 12) && (col1 >= 3))",
048: "((col1 <= 12) && (col1 >= 3) && (col2 == 3)) ", };
049:
050: private static final Expression[] expressions = {
051: new Equal(new BasicVariableOperand("col1"),
052: new BasicOperand(12)),
053: new Equal(new BasicVariableOperand("col1"),
054: new BasicOperand("AZERTY")),
055: new NotEqual(new BasicVariableOperand("col1"),
056: new BasicOperand(12)),
057: new Greater(new BasicVariableOperand("col1"),
058: new BasicOperand(12)),
059: new GreaterEqual(new BasicVariableOperand("col1"),
060: new BasicOperand(12)),
061: new Lower(new BasicVariableOperand("col1"),
062: new BasicOperand(12)),
063: new LowerEqual(new BasicVariableOperand("col1"),
064: new BasicOperand(12)),
065: new ConditionalAnd(new LowerEqual(new BasicVariableOperand(
066: "col1"), new BasicOperand(12)), new GreaterEqual(
067: new BasicVariableOperand("col1"), new BasicOperand(
068: 3))),
069: new ConditionalAnd(new LowerEqual(new BasicVariableOperand(
070: "col1"), new BasicOperand(12)), new ConditionalAnd(
071: new GreaterEqual(new BasicVariableOperand("col1"),
072: new BasicOperand(3)), new Equal(
073: new BasicVariableOperand("col2"),
074: new BasicOperand(3)))) };
075:
076: private static Logger logger = null;
077:
078: public TestParsingInheritanceFilter(String s) {
079: super (s);
080: if (logger == null) {
081: logger = Monolog.initialize().getLogger(
082: getClass().getName());
083: }
084: }
085:
086: public void testA() {
087: FilterManager parser = new FilterManager(logger);
088: for (int i = 0; i < filters.length; i++) {
089: logger.log(BasicLevel.DEBUG, "Parsing of filter: "
090: + filters[i]);
091: try {
092: Expression exp = parser.getParser().parse(filters[i]);
093: TestExpressionHelper.equals("", expressions[i], exp,
094: logger);
095: } catch (Error e) {
096: fail(e.getMessage());
097: } catch (Exception e) {
098: Exception ie = ExceptionHelper.getNested(e);
099: logger.log(BasicLevel.ERROR,
100: "Error during the parsing of filter: "
101: + filters[i], ie);
102: fail(e.getMessage());
103: }
104: }
105: }
106: }
|