org.apache.derbyTesting.functionTests.tests.lang
Class TimestampArithTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.lang.TimestampArithTest
All Implemented Interfaces:
junit.framework.Test

public class TimestampArithTest
extends BaseJDBCTestCase

Test the JDBC TIMESTAMPADD and TIMESTAMPDIFF escape functions. Things to test: + Test each interval type with timestamp, date, and time inputs. + Test diff with all 9 combinations of datetime input types (timestamp - timestamp, timestamp - date, etc). + Test PreparedStatements with parameters, '?', in each argument, and Statements. (Statements are prepared internally so we do not also have to test PrepardStatements without parameters). + Test with null inputs. + Test with input string that is convertible to timestamp. + Test with invalid interval type. + Test with invalid arguments in the date time arguments. + Test TIMESTAMPADD with an invalid type in the count argument. + Test overflow cases.


Nested Class Summary
private  class TimestampArithTest.OneAddTest
           
private  class TimestampArithTest.OneDiffTest
           
private  class TimestampArithTest.OneStringAddTest
           
private  class TimestampArithTest.OneStringDiffTest
           
private  class TimestampArithTest.OneTest
          Abstract class that factors out all the common code for the timestamps tests.
 
Field Summary
private  TimestampArithTest.OneAddTest[] addBetweenDateAndTsTests
          date + timestamp
private  TimestampArithTest.OneStringAddTest[] addBetweenStringTests
           
private  TimestampArithTest.OneAddTest[] addBetweenTsTests
          timestamp + timestamp
private static int DAY_INTERVAL
           
private  TimestampArithTest.OneDiffTest[] diffBetweenDateAndTsTests
          date - timestamp
private  TimestampArithTest.OneStringDiffTest[] diffBetweenStringTests
           
private  TimestampArithTest.OneDiffTest[] diffBetweenTsAndDateTests
          timestamp - date
private  TimestampArithTest.OneDiffTest[] diffBetweenTsTests
          timestamp - timestamp
private static int FRAC_SECOND_INTERVAL
           
private static int HOUR_INTERVAL
           
private static java.lang.String[] intervalJdbcNames
           
private  java.lang.String[][] invalid
           
private static int MINUTE_INTERVAL
           
private static int MONTH_INTERVAL
           
private static int ONE_BILLION
           
private  TimestampArithTest.OneTest[] overflowTests
          check overflow conditions
private static int QUARTER_INTERVAL
           
private static int SECOND_INTERVAL
           
private static java.sql.Statement stmt
           
private static java.lang.String TODAY
           
private static java.lang.String TOMORROW
           
private static java.sql.PreparedStatement[] tsAddPS
           
private static java.sql.PreparedStatement[] tsDiffPS
           
private static java.lang.String WEEK_FROM_TODAY
           
private static int WEEK_INTERVAL
           
private static java.lang.String YEAR_FROM_TODAY
           
private static java.lang.String YEAR_FROM_TOMORROW
           
private static int YEAR_INTERVAL
           
private static java.lang.String YESTERDAY
           
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
TimestampArithTest(java.lang.String name)
          Basic constructor.
 
Method Summary
private static java.lang.String composeSqlStr(java.lang.String fn, int interval, java.lang.String parm1, java.lang.String parm2)
           
private static java.lang.String dateTimeToLiteral(java.lang.Object ts)
           
private static java.sql.Date dt(java.lang.String s)
           
private static void expectException(java.sql.PreparedStatement ps, java.lang.Object obj1, java.lang.Object obj2, java.lang.String expectedSQLState, java.lang.String label)
           
private static void expectNullResult(java.sql.PreparedStatement ps, java.lang.String label)
           
protected  void initializeConnection(java.sql.Connection conn)
          Allow a sub-class to initialize a connection to provide consistent connection state for its tests.
private static java.lang.String isoFormatDate(java.util.Calendar cal)
           
private static void setDateTime(java.sql.PreparedStatement ps, int parameterIdx, java.util.Date dateTime)
           
static junit.framework.Test suite()
           
 void testAddBetweenDateAndTimestamps()
           
 void testAddBetweenString()
           
 void testAddBetweenTimestamp()
           
 void testDiffBetweenDateAndTimestamp()
           
 void testDiffBetweenString()
           
 void testDiffBetweenTimestamp()
           
 void testDiffBetweenTimestampAndDate()
           
 void testInvalidArgTypes()
           
 void testInvalidLengths()
           
 void testNullInputs()
          Tests null inputs, each position, each type.
 void testOverflow()
           
private static java.sql.Timestamp ts(java.lang.String s)
           
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

diffBetweenTsTests

private final TimestampArithTest.OneDiffTest[] diffBetweenTsTests
timestamp - timestamp


diffBetweenTsAndDateTests

private final TimestampArithTest.OneDiffTest[] diffBetweenTsAndDateTests
timestamp - date


diffBetweenDateAndTsTests

private final TimestampArithTest.OneDiffTest[] diffBetweenDateAndTsTests
date - timestamp


addBetweenTsTests

