org.apache.derbyTesting.functionTests.tests.jdbcapi
Class ClobTest

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

public class ClobTest
extends BaseJDBCTestCase

Test the methods defined by the Clob interface.

Only methods defined by JDBC 3 or earlier are tested here, and the focus of the test is the interface methods. Less attention is given to inserting Clobs and fetching Clobs from the database.


Nested Class Summary
private static class ClobTest.ClobTestSetup
          Decorator creating the neccessary test data.
 
Field Summary
private  java.sql.Clob clob
          The Clob used for testing.
private static int nextUniqueId
          Next unique id for a Clob.
private static java.lang.String NORWEGIAN_LETTERS
          Test data, 18 characters long, containing only Norwegian letters.
private static int SET_ASCII_STREAM
          Constant for Clob.setAsciiStream method.
private static int SET_CHARACTER_STREAM
          Constant for Clob.setCharacterStream method.
private static int SET_STRING
          Constant for Clob.setString method.
private static int TRANSFER_BUFFER_SIZE
          Buffer size to use when transferring data between streams.
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
ClobTest(java.lang.String testName)
           
 
Method Summary
private  void executeTestPositionWithStringToken(java.lang.String token, long prefixLength)
          Insert text into a Clob using Clob.setAsciiStream(long) and then search for the specified token.
private  void insertDataWithToken(java.lang.String token, long pre, long post, int mode)
          Inserts data into the test Clob, referenced by this.clob.
protected  void setUp()
          Obtain a Clob containing the empty string.
static junit.framework.Test suite()
           
protected  void tearDown()
          Nullify reference to Clob.
private  void testCloningThroughAddBatch(boolean sourceAsStream, boolean autoCommit)
          Adds a series of Clobs into the test table using a batch, then deletes the Clobs inserted.
 void testCloningThroughAddBatchWithStream()
          Tests that cloning an SQLClob object works when a stream has been set as the source of the Clob.
 void testCloningThroughAddBatchWithString()
          Tests that cloning an SQLClob object works when a string has been set as the source of the Clob.
 void testGetLengthAfterTruncate()
          Tests that the length of a Clob isn't cached in such a way that the length isn't updated after truncation.
 void testGetSubString_BiggerThanInternalBuffer()
          Tests if big strings can be handled.
 void testGetSubString_PosNegative()
           
 void testGetSubString_PosOneTooBig()
           
 void testGetSubString_PosTooBig()
           
 void testGetSubString_RequestZeroLength_PosTooBig()
           
 void testGetSubString_RequestZeroLength_PosValid()
           
 void testInsertCharacter_ReadOnlyToTemporary()
          Tests that Derby specific end-of-stream markers aren't passed over to the temporary Clob, which doesn't use such markers.
 void testInsertStringInMiddle_Multibyte()
           
 void testInsertStringOnEmptyClob_Multibyte()
           
 void testInsertStringOnEmptyClob_Singlebyte()
           
 void testLengthAfterInsertOnEmpty()
          Tests that the length is updated correctly when inserting data.
 void testLengthAfterInsertOnLarge()
          Tests that the length is updated correctly when inserting data.
 void testLengthOnEmptyClob()
           
 void testPositionWithString_ASCII_SimplePartialRecurringPattern()
           
 void testPositionWithString_CJK()
           
 void testPositionWithString_IOS88591()
           
 void testPositionWithString_USASCII()
           
 void testReplaceMultibyteWithSingleByteBackwards()
           
 void testReplaceMultibyteWithSingleByteForwards()
           
 void testSetStringOnWrongOffset()
          Test setString() refuses wrong offset.
 void testSetStringWithBigPos()
          Test setString() refuses pos bigger than clob.length() + 1.
 void testSetStringWithEmptyString()
          Test setString() accepts a empty String, and just return 0.
 void testSetStringWithNull()
          Test setStrinng() refuses a Null String.
 void testSetStringWithWrongLen()
          Test setString() refuses wrong len.
 void testTruncateExactInMemory()
          Truncating a Clob to the current length should work.
 void testTruncateExactOnDisk()
          Truncating a Clob to the current length should work.
 void testTruncateTooLongInMemory()
          Specify a position that is larger then the Clob length.
 void testTruncateTooLongOnDisk()
          Specify a position that is larger then the Clob length.
 void testTruncateZeroInMemory()
          Truncating a Clob to the empty string.
 void testTruncateZeroOnDisk()
          Truncating a Clob to the empty string.
