org.objectweb.cjdbc.driver
Class BlobTest

java.lang.Object
  extended byTestCase
      extended byorg.objectweb.cjdbc.driver.BlobTest

public class BlobTest
extends TestCase

Blob test class.

Author:
Nicolas Modrzyk
See Also:
Blob, PreparedStatement, Serialized Form

Field Summary
(package private)  java.lang.String cjdbcDriver
           
(package private)  java.lang.String cjdbcUrl
           
(package private)  java.sql.Connection con
          The connection to be used to the database for the test
(package private)  java.lang.String configFile
           
 
Constructor Summary
BlobTest()
           
 
Method Summary
 void displayResults(java.lang.String iamtested, boolean copy, boolean swithblob, boolean swithbytes)
          Display basic results on testing
static void main(java.lang.String[] args)
          The main program for the BlobTest class
 boolean pTestBigBlobStorage(java.lang.String storeFile)
          Send a file to database and retrieve it as a Blob object
private  boolean pTestBlobBytes(java.lang.String storeFile, boolean callBlobMethods)
          This is called by the methods above since contains very similar code.
 boolean pTestBlobWithBytes(java.lang.String storeFile)
          Test implementation of blobs without having to use the code specific to cjdbc.
 boolean pTestCopy(java.lang.String storeFile)
          Just copy a file to see if no data is lost.
(package private) static byte[] readBinary(java.io.File file)
          ReadBinary data from the file.
protected  void setUp()
          Load cjdbc driver and retrieve connection from database
static Test suite()
          A unit test suite for JUnit
 void testBlobCreation()
          Basic test to retrieve a blob and validate its content
 void testBlobs()
          Test a number of files to be copied and transfer and retrieved to the database.
 void testClob()
          Test method for clobs.
 void testHexMethods()
          Test Hexa methods conversion in the blob data
(package private) static void writeBinary(byte[] data, java.io.File file)
          WriteBinary data to the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cjdbcUrl

final java.lang.String cjdbcUrl
See Also:
Constant Field Values

configFile

final java.lang.String configFile
See Also:
Constant Field Values

cjdbcDriver

final java.lang.String cjdbcDriver
See Also:
Constant Field Values

con

java.sql.Connection con
The connection to be used to the database for the test

Constructor Detail

BlobTest

public BlobTest()
Method Detail

suite

public static Test suite()
A unit test suite for JUnit

Returns:
The test suite

main

public static void main(java.lang.String[] args)
The main program for the BlobTest class

Parameters:
args - The command line arguments

setUp

protected void setUp()
Load cjdbc driver and retrieve connection from database

See Also:
junit.framework.TestCase#setUp()

testHexMethods

public void testHexMethods()
Test Hexa methods conversion in the blob data


testClob

public void testClob()
Test method for clobs.


testBlobCreation

public void testBlobCreation()
Basic test to retrieve a blob and validate its content


testBlobs

public void testBlobs()
Test a number of files to be copied and transfer and retrieved to the database. The test fails if a single file test has failed, but a more in depth results is displayed

See Also:
pTestCopy, pTestBibBlobStorage, displayResults

displayResults

public void displayResults(java.lang.String iamtested,
                           boolean copy,
                           boolean swithblob,
                           boolean swithbytes)
Display basic results on testing

Parameters:
iamtested - is the file that was tested
copy - isSuccess
swithblob - result of test with blob
swithbytes - result of test with bytes

pTestCopy

public boolean pTestCopy(java.lang.String storeFile)
                  throws java.io.IOException
Just copy a file to see if no data is lost. Useful for binaries and special encoded files

Parameters:
storeFile - target file to copy
Returns:
true if size of copied file and original files are same.
Throws:
java.io.IOException - if read or write fails on targer storeFile

pTestBigBlobStorage

public boolean pTestBigBlobStorage(java.lang.String storeFile)
                            throws java.io.IOException,
                                   java.sql.SQLException
Send a file to database and retrieve it as a Blob object

Parameters:
storeFile - target file to manipulate as a Blob
Returns:
true if size of stored,retrieved file is same as original
Throws:
java.io.IOException - if write or read fails from target files
java.sql.SQLException - when talking to the database

pTestBlobWithBytes

public boolean pTestBlobWithBytes(java.lang.String storeFile)
                           throws java.io.IOException,
                                  java.sql.SQLException
Test implementation of blobs without having to use the code specific to cjdbc. This is exactly the same test as above without the call for the new instance method.

Parameters:
storeFile - the file to test
Returns:
true if the test was successful.
Throws:
java.io.IOException - if problems reading blob
java.sql.SQLException - if sql problem on the server side

pTestBlobBytes

private boolean pTestBlobBytes(java.lang.String storeFile,
                               boolean callBlobMethods)
                        throws java.io.IOException,
                               java.sql.SQLException
This is called by the methods above since contains very similar code.

Parameters:
storeFile -
callBlobMethods -
Returns:
Throws:
java.io.IOException
java.sql.SQLException

readBinary

static byte[] readBinary(java.io.File file)
                  throws java.io.IOException
ReadBinary data from the file. Tested ok with writeBinary param file destination target

Throws:
java.io.IOException - if read fails from target

writeBinary

static void writeBinary(byte[] data,
                        java.io.File file)
                 throws java.io.IOException
WriteBinary data to the file. Tested ok with readBinary

Parameters:
data - to be written to the file
file - destination target
Throws:
java.io.IOException - if write fails on target


Copyright © 2002, 2003 - ObjectWeb Consortium - All Rights Reserved.