Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2021-09-08 09:14:28 +02:00 committed by Christian Beikov
parent b2b8197388
commit 0c96fd75af
4 changed files with 39 additions and 23 deletions

View File

@ -4,7 +4,8 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.sql; package org.hibernate.orm.test.type.descriptor.sql;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
@ -12,7 +13,7 @@ import java.sql.Clob;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import junit.framework.Assert; import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* TODO : javadoc * TODO : javadoc
@ -39,7 +40,7 @@ public class PreparedStatementProxy<T> implements InvocationHandler {
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ( value == null ) { if ( value == null ) {
Assert.assertEquals( "Expecting setNull call", "setNull", method.getName() ); assertEquals( "setNull", method.getName(), "Expecting setNull call" );
return null; return null;
} }
if ( method.getName().equals( methodName ) && args.length >= 1 ) { if ( method.getName().equals( methodName ) && args.length >= 1 ) {
@ -50,14 +51,14 @@ public class PreparedStatementProxy<T> implements InvocationHandler {
} }
protected void checkValue(T arg) throws SQLException { protected void checkValue(T arg) throws SQLException {
Assert.assertEquals( value, arg ); assertEquals( value, arg );
} }
protected final String extractString(Clob clob) throws SQLException { protected final String extractString(Clob clob) throws SQLException {
if ( StringClobImpl.class.isInstance( clob ) ) { if ( StringClobImpl.class.isInstance( clob ) ) {
return ( (StringClobImpl) clob ).getValue(); return ( (StringClobImpl) clob ).getValue();
} }
return clob.getSubString( 1, (int)clob.length() ); return clob.getSubString( 1, (int) clob.length() );
} }
private final String methodName; private final String methodName;
@ -83,7 +84,7 @@ public class PreparedStatementProxy<T> implements InvocationHandler {
new PreparedStatementProxy<Clob>( "setClob", value ) { new PreparedStatementProxy<Clob>( "setClob", value ) {
@Override @Override
protected void checkValue(Clob arg) throws SQLException { protected void checkValue(Clob arg) throws SQLException {
Assert.assertEquals( extractString( getValue() ), extractString( arg ) ); assertEquals( extractString( getValue() ), extractString( arg ) );
} }
} }
); );

View File

@ -4,7 +4,8 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.sql; package org.hibernate.orm.test.type.descriptor.sql;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
@ -53,13 +54,13 @@ public class ResultSetProxy<T> implements InvocationHandler {
public static ResultSet generateProxy(final String value) { public static ResultSet generateProxy(final String value) {
return generateProxy( return generateProxy(
new ResultSetProxy<String>( "getString", value ) new ResultSetProxy<>( "getString", value )
); );
} }
public static ResultSet generateProxy(final Clob value) { public static ResultSet generateProxy(final Clob value) {
return generateProxy( return generateProxy(
new ResultSetProxy<Clob>( "getClob", value ) new ResultSetProxy<>( "getClob", value )
); );
} }
} }

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.sql; package org.hibernate.orm.test.type.descriptor.sql;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;

View File

@ -4,7 +4,8 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.sql; package org.hibernate.orm.test.type.descriptor.sql;
import java.sql.Clob; import java.sql.Clob;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -13,39 +14,52 @@ import java.util.TimeZone;
import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.ClobTypeDescriptor; 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.type.descriptor.jdbc.VarcharTypeDescriptor;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StringValueMappingTest extends BaseUnitTestCase { @BaseUnitTest
public class StringValueMappingTest {
private final StringTypeDescriptor stringJavaDescriptor = new StringTypeDescriptor(); private final StringTypeDescriptor stringJavaDescriptor = new StringTypeDescriptor();
private final VarcharTypeDescriptor varcharSqlDescriptor = new VarcharTypeDescriptor(); private final VarcharTypeDescriptor varcharSqlDescriptor = new VarcharTypeDescriptor();
private final ClobTypeDescriptor clobSqlDescriptor = ClobTypeDescriptor.DEFAULT; private final ClobTypeDescriptor clobSqlDescriptor = ClobTypeDescriptor.DEFAULT;
private final WrapperOptions wrapperOptions = new WrapperOptions() { private final WrapperOptions wrapperOptions = new WrapperOptions() {
@Override
public SharedSessionContractImplementor getSession() {
return getSession();
}
public boolean useStreamForLobBinding() { public boolean useStreamForLobBinding() {
return false; return false;
} }
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return 0;
}
public LobCreator getLobCreator() { public LobCreator getLobCreator() {
return NonContextualLobCreator.INSTANCE; return NonContextualLobCreator.INSTANCE;
} }
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) { public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor sqlTypeDescriptor) {
return 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; public static final int BIND_POSITION = -1;
@Test @Test
@ -66,7 +80,7 @@ public class StringValueMappingTest extends BaseUnitTestCase {
final String fixture = "string value"; final String fixture = "string value";
ResultSet resultSet = ResultSetProxy.generateProxy( fixture ); 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 ); assertEquals( fixture, value );
PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture ); PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture );
@ -81,7 +95,7 @@ public class StringValueMappingTest extends BaseUnitTestCase {
final String fixture = null; final String fixture = null;
ResultSet resultSet = ResultSetProxy.generateProxy( fixture ); 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 ); assertEquals( fixture, value );
PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture ); PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture );
@ -97,7 +111,7 @@ public class StringValueMappingTest extends BaseUnitTestCase {
final Clob clob = new StringClobImpl( fixture ); final Clob clob = new StringClobImpl( fixture );
ResultSet resultSet = ResultSetProxy.generateProxy( clob ); 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 ); assertEquals( fixture, value );
PreparedStatement ps = PreparedStatementProxy.generateProxy( clob ); PreparedStatement ps = PreparedStatementProxy.generateProxy( clob );
@ -113,7 +127,7 @@ public class StringValueMappingTest extends BaseUnitTestCase {
final Clob clob = null; final Clob clob = null;
ResultSet resultSet = ResultSetProxy.generateProxy( clob ); 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 ); assertNull( value );
PreparedStatement ps = PreparedStatementProxy.generateProxy( clob ); PreparedStatement ps = PreparedStatementProxy.generateProxy( clob );