Package org.objectweb.speedo

Source Code of org.objectweb.speedo.TestParsingInheritanceFilter

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

import org.objectweb.medor.expression.api.Expression;
import org.objectweb.medor.expression.lib.BasicOperand;
import org.objectweb.medor.expression.lib.BasicVariableOperand;
import org.objectweb.medor.expression.lib.ConditionalAnd;
import org.objectweb.medor.expression.lib.Equal;
import org.objectweb.medor.expression.lib.Greater;
import org.objectweb.medor.expression.lib.GreaterEqual;
import org.objectweb.medor.expression.lib.Lower;
import org.objectweb.medor.expression.lib.LowerEqual;
import org.objectweb.medor.expression.lib.NotEqual;
import org.objectweb.medor.filter.TestExpressionHelper;
import org.objectweb.speedo.api.ExceptionHelper;
import org.objectweb.speedo.generation.jorm.rdb.FilterManager;
import org.objectweb.util.monolog.Monolog;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;

import junit.framework.TestCase;

/**
*
* @author S.Chassande-Barrioz
*/
public class TestParsingInheritanceFilter extends TestCase {

  private static final String[] filters = {
    "(col1 == 12)",
    "(col1 == \"AZERTY\")",
    "(col1 != 12)",
    "(col1 > 12)",
    "(col1 >= 12)",
    "(col1 < 12)",
    "(col1 <= 12)",
    "((col1 <= 12) && (col1 >= 3))",
    "((col1 <= 12) && (col1 >= 3) && (col2 == 3)) ",
  };

  private static final Expression[] expressions = {
    new Equal(new BasicVariableOperand("col1"), new BasicOperand(12)),
    new Equal(new BasicVariableOperand("col1"), new BasicOperand("AZERTY")),
    new NotEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
    new Greater(new BasicVariableOperand("col1"), new BasicOperand(12)),
    new GreaterEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
    new Lower(new BasicVariableOperand("col1"), new BasicOperand(12)),
    new LowerEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
    new ConditionalAnd(
        new LowerEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
        new GreaterEqual(new BasicVariableOperand("col1"), new BasicOperand(3))),
    new ConditionalAnd(
          new LowerEqual(new BasicVariableOperand("col1"), new BasicOperand(12)),
        new ConditionalAnd(
            new GreaterEqual(new BasicVariableOperand("col1"), new BasicOperand(3)),
          new Equal(new BasicVariableOperand("col2"), new BasicOperand(3))))
  };

  private static Logger logger = null;


  public TestParsingInheritanceFilter(String s) {
    super(s);
    if (logger == null) {
      logger = Monolog.initialize().getLogger(getClass().getName());
    }
  }

  public void testA() {
    FilterManager parser = new FilterManager(logger);
    for(int i=0; i<filters.length; i++) {
      logger.log(BasicLevel.DEBUG, "Parsing of filter: " + filters[i]);
      try {
        Expression exp = parser.getParser().parse(filters[i]);
        TestExpressionHelper.equals("", expressions[i], exp, logger);
      } catch (Error e) {
        fail(e.getMessage());
      } catch (Exception e) {
        Exception ie = ExceptionHelper.getNested(e);
        logger.log(BasicLevel.ERROR, "Error during the parsing of filter: " + filters[i], ie);
        fail(e.getMessage());
      }
    }
  }
}
TOP

Related Classes of org.objectweb.speedo.TestParsingInheritanceFilter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.