From 0c96fd75af1a53533b47787e3de9f2f2af6154aa Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 8 Sep 2021 09:14:28 +0200 Subject: [PATCH] Re-enabled additional tests --- .../sql/PreparedStatementProxy.java | 13 +++--- .../type/descriptor/sql/ResultSetProxy.java | 7 ++-- .../type/descriptor/sql/StringClobImpl.java | 2 +- .../sql/StringValueMappingTest.java | 40 +++++++++++++------ 4 files changed, 39 insertions(+), 23 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/type/descriptor/sql/PreparedStatementProxy.java (86%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/type/descriptor/sql/ResultSetProxy.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/type/descriptor/sql/StringClobImpl.java (97%) rename hibernate-core/src/{test_legacy/org/hibernate => test/java/org/hibernate/orm}/test/type/descriptor/sql/StringValueMappingTest.java (76%) diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/PreparedStatementProxy.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/PreparedStatementProxy.java similarity index 86% rename from hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/PreparedStatementProxy.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/PreparedStatementProxy.java index fc83894994..d07cf43f68 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/PreparedStatementProxy.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/PreparedStatementProxy.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.type.descriptor.sql; +package org.hibernate.orm.test.type.descriptor.sql; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -12,7 +13,7 @@ import java.sql.Clob; import java.sql.PreparedStatement; import java.sql.SQLException; -import junit.framework.Assert; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * TODO : javadoc @@ -39,7 +40,7 @@ public class PreparedStatementProxy implements InvocationHandler { @SuppressWarnings({ "unchecked" }) public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ( value == null ) { - Assert.assertEquals( "Expecting setNull call", "setNull", method.getName() ); + assertEquals( "setNull", method.getName(), "Expecting setNull call" ); return null; } if ( method.getName().equals( methodName ) && args.length >= 1 ) { @@ -50,14 +51,14 @@ public class PreparedStatementProxy implements InvocationHandler { } protected void checkValue(T arg) throws SQLException { - Assert.assertEquals( value, arg ); + assertEquals( value, arg ); } protected final String extractString(Clob clob) throws SQLException { if ( StringClobImpl.class.isInstance( clob ) ) { return ( (StringClobImpl) clob ).getValue(); } - return clob.getSubString( 1, (int)clob.length() ); + return clob.getSubString( 1, (int) clob.length() ); } private final String methodName; @@ -83,7 +84,7 @@ public class PreparedStatementProxy implements InvocationHandler { new PreparedStatementProxy( "setClob", value ) { @Override protected void checkValue(Clob arg) throws SQLException { - Assert.assertEquals( extractString( getValue() ), extractString( arg ) ); + assertEquals( extractString( getValue() ), extractString( arg ) ); } } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/ResultSetProxy.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/ResultSetProxy.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/ResultSetProxy.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/ResultSetProxy.java index cec79141bc..6a74d7d52c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/ResultSetProxy.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/ResultSetProxy.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.type.descriptor.sql; +package org.hibernate.orm.test.type.descriptor.sql; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -53,13 +54,13 @@ public class ResultSetProxy implements InvocationHandler { public static ResultSet generateProxy(final String value) { return generateProxy( - new ResultSetProxy( "getString", value ) + new ResultSetProxy<>( "getString", value ) ); } public static ResultSet generateProxy(final Clob value) { return generateProxy( - new ResultSetProxy( "getClob", value ) + new ResultSetProxy<>( "getClob", value ) ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringClobImpl.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/StringClobImpl.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringClobImpl.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/StringClobImpl.java index 8931013da7..ac3aba193c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/sql/StringClobImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/StringClobImpl.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.type.descriptor.sql; +package org.hibernate.orm.test.type.descriptor.sql; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/type/descriptor/sql/StringValueMappingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/StringValueMappingTest.java similarity index 76% rename from hibernate-core/src/test_legacy/org/hibernate/test/type/descriptor/sql/StringValueMappingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/StringValueMappingTest.java index b7d1fac853..21940b95ca 100644 --- a/hibernate-core/src/test_legacy/org/hibernate/test/type/descriptor/sql/StringValueMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/sql/StringValueMappingTest.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.type.descriptor.sql; +package org.hibernate.orm.test.type.descriptor.sql; + import java.sql.Clob; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -13,39 +14,52 @@ import java.util.TimeZone; import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator; +import org.hibernate.engine.spi.SharedSessionContractImplementor; 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.jdbc.ClobTypeDescriptor; -import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.VarcharTypeDescriptor; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.BaseUnitTest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Steve Ebersole */ -public class StringValueMappingTest extends BaseUnitTestCase { +@BaseUnitTest +public class StringValueMappingTest { private final StringTypeDescriptor stringJavaDescriptor = new StringTypeDescriptor(); private final VarcharTypeDescriptor varcharSqlDescriptor = new VarcharTypeDescriptor(); private final ClobTypeDescriptor clobSqlDescriptor = ClobTypeDescriptor.DEFAULT; private final WrapperOptions wrapperOptions = new WrapperOptions() { + @Override + public SharedSessionContractImplementor getSession() { + return getSession(); + } + public boolean useStreamForLobBinding() { return false; } + @Override + public int getPreferredSqlTypeCodeForBoolean() { + return 0; + } + public LobCreator getLobCreator() { return NonContextualLobCreator.INSTANCE; } - public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) { + public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor sqlTypeDescriptor) { return sqlTypeDescriptor; } @@ -55,7 +69,7 @@ public class StringValueMappingTest extends BaseUnitTestCase { } }; - public static final String COLUMN_NAME = "n/a"; + public static final int COLUMN_POSITION = 0; public static final int BIND_POSITION = -1; @Test @@ -66,7 +80,7 @@ public class StringValueMappingTest extends BaseUnitTestCase { final String fixture = "string value"; ResultSet resultSet = ResultSetProxy.generateProxy( fixture ); - final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions ); + final String value = extractor.extract( resultSet, COLUMN_POSITION, wrapperOptions ); assertEquals( fixture, value ); PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture ); @@ -81,7 +95,7 @@ public class StringValueMappingTest extends BaseUnitTestCase { final String fixture = null; ResultSet resultSet = ResultSetProxy.generateProxy( fixture ); - final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions ); + final String value = extractor.extract( resultSet, COLUMN_POSITION, wrapperOptions ); assertEquals( fixture, value ); PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture ); @@ -97,7 +111,7 @@ public class StringValueMappingTest extends BaseUnitTestCase { final Clob clob = new StringClobImpl( fixture ); ResultSet resultSet = ResultSetProxy.generateProxy( clob ); - final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions ); + final String value = extractor.extract( resultSet, COLUMN_POSITION, wrapperOptions ); assertEquals( fixture, value ); PreparedStatement ps = PreparedStatementProxy.generateProxy( clob ); @@ -113,7 +127,7 @@ public class StringValueMappingTest extends BaseUnitTestCase { final Clob clob = null; ResultSet resultSet = ResultSetProxy.generateProxy( clob ); - final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions ); + final String value = extractor.extract( resultSet, COLUMN_POSITION, wrapperOptions ); assertNull( value ); PreparedStatement ps = PreparedStatementProxy.generateProxy( clob );