forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproducer for quarkusio#19867: test that @AttributeOverride is taken…
… into account
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
...c/test/java/io/quarkus/hibernate/orm/mapping/attributeoverride/AttributeOverrideTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package io.quarkus.hibernate.orm.mapping.attributeoverride; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.AttributeOverride; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.MappedSuperclass; | ||
import javax.transaction.Transactional; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.SchemaUtil; | ||
import io.quarkus.hibernate.orm.SmokeTestUtils; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Checks that {@code @Converter(autoApply = true)} works correctly. | ||
* <p> | ||
* This test used to fail on startup when the annotation was not detected correctly. | ||
*/ | ||
public class AttributeOverrideTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(MappedSuperclassType.class) | ||
.addClass(DerivedEntityType.class) | ||
.addClass(SchemaUtil.class) | ||
.addClass(SmokeTestUtils.class)) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.hibernate-orm.log.sql", "true"); | ||
|
||
@Inject | ||
EntityManagerFactory entityManagerFactory; | ||
|
||
@Inject | ||
EntityManager entityManager; | ||
|
||
@Test | ||
@Transactional | ||
public void attributeOverrideTakenIntoAccount() { | ||
assertThat(SchemaUtil.getColumnNames(entityManagerFactory, DerivedEntityType.class)) | ||
.contains("custom_name") | ||
.doesNotContain("name"); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void smokeTest() { | ||
SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(entityManager, | ||
DerivedEntityType.class, DerivedEntityType::new, | ||
DerivedEntityType::getId, DerivedEntityType::setName, DerivedEntityType::getName); | ||
} | ||
|
||
@MappedSuperclass | ||
public static class MappedSuperclassType { | ||
|
||
private String name; | ||
|
||
public MappedSuperclassType() { | ||
} | ||
|
||
public MappedSuperclassType(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
|
||
@Entity(name = "derivedentity") | ||
@AttributeOverride(name = "name", column = @Column(name = "custom_name")) | ||
public static class DerivedEntityType extends MappedSuperclassType { | ||
|
||
@Id | ||
@GeneratedValue | ||
private long id; | ||
|
||
public DerivedEntityType() { | ||
} | ||
|
||
public DerivedEntityType(String name) { | ||
super(name); | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
} | ||
} |