net.sf.farrago.test
Class FarragoTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.eigenbase.test.DiffTestCase
              extended by net.sf.farrago.test.ResultSetTestCase
                  extended by net.sf.farrago.test.FarragoTestCase
All Implemented Interfaces:
Test
Direct Known Subclasses:
FarragoAutoCalcRulesTest, FarragoCalcSystemTest, FarragoDdlGeneratorTest, FarragoEngineDriverTest, FarragoQueryTest, FarragoRepositoryTest, FarragoSorterTest, FarragoSqlOperatorsSuite.MyFarragoTestCase, FarragoSqlRunnerTest, FarragoSqlTest, FarragoSqlTestWrapper, FarragoSqlToRelTestBase, FarragoTestCase.Cleanup, FarragoTestConcurrentTestCase, FennelDmlTest, JmiMemTest, JmiModelTest, TestLeaks

public abstract class FarragoTestCase
extends ResultSetTestCase

FarragoTestCase is a common base for Farrago JUnit tests. Subclasses must implement the suite() method in order to get a database connection correctly initialized. See FarragoQueryTest for an example.

For SQL tests, FarragoTestCase writes the output from sqlline to a file called <testname>.log, and compares that output with a reference log file <testname>.ref.

It is also possible to have additional logfiles, for tests which generate output to files. FarragoTestCase scans the input .sql file for lines of the form

##COMPARE <file>.log
and for each such command, it compares file.log with file.ref.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/test/FarragoTestCase.java#79 $
Author:
John V. Sichi

Nested Class Summary
static class FarragoTestCase.Cleanup
          Helper for staticSetUp.
static class FarragoTestCase.CleanupFactory
          CleanupFactory is a factory for Cleanup objects.
private static class FarragoTestCase.ReplacingOutputStream
          Stream which applies regular expression replacement to its contents.
private static class FarragoTestCase.ShutdownThread
           
 
Field Summary
protected  FarragoCompoundAllocation allocOwner
          An owner for any heavyweight allocations.
private static int connCounter
          Connection counter for distinguishing connections during debug.
protected static Connection connection
          JDBC connection to Farrago database.
private static boolean individualTest
          Flag used to allow individual test methods to be called from IntelliJ.
protected  PreparedStatement preparedStmt
          PreparedStatement for processing queries.
protected static FarragoRepos repos
          Repos for test object definitions.
private static SortedMap<String,Object> savedFarragoConfig
          Saved copy of Farrago configuration parameters.
private static SortedMap<String,Object> savedFennelConfig
          Saved copy of Fennel configuration parameters.
private static Thread shutdownHook
           
protected  Statement stmt
          Statement for processing queries.
protected static Logger tracer
          Logger to use for test tracing.
 
Fields inherited from class net.sf.farrago.test.ResultSetTestCase
resultSet
 
Fields inherited from class org.eigenbase.test.DiffTestCase
logFile, logOutputStream, refFile
 
Constructor Summary
protected FarragoTestCase(String testName)
          Creates a new FarragoTestCase object.
 
Method Summary
static void forceShutdown()
           
protected static String getJdbcUri(FarragoAbstractJdbcDriver driver)
           
protected static FarragoSession getSession()
           
protected  File getTestlogRoot()
           
