From 700ec50beaa95fd4925c3aa0dd55b3b633bae7b6 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 15 Aug 2013 13:07:05 -0400 Subject: [PATCH] HHH-8207 - Locale conversion is broken Conflicts: hibernate-core/src/test/java/org/hibernate/test/type/AttributeConverterTest.java --- .../type/BasicTypeRegistryTest.java | 11 ++- .../hibernate/{ => test}/type/TypeTest.java | 35 +++++++- .../java/AbstractDescriptorTest.java | 4 +- .../java/BigDecimalDescriptorTest.java | 4 +- .../java/BigIntegerDescriptorTest.java | 4 +- .../descriptor/java/BlobDescriptorTest.java | 27 ++---- .../java/BooleanDescriptorTest.java | 4 +- .../java/LocaleTypeDescriptorTest.java | 69 +++++++++++++++ .../descriptor/java/StringDescriptorTest.java | 4 +- .../sql/PreparedStatementProxy.java | 2 +- .../type/descriptor/sql/ResultSetProxy.java | 2 +- .../type/descriptor/sql/StringClobImpl.java | 2 +- .../sql/StringValueMappingTest.java | 5 +- .../descriptor/java/BlobDescriptorTest.java | 84 ------------------- 14 files changed, 141 insertions(+), 116 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/BasicTypeRegistryTest.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/TypeTest.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/java/AbstractDescriptorTest.java (97%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/java/BigDecimalDescriptorTest.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/java/BigIntegerDescriptorTest.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/java/BooleanDescriptorTest.java (93%) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/java/StringDescriptorTest.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/sql/PreparedStatementProxy.java (98%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/sql/ResultSetProxy.java (98%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/sql/StringClobImpl.java (98%) rename hibernate-core/src/test/java/org/hibernate/{ => test}/type/descriptor/sql/StringValueMappingTest.java (95%) delete mode 100644 hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/BasicTypeRegistryTest.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/BasicTypeRegistryTest.java index a898e7a17d..ed9b7cc6b3 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/BasicTypeRegistryTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type; +package org.hibernate.test.type; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -33,6 +33,15 @@ import org.junit.Test; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.testing.junit4.BaseUnitTestCase; + +import org.hibernate.type.AbstractSingleColumnStandardBasicType; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; +import org.hibernate.type.CompositeCustomType; +import org.hibernate.type.CustomType; +import org.hibernate.type.Type; +import org.hibernate.type.UUIDBinaryType; +import org.hibernate.type.UUIDCharType; import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; import org.hibernate.usertype.CompositeUserType; diff --git a/hibernate-core/src/test/java/org/hibernate/type/TypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/TypeTest.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/type/TypeTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/TypeTest.java index 541725b034..3f6a6de910 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/TypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/TypeTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type; +package org.hibernate.test.type; import java.io.Serializable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -45,6 +45,39 @@ import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.util.SerializationHelper; import org.hibernate.internal.util.collections.ArrayHelper; +import org.hibernate.type.AbstractSingleColumnStandardBasicType; +import org.hibernate.type.BigDecimalType; +import org.hibernate.type.BigIntegerType; +import org.hibernate.type.BinaryType; +import org.hibernate.type.BooleanType; +import org.hibernate.type.ByteType; +import org.hibernate.type.CalendarDateType; +import org.hibernate.type.CalendarType; +import org.hibernate.type.CharArrayType; +import org.hibernate.type.CharacterArrayType; +import org.hibernate.type.CharacterType; +import org.hibernate.type.ClassType; +import org.hibernate.type.CurrencyType; +import org.hibernate.type.DateType; +import org.hibernate.type.DoubleType; +import org.hibernate.type.FloatType; +import org.hibernate.type.ImageType; +import org.hibernate.type.IntegerType; +import org.hibernate.type.LocaleType; +import org.hibernate.type.LongType; +import org.hibernate.type.MaterializedBlobType; +import org.hibernate.type.MaterializedClobType; +import org.hibernate.type.NumericBooleanType; +import org.hibernate.type.SerializableType; +import org.hibernate.type.ShortType; +import org.hibernate.type.StringType; +import org.hibernate.type.TextType; +import org.hibernate.type.TimeType; +import org.hibernate.type.TimeZoneType; +import org.hibernate.type.TimestampType; +import org.hibernate.type.TrueFalseType; +import org.hibernate.type.YesNoType; + import org.hibernate.testing.junit4.BaseUnitTestCase; import static org.junit.Assert.assertFalse; diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/AbstractDescriptorTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/AbstractDescriptorTest.java index 312aeaaa14..ba8a2a1c40 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/AbstractDescriptorTest.java @@ -21,11 +21,13 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.java; +package org.hibernate.test.type.descriptor.java; import java.io.Serializable; import java.sql.Blob; import java.sql.Clob; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; + import org.junit.Before; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BigDecimalDescriptorTest.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BigDecimalDescriptorTest.java index c3924ffadd..0643102cdc 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BigDecimalDescriptorTest.java @@ -21,9 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.java; +package org.hibernate.test.type.descriptor.java; import java.math.BigDecimal; +import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor; + /** * @author Steve Ebersole */ diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BigIntegerDescriptorTest.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BigIntegerDescriptorTest.java index fceb752037..76ec3e94bb 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BigIntegerDescriptorTest.java @@ -21,9 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.java; +package org.hibernate.test.type.descriptor.java; import java.math.BigInteger; +import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor; + /** * @author Steve Ebersole */ diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BlobDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BlobDescriptorTest.java index bb5f5894d9..b5f1cd2935 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BlobDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BlobDescriptorTest.java @@ -22,24 +22,19 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.type.descriptor.java; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; import java.sql.Blob; import java.sql.SQLException; -import org.hibernate.engine.jdbc.BlobImplementer; +import org.junit.Test; + import org.hibernate.engine.jdbc.BlobProxy; -import org.hibernate.testing.TestForIssue; -import org.hibernate.type.descriptor.java.AbstractDescriptorTest; import org.hibernate.type.descriptor.java.BlobTypeDescriptor; import org.hibernate.type.descriptor.java.DataHelper; import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor; -import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Steve Ebersole @@ -89,14 +84,4 @@ public class BlobDescriptorTest extends AbstractDescriptorTest { fail( "SQLException accessing blob : " + e.getMessage() ); } } - - @Test - @TestForIssue( jiraKey = "HHH-8193" ) - public void testStreamResetOnAccess() throws IOException { - byte[] bytes = new byte[] { 1, 2, 3, 4 }; - BlobImplementer blob = (BlobImplementer) BlobProxy.generateProxy( bytes ); - int value = blob.getUnderlyingStream().getInputStream().read(); - // Call to BlobImplementer#getUnderlyingStream() should mark input stream for reset. - assertEquals( bytes.length, blob.getUnderlyingStream().getInputStream().available() ); - } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BooleanDescriptorTest.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BooleanDescriptorTest.java index 15cb04dd24..a045f548c6 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/BooleanDescriptorTest.java @@ -21,9 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.java; +package org.hibernate.test.type.descriptor.java; +import org.hibernate.type.descriptor.java.BooleanTypeDescriptor; + /** * @author Steve Ebersole */ diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java new file mode 100644 index 0000000000..8584106acc --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.type.descriptor.java; + +import java.util.Locale; +import java.util.StringTokenizer; + +import org.hibernate.internal.util.StringHelper; +import org.hibernate.type.descriptor.java.LocaleTypeDescriptor; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; + +/** + * Tests of the {@link LocaleTypeDescriptor} class. + * + * @author Christian Beikov + * @author Steve Ebersole + */ +public class LocaleTypeDescriptorTest extends BaseUnitTestCase { + @Test + public void testConversionFromString() { + assertEquals( toLocale( "de", null, null ), LocaleTypeDescriptor.INSTANCE.fromString( "de" ) ); + assertEquals( toLocale( "de", "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE" ) ); + assertEquals( toLocale( null, "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE" ) ); + assertEquals( toLocale( null, null, "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "__ch" ) ); + assertEquals( toLocale( null, "DE", "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE_ch" ) ); + assertEquals( toLocale( "de", null, "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "de__ch" ) ); + assertEquals( toLocale( "de", "DE", "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE_ch" ) ); + } + + public Locale toLocale(String lang, String region, String variant) { + final Locale.Builder builder = new Locale.Builder(); + if ( StringHelper.isNotEmpty( lang ) ) { + builder.setLanguage( lang ); + } + if ( StringHelper.isNotEmpty( region ) ) { + builder.setRegion( region ); + } + if ( StringHelper.isNotEmpty( variant ) ) { + builder.setVariant( variant ); + } + return builder.build(); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/StringDescriptorTest.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/StringDescriptorTest.java index 496358865c..df48304864 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/StringDescriptorTest.java @@ -21,9 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.java; +package org.hibernate.test.type.descriptor.java; +import org.hibernate.type.descriptor.java.StringTypeDescriptor; + /** * @author Steve Ebersole */ diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/PreparedStatementProxy.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/PreparedStatementProxy.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/PreparedStatementProxy.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/PreparedStatementProxy.java index 521f1cd749..2429ed9c2f 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/PreparedStatementProxy.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/PreparedStatementProxy.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.sql; +package org.hibernate.test.type.descriptor.sql; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/ResultSetProxy.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/ResultSetProxy.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/ResultSetProxy.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/ResultSetProxy.java index 5406a25a75..a8932c1d39 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/ResultSetProxy.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/ResultSetProxy.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.sql; +package org.hibernate.test.type.descriptor.sql; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringClobImpl.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringClobImpl.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringClobImpl.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringClobImpl.java index e7e362c459..3a0246e492 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringClobImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringClobImpl.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.sql; +package org.hibernate.test.type.descriptor.sql; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringValueMappingTest.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java rename to hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringValueMappingTest.java index 2803819df3..992cb643e1 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringValueMappingTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.type.descriptor.sql; +package org.hibernate.test.type.descriptor.sql; import java.sql.Clob; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -36,6 +36,9 @@ import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.StringTypeDescriptor; +import org.hibernate.type.descriptor.sql.ClobTypeDescriptor; +import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; +import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java deleted file mode 100644 index 8cdc89ab4e..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.type.descriptor.java; -import java.sql.Blob; -import java.sql.SQLException; - -import org.junit.Test; - -import org.hibernate.engine.jdbc.BlobProxy; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Steve Ebersole - */ -public class BlobDescriptorTest extends AbstractDescriptorTest { - final Blob original = BlobProxy.generateProxy( new byte[] { 1, 2, 3 } ); - final Blob copy = BlobProxy.generateProxy( new byte[] { 1, 2, 3 } ); - final Blob different = BlobProxy.generateProxy( new byte[] { 3, 2, 1 } ); - - public BlobDescriptorTest() { - super( BlobTypeDescriptor.INSTANCE ); - } - - @Override - protected Data getTestData() { - return new Data( original, copy, different ); - } - - @Override - protected boolean shouldBeMutable() { - return false; - } - - @Test - @Override - public void testEquality() { - // blobs of the same internal value are not really comparable - assertFalse( original == copy ); - assertTrue( BlobTypeDescriptor.INSTANCE.areEqual( original, original ) ); - assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, copy ) ); - assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, different ) ); - } - - @Test - @Override - public void testExternalization() { - // blobs of the same internal value are not really comparable - String externalized = BlobTypeDescriptor.INSTANCE.toString( original ); - Blob consumed = BlobTypeDescriptor.INSTANCE.fromString( externalized ); - try { - PrimitiveByteArrayTypeDescriptor.INSTANCE.areEqual( - DataHelper.extractBytes( original.getBinaryStream() ), - DataHelper.extractBytes( consumed.getBinaryStream() ) - ); - } - catch ( SQLException e ) { - fail( "SQLException accessing blob : " + e.getMessage() ); - } - } -} \ No newline at end of file