HHH-17653 Add test for issue

This commit is contained in:
Andrea Boriero 2024-01-19 11:57:59 +01:00 committed by Christian Beikov
parent 240514986d
commit 4ba772b72d
2 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,70 @@
package org.hibernate.orm.test.idgen;
import org.hibernate.AnnotationException;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@BaseUnitTest
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@Jira("HHH-17653")
public class GeneratorNotAppliedToIdEmbeddableFieldsShouldThrowAnExceptionTest {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;
@AfterEach
public void tearDown() {
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
@Test
public void testThatAnAnnotationExceptionIsThrown() {
Exception exception = assertThrows( AnnotationException.class, () -> {
serviceRegistry = ServiceRegistryUtil.serviceRegistry();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( TestEntity.class )
.buildMetadata();
} );
assertThat( exception.getMessage() ).contains( "Property 'serialValue'" );
}
@Entity(name = "TestEntity")
@Table(name = "TEST_ENITY")
public static class TestEntity {
@Id
private String id;
@Embedded
private TestEmbeddable testEmbeddable;
}
@Embeddable
public static class TestEmbeddable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer serialValue;
}
}

View File

@ -0,0 +1,60 @@
package org.hibernate.orm.test.idgen;
import org.hibernate.AnnotationException;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@BaseUnitTest
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@Jira("HHH-17653")
public class GeneratorNotAppliedToIdFieldsShouldThrowAnExceptionTest {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;
@AfterEach
public void tearDown() {
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
@Test
public void testThatAnAnnotationExceptionIsThrown() {
Exception exception = assertThrows( AnnotationException.class, () -> {
serviceRegistry = ServiceRegistryUtil.serviceRegistry();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( TestEntity.class )
.buildMetadata();
} );
assertThat( exception.getMessage() ).contains( "Property '" + TestEntity.class.getName() + ".name'" );
}
@Entity(name = "TestEntity")
@Table(name = "TEST_ENITY")
public static class TestEntity {
@Id
private String id;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String name;
}
}