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

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.CastingTest
All Implemented Interfaces:
junit.framework.Test

public class CastingTest
extends BaseJDBCTestCase


Nested Class Summary
static class CastingTest.TypedColumn
           
 
Field Summary
static boolean _
           
static int BIGINT_OFFSET
           
static int BLOB_OFFSET
           
static int CHAR_FOR_BIT_OFFSET
           
static int CHAR_OFFSET
           
static int CLOB_OFFSET
           
static int DATE_OFFSET
           
static int DECIMAL_OFFSET
           
static int DOUBLE_OFFSET
           
private static java.lang.String[][] explicitCastValues
           
private static CastingTest.TypedColumn[] ILLEGAL_BOOLEAN_CASTS
           
static java.lang.String ILLEGAL_CAST_EXCEPTION_SQLSTATE
           
static int INTEGER_OFFSET
           
static int[] jdbcTypes
           
static java.lang.String LANG_FORMAT_EXCEPTION_SQLSTATE
           
static java.lang.String LANG_NOT_COMPARABLE_SQLSTATE
           
static java.lang.String LANG_NOT_STORABLE_SQLSTATE
           
private static CastingTest.TypedColumn[] LEGAL_BOOLEAN_CASTS
           
static int LONGVARCHAR_FOR_BIT_OFFSET
           
static int LONGVARCHAR_OFFSET
           
static java.lang.String METHOD_NOT_FOUND_SQLSTATE
           
static int NULL_DATA_OFFSET
           
static java.lang.String NULL_VALUE
           
static int REAL_OFFSET
           
static int SMALLINT_OFFSET
           
static java.lang.String[][] SQLData
           
static int SQLTYPE_ARRAY_SIZE
           
static boolean[][] T_146
          Table 146 - Supported explicit casts between Built-in DataTypes This table has THE FOR BIT DATA TYPES broken out into separate columns for clarity and testing
static boolean[][] T_147a
          Table 147 describes Data Type Compatibility for Assignments The table 147a covers the assignments as they do differ somewhat from comparisons which can be found in 147b
static boolean[][] T_147b
           
static int TIME_OFFSET
           
static int TIMESTAMP_OFFSET
           
static int VALID_DATA_OFFSET
           
static java.lang.String VALID_DATE_STRING
           
static java.lang.String VALID_TIME_STRING
           
static java.lang.String VALID_TIMESTAMP_STRING
           
static int VARCHAR_FOR_BIT_OFFSET
           
static int VARCHAR_OFFSET
           
static boolean X
           
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
CastingTest(java.lang.String name)
           
 
Method Summary
private  void assertAllTypesCovered()
           
private  void assertBooleanResults(java.lang.String queryText, boolean expectedValue, int expectedRowCount)
           
private  void assertNoBoolean()
           
private  void assertScalarResult(java.lang.String queryText, int expectedValue)
           
private  java.sql.PreparedStatement chattyPrepare(java.lang.String text)
          Prepare a statement and report its sql text.
private static void checkSupportedAssignment(int sourceType, int targetType)
           
private static void checkSupportedCast(int sourceType, int targetType)
           
private static void checkSupportedComparison(int sourceType, int targetType)
           
private  void expectError(java.lang.String sqlState, java.lang.String query)
          Assert that the statement text, when compiled, raises an exception
private static java.lang.String formatString(java.lang.String str)
           
private static java.lang.String getCompatibleString(int sourceType, int targetType, int dataOffset)
           
private static java.lang.String getShortTypeName(int type)
          Truncates (*) from typename
private static java.lang.String getTableName(int type)
          Build a unique table name from the type
private  void goodStatement(java.lang.String ddl)
          Run good DDL.
private static boolean isBinaryType(int typeOffset)
           
private static boolean isCastException(java.sql.SQLException se)
           
private static boolean isCharacterType(int typeOffset)
           
private static boolean isClob(int typeOffset)
           
private static boolean isDateTimeTimestamp(int typeOffset)
           
private static boolean isLob(int typeOffset)
           
private static boolean isLongType(int typeOffset)
           
private static boolean isMethodNotFoundException(java.sql.SQLException se)
           
private static boolean isNotComparableException(java.sql.SQLException se)
           
private static boolean isNotStorableException(java.sql.SQLException se)
           
private static boolean isSupportedAssignment(int sourceType, int targetType)
           
private static boolean isSupportedCast(int sourceType, int targetType)
           
private static boolean isSupportedComparison(int sourceType, int targetType)
           
private  java.lang.String makeCastedColumnList(java.lang.String columnName, CastingTest.TypedColumn[] targetTypes)
           
private  java.lang.String makeColumnList(CastingTest.TypedColumn[] columns)
           
private  java.lang.String makeRepeatedColumnList(java.lang.String columnName, int N)
           
