HHH-5704 HHH-5893 : Added tests for empty LOBs

This commit is contained in:
Gail Badner 2011-02-07 13:56:41 -08:00 committed by JPAV
parent c6a407332a
commit 4410a941e7
5 changed files with 64 additions and 9 deletions

View File

@ -68,6 +68,7 @@ public class BlobLocatorTest extends DatabaseSpecificFunctionalTestCase {
public void testBoundedBlobLocatorAccess() throws Throwable {
byte[] original = buildRecursively( BLOB_SIZE, true );
byte[] changed = buildRecursively( BLOB_SIZE, false );
byte[] empty = new byte[] {};
Session s = openSession();
s.beginTransaction();
@ -118,11 +119,23 @@ public class BlobLocatorTest extends DatabaseSpecificFunctionalTestCase {
s.getTransaction().commit();
s.close();
// test empty blob
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
assertEquals( changed, extractData( entity.getBlobLocator() ) );
entity.setBlobLocator( s.getLobHelper().createBlob( empty ) );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
if ( entity.getBlobLocator() != null) {
assertEquals( empty.length, entity.getBlobLocator().length() );
assertEquals( empty, extractData( entity.getBlobLocator() ) );
}
s.delete( entity );
s.getTransaction().commit();
s.close();

View File

@ -27,9 +27,11 @@ import junit.framework.Test;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.junit.functional.DatabaseSpecificFunctionalTestCase;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.type.descriptor.java.DataHelper;
import org.hibernate.util.StringHelper;
/**
* Tests lazy materialization of data mapped by
@ -64,6 +66,7 @@ public class ClobLocatorTest extends DatabaseSpecificFunctionalTestCase {
public void testBoundedClobLocatorAccess() throws Throwable {
String original = buildRecursively( CLOB_SIZE, 'x' );
String changed = buildRecursively( CLOB_SIZE, 'y' );
String empty = "";
Session s = openSession();
s.beginTransaction();
@ -114,11 +117,23 @@ public class ClobLocatorTest extends DatabaseSpecificFunctionalTestCase {
s.getTransaction().commit();
s.close();
// test empty clob
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
assertEquals( changed, extractData( entity.getClobLocator() ) );
entity.setClobLocator( s.getLobHelper().createClob( empty ) );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
if ( entity.getClobLocator() != null) {
assertEquals( empty.length(), entity.getClobLocator().length() );
assertEquals( empty, extractData( entity.getClobLocator() ) );
}
s.delete( entity );
s.getTransaction().commit();
s.close();
@ -163,14 +178,7 @@ public class ClobLocatorTest extends DatabaseSpecificFunctionalTestCase {
}
private String extractData(Clob clob) throws Throwable {
if ( getDialect() instanceof H2Dialect ) {
return clob.getSubString( 1, ( int ) clob.length() );
}
else {
char[] data = new char[ (int) clob.length() ];
clob.getCharacterStream().read( data );
return new String( data );
}
return DataHelper.extractString( clob.getCharacterStream() );
}

View File

@ -44,6 +44,7 @@ public abstract class LongByteArrayTest extends DatabaseSpecificFunctionalTestCa
public void testBoundedLongByteArrayAccess() {
byte[] original = buildRecursively( ARRAY_SIZE, true );
byte[] changed = buildRecursively( ARRAY_SIZE, false );
byte[] empty = new byte[] {};
Session s = openSession();
s.beginTransaction();
@ -82,6 +83,17 @@ public abstract class LongByteArrayTest extends DatabaseSpecificFunctionalTestCa
s.beginTransaction();
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
assertNull( entity.getLongByteArray() );
entity.setLongByteArray( empty );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
if ( entity.getLongByteArray() != null ) {
assertEquals( empty.length, entity.getLongByteArray().length );
assertEquals( empty, entity.getLongByteArray() );
}
s.delete( entity );
s.getTransaction().commit();
s.close();

View File

@ -42,6 +42,7 @@ public abstract class LongStringTest extends DatabaseSpecificFunctionalTestCase
public void testBoundedLongStringAccess() {
String original = buildRecursively( LONG_STRING_SIZE, 'x' );
String changed = buildRecursively( LONG_STRING_SIZE, 'y' );
String empty = "";
Session s = openSession();
s.beginTransaction();
@ -80,6 +81,17 @@ public abstract class LongStringTest extends DatabaseSpecificFunctionalTestCase
s.beginTransaction();
entity = ( LongStringHolder ) s.get( LongStringHolder.class, entity.getId() );
assertNull( entity.getLongString() );
entity.setLongString( empty );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
entity = ( LongStringHolder ) s.get( LongStringHolder.class, entity.getId() );
if ( entity.getLongString() != null ) {
assertEquals( empty.length(), entity.getLongString().length() );
assertEquals( empty, entity.getLongString() );
}
s.delete( entity );
s.getTransaction().commit();
s.close();

View File

@ -32,6 +32,7 @@ public class SerializableTypeTest extends FunctionalTestCase {
public void testNewSerializableType() {
final String initialPayloadText = "Initial payload";
final String changedPayloadText = "Changed payload";
final String empty = "";
Session s = openSession();
s.beginTransaction();
@ -70,6 +71,15 @@ public class SerializableTypeTest extends FunctionalTestCase {
s.beginTransaction();
holder = ( SerializableHolder ) s.get( SerializableHolder.class, holder.getId() );
assertNull( holder.getSerialData() );
holder.setSerialData( new SerializableData( empty ) );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
holder = ( SerializableHolder ) s.get( SerializableHolder.class, holder.getId() );
serialData = ( SerializableData ) holder.getSerialData();
assertEquals( empty, serialData.getPayload() );
s.delete( holder );
s.getTransaction().commit();
s.close();