private  int transferData(java.io.InputStream source, java.io.OutputStream dest, int tz)
          Transfer data from an input stream to an output stream.
private  int transferData(java.io.Reader source, int tz)
           
private  int transferData(java.io.Reader source, java.io.Writer dest, int tz)
          Transfer data from a source Reader to a destination Writer.
private  void truncateToZero(long initSize)
          Truncates the default Clob to zero length and checks some basic operations on the empty Clob.
 
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

TRANSFER_BUFFER_SIZE

private static final int TRANSFER_BUFFER_SIZE
Buffer size to use when transferring data between streams.

See Also:
Constant Field Values

SET_STRING

private static final int SET_STRING
Constant for Clob.setString method.

See Also:
Constant Field Values

SET_ASCII_STREAM

private static final int SET_ASCII_STREAM
Constant for Clob.setAsciiStream method.

See Also:
Constant Field Values

SET_CHARACTER_STREAM

private static final int SET_CHARACTER_STREAM
Constant for Clob.setCharacterStream method.

See Also:
Constant Field Values

nextUniqueId

private static int nextUniqueId
Next unique id for a Clob. Note that this isn't accessed in a thread- safe way.


NORWEGIAN_LETTERS

private static final java.lang.String NORWEGIAN_LETTERS
Test data, 18 characters long, containing only Norwegian letters.

See Also:
Constant Field Values

clob

private java.sql.Clob clob
The Clob used for testing. It is reinitialized to a Clob containing the empty string for each test.

Constructor Detail

ClobTest

public ClobTest(java.lang.String testName)
Method Detail

testGetSubString_PosOneTooBig

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

testGetSubString_PosTooBig

public void testGetSubString_PosTooBig()

testGetSubString_PosNegative

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

testGetSubString_RequestZeroLength_PosValid

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

testGetSubString_RequestZeroLength_PosTooBig

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

testGetSubString_BiggerThanInternalBuffer

public void testGetSubString_BiggerThanInternalBuffer()
                                               throws java.io.IOException,
                                                      java.sql.SQLException
Tests if big strings can be handled.

The motivation for the test is to make sure big buffers are filled with the call to read inside a loop. Big in this sense means bigger than some internal buffer. This is typically around 8 KB or so, but we try something considerably bigger. If a char/byte array is attempted filled with a single call to read, the resulting string wil typically contain at positions after the size of the internal buffer.

Throws:
java.io.IOException
java.sql.SQLException

testLengthOnEmptyClob

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

testInsertStringOnEmptyClob_Singlebyte

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

testInsertStringOnEmptyClob_Multibyte

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

testInsertStringInMiddle_Multibyte

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

testLengthAfterInsertOnEmpty

public void testLengthAfterInsertOnEmpty()
                                  throws java.io.IOException,
                                         java.sql.SQLException
Tests that the length is updated correctly when inserting data.

Throws:
java.io.IOException
java.sql.SQLException

testLengthAfterInsertOnLarge

public void testLengthAfterInsertOnLarge()
                                  throws java.io.IOException,
                                         java.sql.SQLException
Tests that the length is updated correctly when inserting data.

Throws:
java.io.IOException
java.sql.SQLException

testReplaceMultibyteWithSingleByteForwards

public void testReplaceMultibyteWithSingleByteForwards()
                                                throws java.io.IOException,
                                                       java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