private  void makeTableForCasts(java.lang.String tableName, CastingTest.TypedColumn[] columns)
           
protected  void setUp()
           
private static boolean sqlStateMatches(java.sql.SQLException se, java.lang.String expectedValue)
           
static junit.framework.Test suite()
          Testing server-side behaviour so run in embedded only.
protected  void tearDown()
          Tear down this fixture, sub-classes should call super.tearDown().
 void test_derby887()
          Verify that DERBY-887 is fixed.
 void test_illegalBooleanCasts()
           Verify that the illegal boolean casts work as expected.
 void test_legalBooleanCasts()
           Verify that the legal boolean casts work as expected.
 void testAssignments()
           
 void testComparisons()
           
 void testExplicitCasts()
           
 
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, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, 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, 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

VALID_DATE_STRING

public static java.lang.String VALID_DATE_STRING

VALID_TIME_STRING

public static java.lang.String VALID_TIME_STRING

VALID_TIMESTAMP_STRING

public static java.lang.String VALID_TIMESTAMP_STRING

NULL_VALUE

public static java.lang.String NULL_VALUE

ILLEGAL_CAST_EXCEPTION_SQLSTATE

public static java.lang.String ILLEGAL_CAST_EXCEPTION_SQLSTATE

LANG_NOT_STORABLE_SQLSTATE

public static java.lang.String LANG_NOT_STORABLE_SQLSTATE

LANG_NOT_COMPARABLE_SQLSTATE

public static java.lang.String LANG_NOT_COMPARABLE_SQLSTATE

METHOD_NOT_FOUND_SQLSTATE

public static java.lang.String METHOD_NOT_FOUND_SQLSTATE

LANG_FORMAT_EXCEPTION_SQLSTATE

public static java.lang.String LANG_FORMAT_EXCEPTION_SQLSTATE

SQLTYPE_ARRAY_SIZE

public static int SQLTYPE_ARRAY_SIZE

SMALLINT_OFFSET

public static int SMALLINT_OFFSET

INTEGER_OFFSET

public static int INTEGER_OFFSET

BIGINT_OFFSET

public static int BIGINT_OFFSET

DECIMAL_OFFSET

public static int DECIMAL_OFFSET

REAL_OFFSET

public static int REAL_OFFSET

DOUBLE_OFFSET

public static int DOUBLE_OFFSET

CHAR_OFFSET

public static int CHAR_OFFSET

VARCHAR_OFFSET

public static int VARCHAR_OFFSET

LONGVARCHAR_OFFSET

public static int LONGVARCHAR_OFFSET

CHAR_FOR_BIT_OFFSET

public static int CHAR_FOR_BIT_OFFSET

VARCHAR_FOR_BIT_OFFSET

public static int VARCHAR_FOR_BIT_OFFSET

LONGVARCHAR_FOR_BIT_OFFSET

public static int LONGVARCHAR_FOR_BIT_OFFSET

CLOB_OFFSET

public static int CLOB_OFFSET

DATE_OFFSET

public static int DATE_OFFSET

TIME_OFFSET

public static int TIME_OFFSET

TIMESTAMP_OFFSET

public static int TIMESTAMP_OFFSET

BLOB_OFFSET

public static int BLOB_OFFSET

jdbcTypes

public static int[] jdbcTypes

NULL_DATA_OFFSET

public static int NULL_DATA_OFFSET

VALID_DATA_OFFSET

public static int VALID_DATA_OFFSET

SQLData

public static java.lang.String[][] SQLData

_

public static final boolean _
See Also:
Constant Field Values

X

public static final boolean X
See Also:
Constant Field Values

T_146

public static final boolean[][] T_146
Table 146 - Supported explicit casts between Built-in DataTypes This table has THE FOR BIT DATA TYPES broken out into separate columns for clarity and testing


T_147a

public static final boolean[][] T_147a
Table 147 describes Data Type Compatibility for Assignments The table 147a covers the assignments as they do differ somewhat from comparisons which can be found in 147b


T_147b

public static final boolean[][] T_147b

explicitCastValues

private static final java.lang.String[][] explicitCastValues

LEGAL_BOOLEAN_CASTS

private static final CastingTest.TypedColumn[] LEGAL_BOOLEAN_CASTS

ILLEGAL_BOOLEAN_CASTS

private static final CastingTest.TypedColumn[] ILLEGAL_BOOLEAN_CASTS
Constructor Detail

CastingTest

public CastingTest(java.lang.String name)
Method Detail

setUp

protected void setUp()
              throws java.sql.SQLException
Overrides:
setUp in class junit.framework.TestCase
Throws:
java.sql.SQLException

testAssignments

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

testExplicitCasts

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

testComparisons

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

test_derby887

public void test_derby887()
                   throws java.lang.Exception
Verify that DERBY-887 is fixed.

Throws:
java.lang.Exception