private final TimestampArithTest.OneAddTest[] addBetweenTsTests
timestamp + timestamp


addBetweenDateAndTsTests

private final TimestampArithTest.OneAddTest[] addBetweenDateAndTsTests
date + timestamp


diffBetweenStringTests

private final TimestampArithTest.OneStringDiffTest[] diffBetweenStringTests

addBetweenStringTests

private final TimestampArithTest.OneStringAddTest[] addBetweenStringTests

overflowTests

private final TimestampArithTest.OneTest[] overflowTests
check overflow conditions


invalid

private final java.lang.String[][] invalid

intervalJdbcNames

private static final java.lang.String[] intervalJdbcNames

stmt

private static java.sql.Statement stmt

tsAddPS

private static java.sql.PreparedStatement[] tsAddPS

tsDiffPS

private static java.sql.PreparedStatement[] tsDiffPS

FRAC_SECOND_INTERVAL

private static final int FRAC_SECOND_INTERVAL
See Also:
Constant Field Values

SECOND_INTERVAL

private static final int SECOND_INTERVAL
See Also:
Constant Field Values

MINUTE_INTERVAL

private static final int MINUTE_INTERVAL
See Also:
Constant Field Values

HOUR_INTERVAL

private static final int HOUR_INTERVAL
See Also:
Constant Field Values

DAY_INTERVAL

private static final int DAY_INTERVAL
See Also:
Constant Field Values

WEEK_INTERVAL

private static final int WEEK_INTERVAL
See Also:
Constant Field Values

MONTH_INTERVAL

private static final int MONTH_INTERVAL
See Also:
Constant Field Values

QUARTER_INTERVAL

private static final int QUARTER_INTERVAL
See Also:
Constant Field Values

YEAR_INTERVAL

private static final int YEAR_INTERVAL
See Also:
Constant Field Values

ONE_BILLION

private static final int ONE_BILLION
See Also:
Constant Field Values

TODAY

private static java.lang.String TODAY

TOMORROW

private static java.lang.String TOMORROW

YEAR_FROM_TOMORROW

private static java.lang.String YEAR_FROM_TOMORROW

YEAR_FROM_TODAY

private static java.lang.String YEAR_FROM_TODAY

YESTERDAY

private static java.lang.String YESTERDAY

WEEK_FROM_TODAY

private static java.lang.String WEEK_FROM_TODAY
Constructor Detail

TimestampArithTest

public TimestampArithTest(java.lang.String name)
Basic constructor.

Method Detail

initializeConnection

protected void initializeConnection(java.sql.Connection conn)
                             throws java.sql.SQLException
Description copied from class: BaseJDBCTestCase
Allow a sub-class to initialize a connection to provide consistent connection state for its tests. Called once for each time these method calls open a connection: Default action is to not modify the connection's state from the initialization provided by the data source.

Overrides:
initializeConnection in class BaseJDBCTestCase
Parameters:
conn - Connection to be intialized
Throws:
java.sql.SQLException - Error setting the initial state.

suite

public static junit.framework.Test suite()

testDiffBetweenTimestamp

public void testDiffBetweenTimestamp()
                              throws java.sql.SQLException
Throws:
java.sql.SQLException

testDiffBetweenTimestampAndDate

public void testDiffBetweenTimestampAndDate()
                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

testDiffBetweenDateAndTimestamp

public void testDiffBetweenDateAndTimestamp()
                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

testAddBetweenTimestamp

public void testAddBetweenTimestamp()
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

testAddBetweenDateAndTimestamps

public void testAddBetweenDateAndTimestamps()
                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

testDiffBetweenString

public void testDiffBetweenString()
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

testAddBetweenString

public void testAddBetweenString()
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

testOverflow

public void testOverflow()
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

testNullInputs

public void testNullInputs()
                    throws java.sql.SQLException
Tests null inputs, each position, each type.

Throws:
java.sql.SQLException

testInvalidLengths

public void testInvalidLengths()
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

testInvalidArgTypes

public void testInvalidArgTypes()
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

expectException

private static void expectException(java.sql.PreparedStatement ps,
                                    java.lang.Object obj1,
                                    java.lang.Object obj2,
                                    java.lang.String expectedSQLState,
                                    java.lang.String label)

expectNullResult

private static void expectNullResult(java.sql.PreparedStatement ps,
                                     java.lang.String label)

isoFormatDate

private static java.lang.String isoFormatDate(java.util.Calendar cal)

dateTimeToLiteral

private static java.lang.String dateTimeToLiteral(java.lang.Object ts)

composeSqlStr

private static java.lang.String composeSqlStr(java.lang.String fn,
                                              int interval,
                                              java.lang.String parm1,
                                              java.lang.String parm2)

setDateTime

private static void setDateTime(java.sql.PreparedStatement ps,
                                int parameterIdx,
                                java.util.Date dateTime)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

ts

private static java.sql.Timestamp ts(java.lang.String s)

dt

private static java.sql.Date dt(java.lang.String s)

Built on Sat 2009-11-28 18:44:18-0800, from revision 885187

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.