testReplaceMultibyteWithSingleByteBackwards

public void testReplaceMultibyteWithSingleByteBackwards()
                                                 throws java.io.IOException,
                                                        java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

testInsertCharacter_ReadOnlyToTemporary

public void testInsertCharacter_ReadOnlyToTemporary()
                                             throws java.io.IOException,
                                                    java.sql.SQLException
Tests that Derby specific end-of-stream markers aren't passed over to the temporary Clob, which doesn't use such markers.

Passing the marker over will normally result in a UTF encoding exception.

ID USAGE: reads id 2, writes id 10002

Throws:
java.io.IOException
java.sql.SQLException

testPositionWithString_ASCII_SimplePartialRecurringPattern

public void testPositionWithString_ASCII_SimplePartialRecurringPattern()
                                                                throws java.io.IOException,
                                                                       java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

testPositionWithString_USASCII

public void testPositionWithString_USASCII()
                                    throws java.io.IOException,
                                           java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

testPositionWithString_IOS88591

public void testPositionWithString_IOS88591()
                                     throws java.io.IOException,
                                            java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

testPositionWithString_CJK

public void testPositionWithString_CJK()
                                throws java.io.IOException,
                                       java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

testSetStringOnWrongOffset

public void testSetStringOnWrongOffset()
                                throws java.sql.SQLException
Test setString() refuses wrong offset.

Throws:
java.sql.SQLException

testSetStringWithWrongLen

public void testSetStringWithWrongLen()
                               throws java.sql.SQLException
Test setString() refuses wrong len.

Throws:
java.sql.SQLException

testSetStringWithBigPos

public void testSetStringWithBigPos()
                             throws java.sql.SQLException
Test setString() refuses pos bigger than clob.length() + 1.

Throws:
java.sql.SQLException

testSetStringWithNull

public void testSetStringWithNull()
                           throws java.sql.SQLException
Test setStrinng() refuses a Null String.

Throws:
java.sql.SQLException

testSetStringWithEmptyString

public void testSetStringWithEmptyString()
                                  throws java.sql.SQLException
Test setString() accepts a empty String, and just return 0.

Throws:
java.sql.SQLException

testTruncateZeroOnDisk

public void testTruncateZeroOnDisk()
                            throws java.io.IOException,
                                   java.sql.SQLException
Truncating a Clob to the empty string.

Throws:
java.io.IOException
java.sql.SQLException

testTruncateZeroInMemory

public void testTruncateZeroInMemory()
                              throws java.io.IOException,
                                     java.sql.SQLException
Truncating a Clob to the empty string.

Throws:
java.io.IOException
java.sql.SQLException

truncateToZero

private void truncateToZero(long initSize)
                     throws java.io.IOException,
                            java.sql.SQLException
Truncates the default Clob to zero length and checks some basic operations on the empty Clob.

Parameters:
initSize - the expected size of the Clob to truncate
Throws:
java.io.IOException
java.sql.SQLException

testTruncateExactOnDisk

public void testTruncateExactOnDisk()
                             throws java.io.IOException,
                                    java.sql.SQLException
Truncating a Clob to the current length should work.

Throws:
java.io.IOException
java.sql.SQLException

testTruncateExactInMemory

public void testTruncateExactInMemory()
                               throws java.io.IOException,
                                      java.sql.SQLException
Truncating a Clob to the current length should work.

Throws:
java.io.IOException
java.sql.SQLException

testTruncateTooLongOnDisk

public void testTruncateTooLongOnDisk()
                               throws java.io.IOException,
                                      java.sql.SQLException
Specify a position that is larger then the Clob length.

This operation should fail and raise an exception.

Throws:
java.io.IOException
java.sql.SQLException

testTruncateTooLongInMemory

public void testTruncateTooLongInMemory()
                                 throws java.io.IOException,
                                        java.sql.SQLException