test_legalBooleanCasts

public void test_legalBooleanCasts()
                            throws java.lang.Exception

Verify that the legal boolean casts work as expected. This test helps verify that DERBY-887 is fixed. Verifies the following:

The following can't be tested until the BOOLEAN type is re-enabled:

Throws:
java.lang.Exception

makeTableForCasts

private void makeTableForCasts(java.lang.String tableName,
                               CastingTest.TypedColumn[] columns)
                        throws java.lang.Exception
Throws:
java.lang.Exception

makeColumnList

private java.lang.String makeColumnList(CastingTest.TypedColumn[] columns)

makeCastedColumnList

private java.lang.String makeCastedColumnList(java.lang.String columnName,
                                              CastingTest.TypedColumn[] targetTypes)

makeRepeatedColumnList

private java.lang.String makeRepeatedColumnList(java.lang.String columnName,
                                                int N)

assertBooleanResults

private void assertBooleanResults(java.lang.String queryText,
                                  boolean expectedValue,
                                  int expectedRowCount)
                           throws java.lang.Exception
Throws:
java.lang.Exception

assertScalarResult

private void assertScalarResult(java.lang.String queryText,
                                int expectedValue)
                         throws java.lang.Exception
Throws:
java.lang.Exception

assertNoBoolean

private void assertNoBoolean()
                      throws java.lang.Exception
Throws:
java.lang.Exception

assertAllTypesCovered

private void assertAllTypesCovered()
                            throws java.lang.Exception
Throws:
java.lang.Exception

test_illegalBooleanCasts

public void test_illegalBooleanCasts()
                              throws java.lang.Exception

Verify that the illegal boolean casts work as expected. This test helps verify that DERBY-887 is fixed. Verifies the following:

The following can't be tested until the BOOLEAN type is re-enabled:

Throws:
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.sql.SQLException,
                        java.lang.Exception
Description copied from class: BaseJDBCTestCase
Tear down this fixture, sub-classes should call super.tearDown(). This cleanups & closes the connection if it is open and any statement objects returned through the utility methods.

Overrides:
tearDown in class BaseJDBCTestCase
Throws:
java.sql.SQLException
java.lang.Exception

getTableName

private static java.lang.String getTableName(int type)
Build a unique table name from the type

Parameters:
type - table offset
Returns:
Table name in format _TAB. Replaces ' ' _;

getShortTypeName

private static java.lang.String getShortTypeName(int type)
Truncates (*) from typename

Parameters:
type - - Type offset
Returns:
short name of type (e.g DECIMAL instead of DECIMAL(10,5)

getCompatibleString

private static java.lang.String getCompatibleString(int sourceType,
                                                    int targetType,
                                                    int dataOffset)

isSupportedCast

private static boolean isSupportedCast(int sourceType,
                                       int targetType)

isSupportedAssignment

private static boolean isSupportedAssignment(int sourceType,
                                             int targetType)

isSupportedComparison

private static boolean isSupportedComparison(int sourceType,
                                             int targetType)

isCastException

private static boolean isCastException(java.sql.SQLException se)

isMethodNotFoundException

private static boolean isMethodNotFoundException(java.sql.SQLException se)

sqlStateMatches

private static boolean sqlStateMatches(java.sql.SQLException se,
                                       java.lang.String expectedValue)

isNotStorableException

private static boolean isNotStorableException(java.sql.SQLException se)

isNotComparableException

private static boolean isNotComparableException(java.sql.SQLException se)

checkSupportedCast

private static void checkSupportedCast(int sourceType,
                                       int targetType)

checkSupportedAssignment

private static void checkSupportedAssignment(int sourceType,
                                             int targetType)

checkSupportedComparison

private static void checkSupportedComparison(int sourceType,
                                             int targetType)

isLongType

private static boolean isLongType(int typeOffset)

isCharacterType

private static boolean isCharacterType(int typeOffset)

isBinaryType

private static boolean isBinaryType(int typeOffset)

isDateTimeTimestamp

private static boolean isDateTimeTimestamp(int typeOffset)

isClob

private static boolean isClob(int typeOffset)

isLob

private static boolean isLob(int typeOffset)

formatString

private static java.lang.String formatString(java.lang.String str)

goodStatement

private void goodStatement(java.lang.String ddl)
                    throws java.sql.SQLException
Run good DDL.

Throws:
java.sql.SQLException

expectError

private void expectError(java.lang.String sqlState,
                         java.lang.String query)
Assert that the statement text, when compiled, raises an exception


chattyPrepare

private java.sql.PreparedStatement chattyPrepare(java.lang.String text)
                                          throws java.sql.SQLException
Prepare a statement and report its sql text.

Throws:
java.sql.SQLException

suite

public static junit.framework.Test suite()
Testing server-side behaviour so run in embedded only.


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.