forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[quarkusio#28576] Tests for property hibernate-orm.packages with Hibe…
…rnate Reactive
- Loading branch information
Showing
6 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
.../hibernate/reactive/singlepersistenceunit/SinglePersistenceUnitPackageAnnotationTest.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,74 @@ | ||
package io.quarkus.hibernate.reactive.singlepersistenceunit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.logging.Formatter; | ||
import java.util.logging.Level; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hibernate.reactive.mutiny.Mutiny; | ||
import org.jboss.logmanager.formatters.PatternFormatter; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.excludedpackage.ExcludedEntity; | ||
import io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.packageincludedthroughannotation.EntityIncludedThroughPackageAnnotation; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.vertx.RunOnVertxContext; | ||
import io.quarkus.test.vertx.UniAsserter; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class SinglePersistenceUnitPackageAnnotationTest { | ||
|
||
private static final Formatter LOG_FORMATTER = new PatternFormatter("%s"); | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addPackage(EntityIncludedThroughPackageAnnotation.class.getPackage().getName()) | ||
.addPackage(ExcludedEntity.class.getPackage().getName())) | ||
.withConfigurationResource("application.properties") | ||
// Expect a warning on startup | ||
.setLogRecordPredicate( | ||
record -> record.getMessage().contains("Could not find a suitable persistence unit for model classes")) | ||
.assertLogRecords(records -> assertThat(records) | ||
.as("Warnings on startup") | ||
.hasSize(1) | ||
.element(0).satisfies(record -> { | ||
assertThat(record.getLevel()).isEqualTo(Level.WARNING); | ||
assertThat(LOG_FORMATTER.formatMessage(record)) | ||
.contains( | ||
io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.excludedpackage.ExcludedEntity.class | ||
.getName()); | ||
})); | ||
|
||
@Inject | ||
Mutiny.SessionFactory sessionFactory; | ||
|
||
@Test | ||
@RunOnVertxContext | ||
public void testIncluded(UniAsserter asserter) { | ||
EntityIncludedThroughPackageAnnotation entity = new EntityIncludedThroughPackageAnnotation("default"); | ||
asserter.assertThat( | ||
() -> persist(entity).chain(() -> find(EntityIncludedThroughPackageAnnotation.class, entity.id)), | ||
retrievedEntity -> assertThat(retrievedEntity.name).isEqualTo(entity.name)); | ||
} | ||
|
||
@Test | ||
@RunOnVertxContext | ||
public void testExcluded(UniAsserter asserter) { | ||
ExcludedEntity entity = new ExcludedEntity("gsmet"); | ||
asserter.assertFailedWith(() -> persist(entity), t -> { | ||
assertThat(t).hasMessageContaining("Unknown entity"); | ||
}); | ||
} | ||
|
||
private Uni<Void> persist(Object entity) { | ||
return sessionFactory.withTransaction(s -> s.persist(entity)); | ||
} | ||
|
||
private <T> Uni<T> find(Class<T> entityClass, Object id) { | ||
return sessionFactory.withSession(s -> s.find(entityClass, id)); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...bernate/reactive/singlepersistenceunit/SinglePersistenceUnitPackageConfigurationTest.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,74 @@ | ||
package io.quarkus.hibernate.reactive.singlepersistenceunit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.logging.Formatter; | ||
import java.util.logging.Level; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hibernate.reactive.mutiny.Mutiny; | ||
import org.jboss.logmanager.formatters.PatternFormatter; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.excludedpackage.ExcludedEntity; | ||
import io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.packageincludedthroughconfig.EntityIncludedThroughPackageConfig; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.vertx.RunOnVertxContext; | ||
import io.quarkus.test.vertx.UniAsserter; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class SinglePersistenceUnitPackageConfigurationTest { | ||
|
||
private static final Formatter LOG_FORMATTER = new PatternFormatter("%s"); | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addPackage(EntityIncludedThroughPackageConfig.class.getPackage().getName()) | ||
.addPackage(ExcludedEntity.class.getPackage().getName())) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.hibernate-orm.packages", | ||
EntityIncludedThroughPackageConfig.class.getPackage().getName()) | ||
// Expect a warning on startup | ||
.setLogRecordPredicate( | ||
record -> record.getMessage().contains("Could not find a suitable persistence unit for model classes")) | ||
.assertLogRecords(records -> assertThat(records) | ||
.as("Warnings on startup") | ||
.hasSize(1) | ||
.element(0).satisfies(record -> { | ||
assertThat(record.getLevel()).isEqualTo(Level.WARNING); | ||
assertThat(LOG_FORMATTER.formatMessage(record)) | ||
.contains(ExcludedEntity.class.getName()); | ||
})); | ||
|
||
@Inject | ||
Mutiny.SessionFactory sessionFactory; | ||
|
||
@Test | ||
@RunOnVertxContext | ||
public void testIncluded(UniAsserter asserter) { | ||
EntityIncludedThroughPackageConfig entity = new EntityIncludedThroughPackageConfig("default"); | ||
asserter.assertThat( | ||
() -> persist(entity).chain(() -> find(EntityIncludedThroughPackageConfig.class, entity.id)), | ||
retrievedEntity -> assertThat(retrievedEntity.name).isEqualTo(entity.name)); | ||
} | ||
|
||
@Test | ||
@RunOnVertxContext | ||
public void testExcluded(UniAsserter asserter) { | ||
ExcludedEntity entity = new ExcludedEntity("gsmet"); | ||
asserter.assertFailedWith(() -> persist(entity), t -> { | ||
assertThat(t).hasMessageContaining("Unknown entity"); | ||
}); | ||
} | ||
|
||
private Uni<Void> persist(Object entity) { | ||
return sessionFactory.withTransaction(s -> s.persist(entity)); | ||
} | ||
|
||
private <T> Uni<T> find(Class<T> entityClass, Object id) { | ||
return sessionFactory.withSession(s -> s.find(entityClass, id)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...rnate/reactive/singlepersistenceunit/entityassignment/excludedpackage/ExcludedEntity.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,24 @@ | ||
package io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.excludedpackage; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class ExcludedEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "excludedSeq") | ||
public long id; | ||
|
||
public String name; | ||
|
||
public ExcludedEntity() { | ||
} | ||
|
||
public ExcludedEntity(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...tyassignment/packageincludedthroughannotation/EntityIncludedThroughPackageAnnotation.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,24 @@ | ||
package io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.packageincludedthroughannotation; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class EntityIncludedThroughPackageAnnotation { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "includedSeq") | ||
public long id; | ||
|
||
public String name; | ||
|
||
public EntityIncludedThroughPackageAnnotation() { | ||
} | ||
|
||
public EntityIncludedThroughPackageAnnotation(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...singlepersistenceunit/entityassignment/packageincludedthroughannotation/package-info.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,4 @@ | ||
@PersistenceUnit(PersistenceUnit.DEFAULT) | ||
package io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.packageincludedthroughannotation; | ||
|
||
import io.quarkus.hibernate.orm.PersistenceUnit; |
24 changes: 24 additions & 0 deletions
24
...nit/entityassignment/packageincludedthroughconfig/EntityIncludedThroughPackageConfig.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,24 @@ | ||
package io.quarkus.hibernate.reactive.singlepersistenceunit.entityassignment.packageincludedthroughconfig; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class EntityIncludedThroughPackageConfig { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "includedSeq") | ||
public long id; | ||
|
||
public String name; | ||
|
||
public EntityIncludedThroughPackageConfig() { | ||
} | ||
|
||
public EntityIncludedThroughPackageConfig(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |