Skip to content

Commit

Permalink
HHH-5704 : Added tests for empty blob, clob, text, and image
Browse files Browse the repository at this point in the history
  • Loading branch information
gbadner committed Feb 2, 2011
1 parent 8e832d8 commit 6b2a698
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
Expand Up @@ -71,6 +71,7 @@ public boolean appliesTo(Dialect dialect) {
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();
Expand Down Expand Up @@ -121,11 +122,21 @@ public void testBoundedBlobLocatorAccess() throws Throwable {
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() );
assertEquals( empty.length, entity.getBlobLocator().length() );
assertEquals( empty, extractData( entity.getBlobLocator() ) );
s.delete( entity );
s.getTransaction().commit();
s.close();
Expand Down
Expand Up @@ -34,6 +34,7 @@
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
Expand Down Expand Up @@ -68,6 +69,7 @@ public boolean appliesTo(Dialect dialect) {
public void testBoundedClobLocatorAccess() throws Throwable {
String original = buildRecursively( CLOB_SIZE, 'x' );
String changed = buildRecursively( CLOB_SIZE, 'y' );
String empty = "";

Session s = openSession();
s.beginTransaction();
Expand Down Expand Up @@ -118,11 +120,21 @@ public void testBoundedClobLocatorAccess() throws Throwable {
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() );
assertEquals( empty.length(), entity.getClobLocator().length() );
assertEquals( empty, extractData( entity.getClobLocator() ) );
s.delete( entity );
s.getTransaction().commit();
s.close();
Expand Down
Expand Up @@ -45,6 +45,7 @@ public LongByteArrayTest(String name) {
public void testBoundedLongByteArrayAccess() {
byte[] original = buildRecursively( ARRAY_SIZE, true );
byte[] changed = buildRecursively( ARRAY_SIZE, false );
byte[] empty = new byte[] {};

Session s = openSession();
s.beginTransaction();
Expand Down Expand Up @@ -83,6 +84,15 @@ public void testBoundedLongByteArrayAccess() {
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() );
assertEquals( empty.length, entity.getLongByteArray().length );
assertEquals( empty, entity.getLongByteArray() );
s.delete( entity );
s.getTransaction().commit();
s.close();
Expand Down
10 changes: 10 additions & 0 deletions testsuite/src/test/java/org/hibernate/test/lob/LongStringTest.java
Expand Up @@ -43,6 +43,7 @@ public LongStringTest(String name) {
public void testBoundedLongStringAccess() {
String original = buildRecursively( LONG_STRING_SIZE, 'x' );
String changed = buildRecursively( LONG_STRING_SIZE, 'y' );
String empty = "";

Session s = openSession();
s.beginTransaction();
Expand Down Expand Up @@ -81,6 +82,15 @@ public void testBoundedLongStringAccess() {
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() );
assertEquals( empty.length(), entity.getLongString().length() );
assertEquals( empty, entity.getLongString() );
s.delete( entity );
s.getTransaction().commit();
s.close();
Expand Down
Expand Up @@ -34,6 +34,7 @@ public String getCacheConcurrencyStrategy() {
public void testNewSerializableType() {
final String initialPayloadText = "Initial payload";
final String changedPayloadText = "Changed payload";
final String empty = "";

Session s = openSession();
s.beginTransaction();
Expand Down Expand Up @@ -72,6 +73,15 @@ public void testNewSerializableType() {
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();
Expand Down

0 comments on commit 6b2a698

Please sign in to comment.