static File getTestlogRootStatic()
          Implementation for { @link DiffTestCase#getTestlogRoot } which uses 'testlog' directory under Farrago home.
protected static Connection newConnection()
           
protected static FarragoAbstractJdbcDriver newJdbcEngineDriver()
          Retrieves a new instance of the FarragoJdbcEngineDriver configured for this test.
protected static void restoreParameters()
          Restores system parameters to state saved by saveParameters().
protected static void restoreParameters(FarragoRepos repos)
           
private static void rollbackIfSupported()
           
protected static void runCleanup()
           
protected  void runSqlLineTest(String sqlFile)
           
protected  void runSqlLineTest(String sqlFile, boolean shouldDiff)
           
protected static void saveParameters()
          Saves system parameters.
protected static void saveParameters(FarragoRepos repos)
           
protected  void setRefFileDiffMasks()
          Sets the diff masks that are common to .REF files
protected  void setUp()
           
protected  boolean shouldDiff()
           
static void staticSetUp()
          One-time setup routine.
static void staticTearDown()
          One-time tear-down routine.
protected  void tearDown()
           
protected  void tearDownImpl()
           
static Test wrappedSuite(Class<? extends TestCase> clazz)
          Generic implementation of suite() to be called by subclasses.
static Test wrappedSuite(TestSuite suite)
          Generic implementation of suite() to be called by subclasses.
 
Methods inherited from class net.sf.farrago.test.ResultSetTestCase
compareResultList, compareResultLists, compareResultSet, compareResultSetWithDelta, compareResultSetWithPattern, getResultSetCount
 
Methods inherited from class org.eigenbase.test.DiffTestCase
addDiffMask, addIgnorePattern, diffFile, diffLines, diffTestLog, fileContents, openTestLog, openTestLogOutputStream, setGC, setVerbose
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, 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

tracer

protected static final Logger tracer
Logger to use for test tracing.


connection

protected static Connection connection
JDBC connection to Farrago database.


repos

protected static FarragoRepos repos
Repos for test object definitions.


individualTest

private static boolean individualTest
Flag used to allow individual test methods to be called from IntelliJ.


savedFarragoConfig

private static SortedMap<String,Object> savedFarragoConfig
Saved copy of Farrago configuration parameters.


savedFennelConfig

private static SortedMap<String,Object> savedFennelConfig
Saved copy of Fennel configuration parameters.


shutdownHook

private static Thread shutdownHook

connCounter

private static int connCounter
Connection counter for distinguishing connections during debug.

See Also:
newConnection()

preparedStmt

protected PreparedStatement preparedStmt
PreparedStatement for processing queries.


stmt

protected Statement stmt
Statement for processing queries.


allocOwner

protected FarragoCompoundAllocation allocOwner
An owner for any heavyweight allocations.

Constructor Detail

FarragoTestCase

protected FarragoTestCase(String testName)
                   throws Exception
Creates a new FarragoTestCase object.

Parameters:
testName - .
Throws:
Exception - .
Method Detail

getTestlogRoot

protected File getTestlogRoot()
                       throws Exception
Specified by:
getTestlogRoot in class DiffTestCase
Returns:
the root under which testlogs should be written
Throws:
Exception

getTestlogRootStatic

public static File getTestlogRootStatic()
Implementation for { @link DiffTestCase#getTestlogRoot } which uses 'testlog' directory under Farrago home.

Returns:
the root under which testlogs should be written

staticSetUp

public static void staticSetUp()
                        throws Exception
One-time setup routine.

Throws:
Exception - .

runCleanup

protected static void runCleanup()
                          throws Exception
Throws:
Exception

staticTearDown

public static void staticTearDown()
                           throws Exception
One-time tear-down routine.

Throws:
Exception - .

getSession

protected static FarragoSession getSession()
Returns:
FarragoSession for this test

rollbackIfSupported

private static void rollbackIfSupported()
                                 throws SQLException
Throws:
SQLException

newConnection

protected static Connection newConnection()
                                   throws Exception
Throws:
Exception

forceShutdown

public static void forceShutdown()
                          throws Exception
Throws:
Exception

saveParameters

protected static void saveParameters()
Saves system parameters.


restoreParameters

protected static void restoreParameters()
Restores system parameters to state saved by saveParameters().


saveParameters

protected static void saveParameters(FarragoRepos repos)

restoreParameters

protected static void restoreParameters(FarragoRepos repos)

wrappedSuite

public static Test wrappedSuite(Class<? extends TestCase> clazz)
Generic implementation of suite() to be called by subclasses.

Parameters:
clazz - the subclass being wrapped
Returns:
a JUnit test suite which will take care of initialization of per-testcase members

wrappedSuite

public static Test wrappedSuite(TestSuite suite)
Generic implementation of suite() to be called by subclasses.

If the SaffronProperties.testEverything property is false, and the SaffronProperties.testName property is set, then returns a suite containing only the tests whose names match.

Parameters:
suite - the suite being wrapped
Returns:
a JUnit test suite which will take care of initialization of per-testcase members

setUp

protected void setUp()
              throws Exception
Overrides:
setUp in class DiffTestCase
Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Overrides:
tearDown in class DiffTestCase
Throws:
Exception

tearDownImpl

protected void tearDownImpl()
                     throws Exception
Throws:
Exception

newJdbcEngineDriver

protected static FarragoAbstractJdbcDriver newJdbcEngineDriver()
                                                        throws Exception
Retrieves a new instance of the FarragoJdbcEngineDriver configured for this test.

Returns:
an instance of FarragoJdbcEngineDriver (or a subclass)
Throws:
Exception

getJdbcUri

protected static String getJdbcUri(FarragoAbstractJdbcDriver driver)
                            throws Exception
Throws:
Exception

runSqlLineTest

protected void runSqlLineTest(String sqlFile)
                       throws Exception
Throws:
Exception

runSqlLineTest

protected void runSqlLineTest(String sqlFile,
                              boolean shouldDiff)
                       throws Exception
Throws:
Exception

shouldDiff

protected boolean shouldDiff()

setRefFileDiffMasks

protected void setRefFileDiffMasks()
Description copied from class: DiffTestCase
Sets the diff masks that are common to .REF files

Overrides:
setRefFileDiffMasks in class DiffTestCase