-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix package name handling in JpaJandexScavenger
- Loading branch information
Showing
4 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
...eployment/src/test/java/io/quarkus/hibernate/orm/xml/orm/OrmXmlAnnotationPackageTest.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,63 @@ | ||
package io.quarkus.hibernate.orm.xml.orm; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityManagerFactory; | ||
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; | ||
|
||
/** | ||
* Test that the <package> element is correctly interpreted in an orm.xml mapping file. | ||
*/ | ||
public class OrmXmlAnnotationPackageTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(SmokeTestUtils.class) | ||
.addClass(SchemaUtil.class) | ||
.addClass(NonAnnotatedEntity.class) | ||
.addClass(OtherNonAnnotatedEntity.class) | ||
.addAsResource("META-INF/orm-package.xml", "my-orm.xml")) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.hibernate-orm.mapping-files", "my-orm.xml"); | ||
|
||
@Inject | ||
EntityManagerFactory entityManagerFactory; | ||
|
||
@Inject | ||
EntityManager entityManager; | ||
|
||
@Test | ||
@Transactional | ||
public void ormXmlTakenIntoAccount() { | ||
assertThat(SchemaUtil.getColumnNames(entityManagerFactory, NonAnnotatedEntity.class)) | ||
.contains("thename") | ||
.doesNotContain("name"); | ||
assertThat(SchemaUtil.getColumnNames(entityManagerFactory, OtherNonAnnotatedEntity.class)) | ||
.contains("thename") | ||
.doesNotContain("name"); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void smokeTest() { | ||
SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(entityManager, | ||
NonAnnotatedEntity.class, NonAnnotatedEntity::new, | ||
NonAnnotatedEntity::getId, NonAnnotatedEntity::setName, NonAnnotatedEntity::getName); | ||
SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(entityManager, | ||
OtherNonAnnotatedEntity.class, OtherNonAnnotatedEntity::new, | ||
OtherNonAnnotatedEntity::getId, OtherNonAnnotatedEntity::setName, OtherNonAnnotatedEntity::getName); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...rm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/orm/OtherNonAnnotatedEntity.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,31 @@ | ||
package io.quarkus.hibernate.orm.xml.orm; | ||
|
||
public class OtherNonAnnotatedEntity { | ||
|
||
private long id; | ||
|
||
private String name; | ||
|
||
public OtherNonAnnotatedEntity() { | ||
} | ||
|
||
public OtherNonAnnotatedEntity(String name) { | ||
this.name = name; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
extensions/hibernate-orm/deployment/src/test/resources/META-INF/orm-package.xml
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,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<entity-mappings | ||
xmlns="http://java.sun.com/xml/ns/persistence/orm" | ||
version="2.0"> | ||
|
||
<package>io.quarkus.hibernate.orm.xml.orm</package> | ||
|
||
<entity class="NonAnnotatedEntity"> | ||
<attributes> | ||
<id name="id"> | ||
<generated-value strategy="IDENTITY" /> | ||
</id> | ||
<basic name="name"> | ||
<column name="thename" /> | ||
</basic> | ||
</attributes> | ||
</entity> | ||
<!-- Overriding the package on purpose; this is to check that we don't prefix the package name unnecessarily to a FQCN --> | ||
<entity class="io.quarkus.hibernate.orm.xml.orm.OtherNonAnnotatedEntity"> | ||
<attributes> | ||
<id name="id"> | ||
<generated-value strategy="IDENTITY" /> | ||
</id> | ||
<basic name="name"> | ||
<column name="thename" /> | ||
</basic> | ||
</attributes> | ||
</entity> | ||
</entity-mappings> |