org.eigenbase.test
Class SqlValidatorTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.eigenbase.test.SqlValidatorTestCase
All Implemented Interfaces:
Test
Direct Known Subclasses:
SqlAdvisorTest, SqlValidatorFeatureTest, SqlValidatorTest

public class SqlValidatorTestCase
extends TestCase

An abstract base class for implementing tests against SqlValidator.

A derived class can refine this test in two ways. First, it can add testXxx() methods, to test more functionality.

Second, it can override the getTester(org.eigenbase.sql.validate.SqlConformance) method to return a different implementation of the SqlValidatorTestCase.Tester object. This encapsulates the differences between test environments, for example, which SQL parser or validator to use.

Since:
Jan 12, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/test/SqlValidatorTestCase.java#38 $
Author:
Wael Chatila

Nested Class Summary
static interface SqlValidatorTestCase.Tester
          Encapsulates differences between test environments, for example, which SQL parser or validator to use.
static class SqlValidatorTestCase.TesterImpl
          Implementation of SqlValidatorTestCase.Tester which talks to a mock catalog.
 
Field Summary
private static Pattern lineColPattern
           
private static Pattern lineColTwicePattern
           
protected static String NL
           
protected  SqlValidatorTestCase.Tester tester
           
 
Constructor Summary
SqlValidatorTestCase(String name)
          Creates a testcase.
 
Method Summary
protected  void assertExceptionIsThrown(String sql, String expectedMsgPattern)
           
 void check(String sql)
           
 void checkCharset(String sql, Charset expectedCharset)
           
 void checkCollation(String sql, String expectedCollationName, SqlCollation.Coercibility expectedCoercibility)
           
 void checkColumnType(String sql, String expected)
          Checks that a query returns a single column, and that the column has the expected type.
static void checkEx(Throwable ex, String expectedMsgPattern, SqlParserUtil.StringAndPos sap)
          Checks whether an exception matches the expected pattern.
 void checkExp(String sql)
           
 void checkExpFails(String sql, String expected)
          Checks that a SQL expression gives a particular error.
 void checkExpType(String sql, String expected)
           
 void checkFails(String sql, String expected)
          Checks that a SQL query gives a particular error, or succeeds if expected is null.
 void checkIntervalConv(String sql, String expected)
          Checks that the first column returned by a query has the expected type.
 void checkResultType(String sql, String expected)
          Checks that a query returns a row of the expected type.
 void checkWholeExpFails(String sql, String expected)
          Checks that a SQL expression gives a particular error, and that the location of the error is the whole expression.
 SqlValidatorTestCase.Tester getTester(SqlConformance conformance)
          Returns a tester.
private static SqlConformance splitConformance(String name)
           
private static String splitName(String name)
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NL

protected static final String NL

lineColPattern

private static final Pattern lineColPattern

lineColTwicePattern

private static final Pattern lineColTwicePattern

tester

protected final SqlValidatorTestCase.Tester tester
Constructor Detail

SqlValidatorTestCase

public SqlValidatorTestCase(String name)
Creates a testcase.

If name is of the form "compatible:testCase", invokes sets the compatibility to "compatible".

Parameters:
name - Name; examples "Sql2003:testGroup", "testGroup"
Method Detail

splitName

private static String splitName(String name)

splitConformance

private static SqlConformance splitConformance(String name)

getTester

public SqlValidatorTestCase.Tester getTester(SqlConformance conformance)
Returns a tester. Derived classes should override this method to run the same set of tests in a different testing environment.

Parameters:
conformance - Language version tests should check compatibility with

check

public void check(String sql)

checkExp

public void checkExp(String sql)

checkFails

public final void checkFails(String sql,
                             String expected)
Checks that a SQL query gives a particular error, or succeeds if expected is null.


checkExpFails

public final void checkExpFails(String sql,
                                String expected)
Checks that a SQL expression gives a particular error.


checkWholeExpFails

public final void checkWholeExpFails(String sql,
                                     String expected)
Checks that a SQL expression gives a particular error, and that the location of the error is the whole expression.


checkExpType

public void checkExpType(String sql,
                         String expected)

checkColumnType

public void checkColumnType(String sql,
                            String expected)
Checks that a query returns a single column, and that the column has the expected type. For example,
checkColumnType("SELECT empno FROM Emp", "INTEGER NOT NULL");

Parameters:
sql - Query
expected - Expected type, including nullability

checkResultType

public void checkResultType(String sql,
                            String expected)
Checks that a query returns a row of the expected type. For example,
checkResultType("select empno, name from emp","{EMPNO INTEGER NOT NULL, NAME VARCHAR(10) NOT NULL}");

Parameters:
sql - Query
expected - Expected row type

checkIntervalConv

public void checkIntervalConv(String sql,
                              String expected)
Checks that the first column returned by a query has the expected type. For example,
checkQueryType("SELECT empno FROM Emp", "INTEGER NOT NULL");

Parameters:
sql - Query
expected - Expected type, including nullability

assertExceptionIsThrown

protected final void assertExceptionIsThrown(String sql,
                                             String expectedMsgPattern)

checkCharset

public void checkCharset(String sql,
                         Charset expectedCharset)

checkCollation

public void checkCollation(String sql,
                           String expectedCollationName,
                           SqlCollation.Coercibility expectedCoercibility)

checkEx

public static void checkEx(Throwable ex,
                           String expectedMsgPattern,
                           SqlParserUtil.StringAndPos sap)
Checks whether an exception matches the expected pattern. If sap contains an error location, checks this too.

Parameters:
ex - Exception thrown
expectedMsgPattern - Expected pattern
sap - Query and (optional) position in query