org.eigenbase.sql.test
Class SqlAdvisorTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.eigenbase.test.SqlValidatorTestCase
              extended by org.eigenbase.sql.test.SqlAdvisorTest
All Implemented Interfaces:
Test

public class SqlAdvisorTest
extends SqlValidatorTestCase

Concrete child class of SqlValidatorTestCase, containing unit tests for SqlAdvisor.

Since:
Jan 16, 2005
Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/test/SqlAdvisorTest.java#3 $
Author:
Tim Leung

Nested Class Summary
 class SqlAdvisorTest.AdvisorTestImpl
           
static interface SqlAdvisorTest.Tester
           
 
Nested classes/interfaces inherited from class org.eigenbase.test.SqlValidatorTestCase
SqlValidatorTestCase.TesterImpl
 
Field Summary
private static List<String> A_TABLE
           
private static List<String> AB_TABLES
           
protected static List<String> AGG_KEYWORDS
           
private static List<String> DEPT_COLUMNS
           
private static List<String> EMP_COLUMNS
           
private static List<String> EMP_TABLE
           
protected static List<String> EXPR_KEYWORDS
           
protected static List<String> FROM_KEYWORDS
           
protected static List<String> JOIN_KEYWORDS
           
 Logger logger
           
private static List<String> ORDER_KEYWORDS
           
protected static List<String> PREDICATE_KEYWORDS
           
protected static List<String> SALES_TABLES
           
private static List<String> SCHEMAS
           
protected static List<String> SELECT_KEYWORDS
           
private static List<String> STAR_KEYWORD
           
private static List<String> WHERE_KEYWORDS
           
 
Fields inherited from class org.eigenbase.test.SqlValidatorTestCase
NL, tester
 
Constructor Summary
SqlAdvisorTest(String name)
           
 
Method Summary
protected  void assertComplete(String sql, List<String>... expectedResults)
           
protected  void assertComplete(String sql, String expectedResults, String expectedWord)
          Tests that a given SQL which may be invalid or incomplete simplifies itself and yields the salesTables set of completion hints.
protected  void assertEquals(String[] actualResults, List<String>... expectedResults)
           
protected  void assertHint(String sql, List<String>... expectedLists)
           
protected  void assertHint(String sql, String expectedResults)
          Checks that a given SQL statement yields the expected set of completion hints.
protected  void assertSimplify(String sql, String expected)
          Tests that a given SQL statement simplifies to the salesTables result.
private  void assertTokenizesTo(String sql, String expected)
           
private  String convertCompletionHints(List<SqlMoniker> hints)
           
protected  List<String> getFromKeywords()
           
protected  List<String> getJoinKeywords()
           
protected  List<String> getSalesTables()
          Returns a list of the tables in the SALES schema.
protected  List<String> getSelectKeywords()
           
 SqlAdvisorTest.Tester getTester(SqlConformance conformance)
          Returns a tester.
protected static
<T> List<T>
plus(List<T>... lists)
          Concatenates several lists of the same type into a single list.
 void testFrom()
           
 void testFromComplete()
           
 void testFromWhere()
           
 void testGroup()
           
 void testInsert()
           
 void testJoin()
           
 void testJoinKeywords()
           
 void testOnCondition()
           
 void testOrderByList()
           
 void testPartialIdentifier()
           
 void testSelectList()
           
 void testSimpleParser()
           
 void testSimpleParserQuotedId()
           
 void testSimpleParserTokenizer()
           
 void testSubQuery()
           
 void testSubQueryInWhere()
           
 void testUnion()
           
 void testWhereList()
           
private static
<T> String
toString(List<T> list)
          Converts a list to a string, one item per line.
 
Methods inherited from class org.eigenbase.test.SqlValidatorTestCase
assertExceptionIsThrown, check, checkCharset, checkCollation, checkColumnType, checkEx, checkExp, checkExpFails, checkExpType, checkFails, checkIntervalConv, checkResultType, checkWholeExpFails
 
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

STAR_KEYWORD

private static final List<String> STAR_KEYWORD

FROM_KEYWORDS

protected static final List<String> FROM_KEYWORDS

AGG_KEYWORDS

protected static final List<String> AGG_KEYWORDS

SALES_TABLES

protected static final List<String> SALES_TABLES

SCHEMAS

private static final List<String> SCHEMAS

AB_TABLES

private static final List<String> AB_TABLES

EMP_TABLE

private static final List<String> EMP_TABLE