Specify a position that is larger then the Clob length.

This operation should fail and raise an exception.

Throws:
java.io.IOException
java.sql.SQLException

testGetLengthAfterTruncate

public void testGetLengthAfterTruncate()
                                throws java.io.IOException,
                                       java.sql.SQLException
Tests that the length of a Clob isn't cached in such a way that the length isn't updated after truncation.

Throws:
java.io.IOException
java.sql.SQLException

testCloningThroughAddBatchWithStream

public void testCloningThroughAddBatchWithStream()
                                          throws java.sql.SQLException
Tests that cloning an SQLClob object works when a stream has been set as the source of the Clob.

See DERBY-4278

Throws:
java.sql.SQLException - if something goes wrong

testCloningThroughAddBatchWithString

public void testCloningThroughAddBatchWithString()
                                          throws java.sql.SQLException
Tests that cloning an SQLClob object works when a string has been set as the source of the Clob.

Throws:
java.sql.SQLException - if something goes wrong

testCloningThroughAddBatch

private void testCloningThroughAddBatch(boolean sourceAsStream,
                                        boolean autoCommit)
                                 throws java.sql.SQLException
Adds a series of Clobs into the test table using a batch, then deletes the Clobs inserted.

Parameters:
sourceAsStream - whether the source shall be specified as a stream or a string
autoCommit - auto commit mode to run with
Throws:
java.sql.SQLException - if something goes wrong

executeTestPositionWithStringToken

private void executeTestPositionWithStringToken(java.lang.String token,
                                                long prefixLength)
                                         throws java.io.IOException,
                                                java.sql.SQLException
Insert text into a Clob using Clob.setAsciiStream(long) and then search for the specified token.

Some data is inserted before and after the token, and the specified token is converted to bytes by using the ISO-8859-1 encoding. Note that ascii in JDBC is equivalent to ISO-8859-1, not US-ASCII.

Throws:
java.io.IOException
java.sql.SQLException

setUp

protected void setUp()
              throws java.lang.Exception
Obtain a Clob containing the empty string.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.lang.Exception
Nullify reference to Clob.

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

suite

public static junit.framework.Test suite()

transferData

private int transferData(java.io.InputStream source,
                         java.io.OutputStream dest,
                         int tz)
                  throws java.io.IOException
Transfer data from an input stream to an output stream.

Parameters:
source - source data
dest - destination to write to
tz - buffer size in number of bytes. Must be 1 or greater.
Returns:
Number of bytes read from the source data. This should equal the number of bytes written to the destination.
Throws:
java.io.IOException

transferData

private int transferData(java.io.Reader source,
                         java.io.Writer dest,
                         int tz)
                  throws java.io.IOException
Transfer data from a source Reader to a destination Writer.

Parameters:
source - source data
dest - destination to write to
tz - buffer size in number of characters. Must be 1 or greater.
Returns:
Number of characters read from the source data. This should equal the number of characters written to the destination.
Throws:
java.io.IOException

transferData

private int transferData(java.io.Reader source,
                         int tz)
                  throws java.io.IOException,
                         java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

insertDataWithToken

private void insertDataWithToken(java.lang.String token,
                                 long pre,
                                 long post,
                                 int mode)
                          throws java.io.IOException,
                                 java.sql.SQLException
Inserts data into the test Clob, referenced by this.clob.

Parameters:
token - a token to insert into the Clob, cannot be null but the empty string is accepted
pre - number of characters to insert before the token, using the repeating alphabet stream (latin lower-case)
post - number of characters to insert after the token, using the repeating alphabet stream (latin lower-case)
mode - insertion mode; SET_STRING, SET_ASCII_STREAM or SET_CHARACTER_STREAM
Throws:
java.io.IOException - if inserting data fails for some reason
java.sql.SQLException - if inserting data fails for some reason

Built on Thu 2009-11-26 18:42:53-0800, from revision 884739

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