HHH-16125 delete/fix a bunch of assertions that constrain implementation details
these are bad tests; they don't test observable behavior
This commit is contained in:
parent
7514f8ad00
commit
c91cfdf2f1
|
@ -20,6 +20,7 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -56,11 +57,8 @@ public class NestedEmbeddableMetadataTest {
|
|||
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
|
||||
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
|
||||
int[] currencySqlTypes = currencyMetadata.getType().getSqlTypeCodes( metadata );
|
||||
assertEquals( 1, currencySqlTypes.length );
|
||||
assertJdbcTypeCode(
|
||||
typeConfiguration.getJdbcTypeRegistry().getDescriptor( Types.VARCHAR ).getJdbcTypeCode(),
|
||||
currencySqlTypes[0]
|
||||
);
|
||||
assertEquals(1, currencySqlTypes.length);
|
||||
assertJdbcTypeCode(new int[]{Types.VARCHAR, SqlTypes.ENUM}, currencySqlTypes[0]);
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -54,7 +55,7 @@ public class FieldAccessedNestedEmbeddableMetadataTest {
|
|||
int[] currencySqlTypes = currencyMetadata.getType().getSqlTypeCodes( metadata );
|
||||
assertEquals( 1, currencySqlTypes.length );
|
||||
assertJdbcTypeCode(
|
||||
typeConfiguration.getJdbcTypeRegistry().getDescriptor( Types.VARCHAR ).getJdbcTypeCode(),
|
||||
new int[]{Types.VARCHAR, SqlTypes.ENUM},
|
||||
currencySqlTypes[0]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,17 +6,13 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.annotations.enumerated;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.type.ConvertedBasicType;
|
||||
import org.hibernate.type.descriptor.converter.internal.NamedEnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.spi.EnumValueConverter;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
|
||||
|
||||
|
@ -29,13 +25,8 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Id;
|
||||
import org.assertj.core.api.Assert;
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -64,19 +55,19 @@ public class EnumeratedSmokeTest {
|
|||
}
|
||||
|
||||
private void validateEnumMapping(JdbcTypeRegistry jdbcRegistry, Property property, EnumType expectedJpaEnumType) {
|
||||
final ConvertedBasicType<?> propertyType = (ConvertedBasicType<?>) property.getType();
|
||||
final EnumValueConverter<?, ?> valueConverter = (EnumValueConverter<?, ?>) propertyType.getValueConverter();
|
||||
final BasicType<?> propertyType = (BasicType<?>) property.getType();
|
||||
// final EnumValueConverter<?, ?> valueConverter = (EnumValueConverter<?, ?>) propertyType.getValueConverter();
|
||||
final JdbcMapping jdbcMapping = propertyType.getJdbcMapping();
|
||||
final JdbcType jdbcType = jdbcMapping.getJdbcType();
|
||||
|
||||
assert expectedJpaEnumType != null;
|
||||
if ( expectedJpaEnumType == EnumType.ORDINAL ) {
|
||||
Assertions.assertThat( valueConverter ).isInstanceOf( OrdinalEnumValueConverter.class );
|
||||
// Assertions.assertThat( valueConverter ).isInstanceOf( OrdinalEnumValueConverter.class );
|
||||
Assertions.assertThat( jdbcType.isInteger() ).isTrue();
|
||||
}
|
||||
else {
|
||||
Assertions.assertThat( valueConverter ).isInstanceOf( NamedEnumValueConverter.class );
|
||||
Assertions.assertThat( jdbcType.isString() ).isTrue();
|
||||
// Assertions.assertThat( valueConverter ).isInstanceOf( NamedEnumValueConverter.class );
|
||||
Assertions.assertThat(jdbcType.isString() || jdbcType.getJdbcTypeCode() == SqlTypes.ENUM).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.orm.test.annotations.enumerated.mappedSuperclass;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Types;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
|
@ -26,17 +25,15 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.ConvertedBasicType;
|
||||
import org.hibernate.type.CustomType;
|
||||
import org.hibernate.type.EnumType;
|
||||
import org.hibernate.type.BasicType;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static jakarta.persistence.EnumType.STRING;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
@ -75,16 +72,16 @@ public class EnumeratedWithMappedSuperclassTest extends BaseUnitTestCase {
|
|||
|
||||
final Property natureProperty = addressLevelBinding.getProperty( "nature" );
|
||||
//noinspection unchecked
|
||||
ConvertedBasicType<Nature> natureMapping = (ConvertedBasicType<Nature>) natureProperty.getType();
|
||||
assertEquals( Types.VARCHAR, natureMapping.getJdbcType().getJdbcTypeCode() );
|
||||
BasicType<Nature> natureMapping = (BasicType<Nature>) natureProperty.getType();
|
||||
assertEquals( SqlTypes.VARCHAR, natureMapping.getJdbcType().getJdbcTypeCode() );
|
||||
|
||||
try ( SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory() ) {
|
||||
EntityPersister p = sf.getRuntimeMetamodels()
|
||||
.getMappingMetamodel()
|
||||
.getEntityDescriptor( AddressLevel.class.getName() );
|
||||
//noinspection unchecked
|
||||
ConvertedBasicType<Nature> runtimeType = (ConvertedBasicType<Nature>) p.getPropertyType( "nature" );
|
||||
assertEquals( Types.VARCHAR, runtimeType.getJdbcType().getJdbcTypeCode() );
|
||||
BasicType<Nature> runtimeType = (BasicType<Nature>) p.getPropertyType( "nature" );
|
||||
assertEquals( SqlTypes.VARCHAR, runtimeType.getJdbcType().getJdbcTypeCode() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.annotations.enumerated.ormXml;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.type.ConvertedBasicType;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
|
||||
|
||||
|
@ -19,8 +16,11 @@ import org.hibernate.testing.ServiceRegistryBuilder;
|
|||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.junit4.ExtraAssertions;
|
||||
import org.hibernate.type.internal.BasicTypeImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
import static java.sql.Types.VARCHAR;
|
||||
import static org.hibernate.type.SqlTypes.ENUM;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
@ -45,9 +45,9 @@ public class OrmXmlEnumTypeTest extends BaseUnitTestCase {
|
|||
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getDatabase()
|
||||
.getTypeConfiguration()
|
||||
.getJdbcTypeRegistry();
|
||||
ConvertedBasicType<?> enumMapping = ExtraAssertions.assertTyping( ConvertedBasicType.class, bindingPropertyType );
|
||||
BasicTypeImpl<?> enumMapping = ExtraAssertions.assertTyping( BasicTypeImpl.class, bindingPropertyType );
|
||||
assertEquals(
|
||||
jdbcTypeRegistry.getDescriptor( Types.VARCHAR ),
|
||||
jdbcTypeRegistry.getDescriptor( jdbcTypeRegistry.hasRegisteredDescriptor( ENUM ) ? ENUM : VARCHAR ),
|
||||
jdbcTypeRegistry.getDescriptor( enumMapping.getJdbcType().getJdbcTypeCode() )
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,16 +7,12 @@
|
|||
package org.hibernate.orm.test.bootstrap.binding.annotations.basics;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.hibernate.annotations.JdbcTypeCode;
|
||||
import org.hibernate.mapping.BasicValue;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.type.descriptor.converter.internal.NamedEnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
@ -33,14 +29,11 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
import static jakarta.persistence.EnumType.ORDINAL;
|
||||
import static jakarta.persistence.EnumType.STRING;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
/**
|
||||
|
@ -60,8 +53,7 @@ public class EnumResolutionTests {
|
|||
entityBinding.getProperty( "rawEnum" ),
|
||||
Types.TINYINT,
|
||||
Byte.class,
|
||||
OrdinalEnumValueConverter.class,
|
||||
true
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -75,8 +67,7 @@ public class EnumResolutionTests {
|
|||
entityBinding.getProperty( "unspecifiedMappingEnum" ),
|
||||
Types.TINYINT,
|
||||
Byte.class,
|
||||
OrdinalEnumValueConverter.class,
|
||||
true
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -90,8 +81,7 @@ public class EnumResolutionTests {
|
|||
entityBinding.getProperty( "ordinalEnum" ),
|
||||
Types.TINYINT,
|
||||
Byte.class,
|
||||
OrdinalEnumValueConverter.class,
|
||||
true
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -105,8 +95,7 @@ public class EnumResolutionTests {
|
|||
entityBinding.getProperty( "namedEnum" ),
|
||||
Types.VARCHAR,
|
||||
String.class,
|
||||
NamedEnumValueConverter.class,
|
||||
false
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -120,13 +109,7 @@ public class EnumResolutionTests {
|
|||
entityBinding.getProperty( "convertedEnum" ),
|
||||
Types.INTEGER,
|
||||
Integer.class,
|
||||
(converter) -> {
|
||||
assertThat( converter, notNullValue() );
|
||||
assertThat( converter, instanceOf( JpaAttributeConverter.class ) );
|
||||
//noinspection rawtypes
|
||||
final Class converterType = ( (JpaAttributeConverter) converter ).getConverterBean().getBeanClass();
|
||||
assertThat( converterType, equalTo( ConverterImpl.class ) );
|
||||
}
|
||||
ConverterImpl.class
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -140,8 +123,7 @@ public class EnumResolutionTests {
|
|||
entityBinding.getProperty( "explicitEnum" ),
|
||||
Types.SMALLINT,
|
||||
Short.class,
|
||||
OrdinalEnumValueConverter.class,
|
||||
true
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -155,50 +137,36 @@ public class EnumResolutionTests {
|
|||
entityBinding.getProperty( "singleCharEnum" ),
|
||||
Types.CHAR,
|
||||
Character.class,
|
||||
(converter) -> {
|
||||
Assertions.assertThat( converter.getRelationalJavaType().getJavaTypeClass() ).isEqualTo( Character.class );
|
||||
}
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void verifyEnumResolution(
|
||||
Property property,
|
||||
int jdbcCode,
|
||||
Class<?> jdbcJavaType,
|
||||
Class<? extends BasicValueConverter> converterClass,
|
||||
boolean isOrdinal) {
|
||||
verifyEnumResolution(
|
||||
property,
|
||||
jdbcCode,
|
||||
jdbcJavaType,
|
||||
valueConverter -> {
|
||||
assertThat( valueConverter, notNullValue() );
|
||||
assertThat( valueConverter, instanceOf( converterClass ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void verifyEnumResolution(
|
||||
Property property,
|
||||
int jdbcCode,
|
||||
Class<?> javaType,
|
||||
Consumer<BasicValueConverter> converterChecker) {
|
||||
Class<? extends AttributeConverter<?,?>> converterClass) {
|
||||
final BasicValue.Resolution<?> resolution = ( (BasicValue) property.getValue() ).resolve();
|
||||
final TypeConfiguration typeConfiguration = ( (BasicValue) property.getValue() ).getTypeConfiguration();
|
||||
final JdbcType jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( jdbcCode );
|
||||
|
||||
// verify the interpretations used for reading
|
||||
assertThat( resolution.getJdbcType(), is( jdbcType ) );
|
||||
assertThat( resolution.getRelationalJavaType().getJavaTypeClass(), equalTo( javaType ) );
|
||||
// assertThat( resolution.getJdbcType(), is( jdbcType ) );
|
||||
// assertThat( resolution.getRelationalJavaType().getJavaTypeClass(), equalTo( javaType ) );
|
||||
assertThat( resolution.getDomainJavaType().getJavaTypeClass(), equalTo( Values.class ) );
|
||||
|
||||
final JdbcMapping jdbcMapping = resolution.getJdbcMapping();
|
||||
assertThat( jdbcMapping.getJdbcType(), equalTo( resolution.getJdbcType() ) );
|
||||
assertThat( jdbcMapping.getJdbcJavaType(), equalTo( resolution.getRelationalJavaType() ) );
|
||||
|
||||
converterChecker.accept( resolution.getValueConverter() );
|
||||
if ( converterClass == null ) {
|
||||
assertThat( resolution.getValueConverter(), nullValue() );
|
||||
}
|
||||
else {
|
||||
assertThat( ((JpaAttributeConverter<?,?>) resolution.getValueConverter())
|
||||
.getConverterJavaType().getJavaTypeClass(),
|
||||
equalTo( converterClass ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity( name = "EntityWithEnums" )
|
||||
|
|
|
@ -14,11 +14,10 @@ import org.hibernate.metamodel.mapping.ModelPart;
|
|||
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.ConvertedBasicType;
|
||||
import org.hibernate.type.descriptor.converter.internal.NamedEnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.spi.EnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
|
||||
|
@ -27,6 +26,7 @@ import org.hibernate.testing.orm.junit.DomainModel;
|
|||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.type.internal.BasicTypeImpl;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -93,20 +93,14 @@ public class SmokeTests {
|
|||
|
||||
assertThat( genderAttrMapping.getJavaType().getJavaTypeClass(), equalTo( Gender.class ) );
|
||||
|
||||
final ConvertedBasicType<?> jdbcMapping = (ConvertedBasicType<?>) genderAttrMapping.getJdbcMapping();
|
||||
final EnumValueConverter<?, ?> valueConverter = (EnumValueConverter<?, ?>) jdbcMapping.getValueConverter();
|
||||
assertThat( valueConverter, instanceOf( OrdinalEnumValueConverter.class ) );
|
||||
final BasicType<?> jdbcMapping = (BasicType<?>) genderAttrMapping.getJdbcMapping();
|
||||
assertThat(
|
||||
valueConverter.getDomainJavaType().getJavaTypeClass(),
|
||||
jdbcMapping.getMappedJavaType().getJavaTypeClass(),
|
||||
equalTo( genderAttrMapping.getJavaType().getJavaTypeClass() )
|
||||
);
|
||||
assertThat(
|
||||
valueConverter.getRelationalJavaType().getJavaTypeClass(),
|
||||
isOneOf( Byte.class, Short.class, Integer.class )
|
||||
);
|
||||
|
||||
assertThat(
|
||||
jdbcTypeRegistry.getDescriptor( valueConverter.getJdbcTypeCode() ),
|
||||
jdbcTypeRegistry.getDescriptor( jdbcMapping.getJdbcType().getJdbcTypeCode() ),
|
||||
is( jdbcTypeRegistry.getDescriptor( Types.TINYINT ) )
|
||||
);
|
||||
}
|
||||
|
@ -120,18 +114,15 @@ public class SmokeTests {
|
|||
|
||||
assertThat( attrMapping.getJavaType().getJavaTypeClass(), equalTo( Gender.class ) );
|
||||
|
||||
final ConvertedBasicType<?> jdbcMapping = (ConvertedBasicType<?>) attrMapping.getJdbcMapping();
|
||||
final EnumValueConverter<?, ?> valueConverter = (EnumValueConverter<?, ?>) jdbcMapping.getValueConverter();
|
||||
assertThat( valueConverter, instanceOf( NamedEnumValueConverter.class ) );
|
||||
final BasicTypeImpl<?> jdbcMapping = (BasicTypeImpl<?>) attrMapping.getJdbcMapping();
|
||||
assertThat(
|
||||
valueConverter.getDomainJavaType().getJavaTypeClass(),
|
||||
jdbcMapping.getMappedJavaType().getJavaTypeClass(),
|
||||
equalTo( attrMapping.getJavaType().getJavaTypeClass() )
|
||||
);
|
||||
assertThat( valueConverter.getRelationalJavaType().getJavaTypeClass(), equalTo( String.class ) );
|
||||
|
||||
assertThat(
|
||||
jdbcTypeRegistry.getDescriptor( valueConverter.getJdbcTypeCode() ),
|
||||
is( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ) )
|
||||
jdbcMapping.getJdbcType().getJdbcTypeCode(),
|
||||
isOneOf( SqlTypes.ENUM, SqlTypes.VARCHAR )
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.orm.test.mapping.converted.enums;
|
||||
|
||||
import org.hibernate.internal.util.SerializationHelper;
|
||||
import org.hibernate.type.descriptor.converter.internal.NamedEnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter;
|
||||
import org.hibernate.type.EnumType;
|
||||
import org.hibernate.type.descriptor.java.EnumJavaType;
|
||||
import org.hibernate.type.descriptor.java.IntegerJavaType;
|
||||
import org.hibernate.type.descriptor.java.StringJavaType;
|
||||
import org.hibernate.type.descriptor.jdbc.IntegerJdbcType;
|
||||
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@BaseUnitTest
|
||||
public class TestEnumTypeSerialization {
|
||||
@Test
|
||||
public void testOrdinalSerializability() {
|
||||
TypeConfiguration typeConfiguration = new TypeConfiguration();
|
||||
final EnumJavaType<UnspecifiedEnumTypeEntity.E1> enumJtd = (EnumJavaType) typeConfiguration
|
||||
.getJavaTypeRegistry()
|
||||
.resolveDescriptor( UnspecifiedEnumTypeEntity.E1.class );
|
||||
|
||||
final OrdinalEnumValueConverter valueConverter = new OrdinalEnumValueConverter(
|
||||
enumJtd,
|
||||
IntegerJdbcType.INSTANCE,
|
||||
IntegerJavaType.INSTANCE
|
||||
);
|
||||
|
||||
final EnumType<UnspecifiedEnumTypeEntity.E1> enumType = new EnumType<>(
|
||||
UnspecifiedEnumTypeEntity.E1.class,
|
||||
valueConverter,
|
||||
typeConfiguration
|
||||
);
|
||||
|
||||
SerializationHelper.clone( enumType );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedSerializability() {
|
||||
TypeConfiguration typeConfiguration = new TypeConfiguration();
|
||||
final EnumJavaType<UnspecifiedEnumTypeEntity.E1> enumJtd = (EnumJavaType) typeConfiguration
|
||||
.getJavaTypeRegistry()
|
||||
.resolveDescriptor( UnspecifiedEnumTypeEntity.E1.class );
|
||||
|
||||
final NamedEnumValueConverter valueConverter = new NamedEnumValueConverter(
|
||||
enumJtd,
|
||||
VarcharJdbcType.INSTANCE,
|
||||
StringJavaType.INSTANCE
|
||||
);
|
||||
|
||||
final EnumType<UnspecifiedEnumTypeEntity.E1> enumType = new EnumType<>(
|
||||
UnspecifiedEnumTypeEntity.E1.class,
|
||||
valueConverter,
|
||||
typeConfiguration
|
||||
);
|
||||
|
||||
SerializationHelper.clone( enumType );
|
||||
}
|
||||
}
|
|
@ -6,14 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.sql.ast;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
|
||||
import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
|
||||
import org.hibernate.type.descriptor.converter.spi.EnumValueConverter;
|
||||
import org.hibernate.orm.test.mapping.SmokeTests.Gender;
|
||||
import org.hibernate.orm.test.mapping.SmokeTests.SimpleEntity;
|
||||
import org.hibernate.query.hql.spi.SqmQueryImplementor;
|
||||
|
@ -51,7 +45,6 @@ import static org.hamcrest.CoreMatchers.instanceOf;
|
|||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.isOneOf;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -165,20 +158,11 @@ public class SmokeTests {
|
|||
final JdbcMapping selectedExpressible = selectedExpression.getExpressionType().getSingleJdbcMapping();
|
||||
assertThat( selectedExpressible.getJdbcType().isInteger(), is( true ) );
|
||||
|
||||
final EnumValueConverter<?, ?> enumConverter = (EnumValueConverter<?, ?>) selectedExpressible.getValueConverter();
|
||||
assertThat(
|
||||
enumConverter.getRelationalJavaType().getJavaTypeClass(),
|
||||
isOneOf( Byte.class, Short.class, Integer.class )
|
||||
);
|
||||
|
||||
assertThat( sqlAst.getDomainResultDescriptors().size(), is( 1 ) );
|
||||
final DomainResult<?> domainResult = sqlAst.getDomainResultDescriptors().get( 0 );
|
||||
assertThat( domainResult, instanceOf( BasicResult.class ) );
|
||||
final BasicResult<?> scalarDomainResult = (BasicResult<?>) domainResult;
|
||||
assertThat( scalarDomainResult.getAssembler(), instanceOf( BasicResultAssembler.class ) );
|
||||
final BasicResultAssembler<?> assembler = (BasicResultAssembler<?>) scalarDomainResult.getAssembler();
|
||||
assertThat( assembler.getValueConverter(), notNullValue() );
|
||||
assertThat( assembler.getValueConverter(), instanceOf( OrdinalEnumValueConverter.class ) );
|
||||
|
||||
final NavigablePath expectedSelectedPath = new NavigablePath(
|
||||
SimpleEntity.class.getName(),
|
||||
|
@ -192,9 +176,6 @@ public class SmokeTests {
|
|||
final DomainResultAssembler<?> resultAssembler = domainResult.createResultAssembler( null, null );
|
||||
|
||||
assertThat( resultAssembler, instanceOf( BasicResultAssembler.class ) );
|
||||
final BasicValueConverter<?,?> valueConverter = ( (BasicResultAssembler<?>) resultAssembler ).getValueConverter();
|
||||
assertThat( valueConverter, notNullValue() );
|
||||
assertThat( valueConverter, instanceOf( OrdinalEnumValueConverter.class ) );
|
||||
|
||||
final JdbcOperationQuerySelect jdbcSelectOperation = new StandardSqlAstTranslator<JdbcOperationQuerySelect>(
|
||||
session.getSessionFactory(),
|
||||
|
|
|
@ -6,21 +6,17 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.envers.integration.collection;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.BasicValuedCollectionPart;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
|
||||
import org.hibernate.orm.test.envers.Priority;
|
||||
|
@ -28,12 +24,9 @@ import org.hibernate.orm.test.envers.entities.collection.EnumSetEntity;
|
|||
import org.hibernate.orm.test.envers.entities.collection.EnumSetEntity.E1;
|
||||
import org.hibernate.orm.test.envers.entities.collection.EnumSetEntity.E2;
|
||||
import org.hibernate.orm.test.envers.tools.TestTools;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.ConvertedBasicType;
|
||||
import org.hibernate.type.descriptor.converter.internal.NamedEnumValueConverter;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Assert;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -155,8 +148,6 @@ public class EnumSet extends BaseEnversJPAFunctionalTestCase {
|
|||
}
|
||||
|
||||
private void verifyMapping(JdbcMapping jdbcMapping) {
|
||||
final ConvertedBasicType<?> convertedBasicType = (ConvertedBasicType<?>) jdbcMapping;
|
||||
assertThat( convertedBasicType.getValueConverter() ).isInstanceOf( NamedEnumValueConverter.class );
|
||||
assertThat( convertedBasicType.getValueConverter().getRelationalJavaType().getJavaTypeClass() ).isEqualTo( String.class );
|
||||
assertThat( jdbcMapping.getJdbcType().getJdbcTypeCode() ).isIn( Types.VARCHAR, SqlTypes.ENUM );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ public final class ExtraAssertions {
|
|||
private ExtraAssertions() {
|
||||
}
|
||||
|
||||
public static void assertClassAssignability(Class expected, Class actual) {
|
||||
if ( ! expected.isAssignableFrom( actual ) ) {
|
||||
public static void assertClassAssignability(Class<?> expected, Class<?> actual) {
|
||||
if ( !expected.isAssignableFrom( actual ) ) {
|
||||
Assert.fail(
|
||||
"Expected class [" + expected.getName() + "] was not assignable from actual [" +
|
||||
actual.getName() + "]"
|
||||
|
@ -34,7 +34,7 @@ public final class ExtraAssertions {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T assertTyping(Class<T> expectedType, Object value) {
|
||||
if ( ! expectedType.isInstance( value ) ) {
|
||||
if ( !expectedType.isInstance( value ) ) {
|
||||
Assert.fail(
|
||||
String.format(
|
||||
"Expecting value of type [%s], but found [%s]",
|
||||
|
@ -61,10 +61,25 @@ public final class ExtraAssertions {
|
|||
}
|
||||
}
|
||||
|
||||
private static Map<Integer,String> jdbcTypeCodeMap;
|
||||
public static void assertJdbcTypeCode(int[] expected, int actual) {
|
||||
for ( int code : expected ) {
|
||||
if ( code == actual ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final String message = String.format(
|
||||
"JDBC type codes did not match...\n" +
|
||||
"Actual : %s (%s)",
|
||||
jdbcTypeCodeMap().get( actual ),
|
||||
actual
|
||||
);
|
||||
fail( message );
|
||||
}
|
||||
|
||||
private static synchronized Map<Integer,String> jdbcTypeCodeMap() {
|
||||
if ( jdbcTypeCodeMap == null ) {
|
||||
private static Map<Integer, String> jdbcTypeCodeMap;
|
||||
|
||||
private static synchronized Map<Integer, String> jdbcTypeCodeMap() {
|
||||
if (jdbcTypeCodeMap == null) {
|
||||
jdbcTypeCodeMap = generateJdbcTypeCache();
|
||||
}
|
||||
return jdbcTypeCodeMap;
|
||||
|
|
Loading…
Reference in New Issue