EXPR_KEYWORDS

protected static final List<String> EXPR_KEYWORDS

SELECT_KEYWORDS

protected static final List<String> SELECT_KEYWORDS

ORDER_KEYWORDS

private static final List<String> ORDER_KEYWORDS

EMP_COLUMNS

private static final List<String> EMP_COLUMNS

DEPT_COLUMNS

private static final List<String> DEPT_COLUMNS

PREDICATE_KEYWORDS

protected static final List<String> PREDICATE_KEYWORDS

WHERE_KEYWORDS

private static final List<String> WHERE_KEYWORDS

A_TABLE

private static final List<String> A_TABLE

JOIN_KEYWORDS

protected static final List<String> JOIN_KEYWORDS

logger

public final Logger logger
Constructor Detail

SqlAdvisorTest

public SqlAdvisorTest(String name)
Method Detail

getFromKeywords

protected List<String> getFromKeywords()

getSelectKeywords

protected List<String> getSelectKeywords()

getSalesTables

protected List<String> getSalesTables()
Returns a list of the tables in the SALES schema. Derived classes with extended SALES schemas may override.

Returns:
list of tables in the SALES schema

getJoinKeywords

protected List<String> getJoinKeywords()

assertTokenizesTo

private void assertTokenizesTo(String sql,
                               String expected)

assertHint

protected void assertHint(String sql,
                          List<String>... expectedLists)
                   throws Exception
Throws:
Exception

assertHint

protected void assertHint(String sql,
                          String expectedResults)
                   throws Exception
Checks that a given SQL statement yields the expected set of completion hints.

Parameters:
sql - SQL statement
expectedResults - Expected list of hints
Throws:
Exception - on error

assertSimplify

protected void assertSimplify(String sql,
                              String expected)
Tests that a given SQL statement simplifies to the salesTables result.

Parameters:
sql - SQL statement to simplify. The SQL statement must contain precisely one caret '^', which marks the location where completion is to occur.
expected - Expected result after simplification.

assertComplete

protected void assertComplete(String sql,
                              List<String>... expectedResults)

assertComplete

protected void assertComplete(String sql,
                              String expectedResults,
                              String expectedWord)
Tests that a given SQL which may be invalid or incomplete simplifies itself and yields the salesTables set of completion hints. This is an integration test of assertHint(java.lang.String, java.util.List...) and assertSimplify(java.lang.String, java.lang.String).

Parameters:
sql - SQL statement
expectedResults - Expected list of hints
expectedWord - Word that we expect to be replaced, or null if we don't care

assertEquals

protected void assertEquals(String[] actualResults,
                            List<String>... expectedResults)
                     throws Exception
Throws:
Exception

convertCompletionHints

private String convertCompletionHints(List<SqlMoniker> hints)

toString

private static <T> String toString(List<T> list)
Converts a list to a string, one item per line.

Parameters:
list - List
Returns:
String with one item of the list per line

getTester

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

Overrides:
getTester in class SqlValidatorTestCase
Parameters:
conformance - Language version tests should check compatibility with

plus

protected static <T> List<T> plus(List<T>... lists)
Concatenates several lists of the same type into a single list.

Parameters:
lists - Lists to concatenate
Returns:
Sum list

testFrom

public void testFrom()
              throws Exception
Throws:
Exception

testFromComplete

public void testFromComplete()

testGroup

public void testGroup()

testJoin

public void testJoin()
              throws Exception
Throws:
Exception

testJoinKeywords

public void testJoinKeywords()

testOnCondition

public void testOnCondition()
                     throws Exception
Throws:
Exception

testFromWhere

public void testFromWhere()
                   throws Exception
Throws:
Exception

testWhereList

public void testWhereList()
                   throws Exception
Throws:
Exception

testSelectList

public void testSelectList()
                    throws Exception
Throws:
Exception

testOrderByList

public void testOrderByList()
                     throws Exception
Throws:
Exception

testSubQuery

public void testSubQuery()
                  throws Exception
Throws:
Exception

testSubQueryInWhere

public void testSubQueryInWhere()

testSimpleParserTokenizer

public void testSimpleParserTokenizer()

testSimpleParser

public void testSimpleParser()

testSimpleParserQuotedId

public void testSimpleParserQuotedId()

testPartialIdentifier

public void testPartialIdentifier()

testInsert

public void testInsert()
                throws Exception
Throws:
Exception

testUnion

public void testUnion()
               throws Exception
Throws:
Exception