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.
Test that extensions work correctly without runtime config
No NPE in particular; see for example quarkusio#23422
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ent/src/test/java/io/quarkus/hibernate/orm/config/namedpu/NoRuntimeConfigNamedPUTest.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,44 @@ | ||
package io.quarkus.hibernate.orm.config.namedpu; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.metamodel.Bindable; | ||
|
||
import io.quarkus.hibernate.orm.PersistenceUnit.PersistenceUnitLiteral; | ||
import io.quarkus.hibernate.orm.runtime.HibernateOrmRuntimeConfig; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Test that Hibernate ORM is able to start even when not providing any runtime property | ||
*/ | ||
public class NoRuntimeConfigNamedPUTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addPackage(MyEntity.class.getPackage().getName())) | ||
.overrideConfigKey("quarkus.datasource.\"ds-1\".db-kind", "h2") | ||
.overrideConfigKey("quarkus.datasource.\"ds-1\".jdbc.url", "jdbc:h2:mem:test") | ||
// For Hibernate ORM, provide only build-time config; rely on defaults for everything else. | ||
.overrideConfigKey("quarkus.hibernate-orm.\"pu-1\".datasource", "ds-1") | ||
// Disable dev services, since they could interfere with runtime config (in particular the schema generation settings). | ||
.overrideConfigKey("quarkus.devservices.enabled", "false"); | ||
|
||
@Test | ||
public void test() { | ||
// Check that runtime config for our PU is indeed missing. | ||
HibernateOrmRuntimeConfig config = Arc.container().instance(HibernateOrmRuntimeConfig.class).get(); | ||
assertThat(config.persistenceUnits).isNullOrEmpty(); | ||
// Test that Hibernate was started correctly regardless. | ||
EntityManagerFactory entityManagerFactory = Arc.container() | ||
.instance(EntityManagerFactory.class, new PersistenceUnitLiteral("pu-1")).get(); | ||
assertThat(entityManagerFactory).isNotNull(); | ||
assertThat(entityManagerFactory.getMetamodel().getEntities()) | ||
.extracting(Bindable::getBindableJavaType) | ||
.containsExactlyInAnyOrder((Class) MyEntity.class); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...e/search/orm/elasticsearch/test/configuration/NoRuntimeConfigNamedPUNamedBackendTest.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,54 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.configuration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.metamodel.Bindable; | ||
|
||
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchRuntimeConfig; | ||
import org.hibernate.search.mapper.orm.entity.SearchIndexedEntity; | ||
import org.hibernate.search.mapper.orm.mapping.SearchMapping; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.hibernate.orm.PersistenceUnit.PersistenceUnitLiteral; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Test that Hibernate Search is able to start even when not providing any runtime property. | ||
*/ | ||
@Disabled("The (build-time) 'version' property is not detected for some reason; I suspect a bug in Quarkus Config when there are two levels of maps in the config.") | ||
public class NoRuntimeConfigNamedPUNamedBackendTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClass(IndexedEntityInNamedBackend.class)) | ||
.overrideConfigKey("quarkus.datasource.\"ds-1\".db-kind", "h2") | ||
.overrideConfigKey("quarkus.datasource.\"ds-1\".jdbc.url", "jdbc:h2:mem:test") | ||
.overrideConfigKey("quarkus.hibernate-orm.\"pu-1\".datasource", "ds-1") | ||
.overrideConfigKey("quarkus.hibernate-orm.\"pu-1\".packages", | ||
IndexedEntityInNamedBackend.class.getPackage().getName()) | ||
// For Hibernate Search, provide only build-time config; rely on defaults for everything else. | ||
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu-1\".elasticsearch.\"mybackend\".version", "7") | ||
// Disable dev services, since they could interfere with runtime config (in particular the schema management settings). | ||
.overrideConfigKey("quarkus.devservices.enabled", "false") | ||
// Make runtime config accessible through CDI | ||
.overrideConfigKey("quarkus.arc.unremovable-types", HibernateSearchElasticsearchRuntimeConfig.class.getName()); | ||
|
||
@Test | ||
public void test() { | ||
// Check that runtime config for our PU is indeed missing. | ||
HibernateSearchElasticsearchRuntimeConfig config = Arc.container() | ||
.instance(HibernateSearchElasticsearchRuntimeConfig.class).get(); | ||
assertThat(config.persistenceUnits).isNullOrEmpty(); | ||
// Test that Hibernate was started correctly regardless. | ||
SearchMapping mapping = Arc.container() | ||
.instance(SearchMapping.class, new PersistenceUnitLiteral("pu-1")).get(); | ||
assertThat(mapping).isNotNull(); | ||
assertThat(mapping.allIndexedEntities()) | ||
.extracting(SearchIndexedEntity::javaClass) | ||
.containsExactlyInAnyOrder((Class) IndexedEntityInNamedBackend.class); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...kus/hibernate/search/orm/elasticsearch/test/configuration/NoRuntimeConfigNamedPUTest.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,49 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.configuration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hibernate.search.mapper.orm.entity.SearchIndexedEntity; | ||
import org.hibernate.search.mapper.orm.mapping.SearchMapping; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.hibernate.orm.PersistenceUnit.PersistenceUnitLiteral; | ||
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchRuntimeConfig; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Test that Hibernate Search is able to start even when not providing any runtime property. | ||
*/ | ||
public class NoRuntimeConfigNamedPUTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClass(IndexedEntity.class)) | ||
.overrideConfigKey("quarkus.datasource.\"ds-1\".db-kind", "h2") | ||
.overrideConfigKey("quarkus.datasource.\"ds-1\".jdbc.url", "jdbc:h2:mem:test") | ||
.overrideConfigKey("quarkus.hibernate-orm.\"pu-1\".datasource", "ds-1") | ||
.overrideConfigKey("quarkus.hibernate-orm.\"pu-1\".packages", | ||
IndexedEntity.class.getPackage().getName()) | ||
// For Hibernate Search, provide only build-time config; rely on defaults for everything else. | ||
.overrideConfigKey("quarkus.hibernate-search-orm.\"pu-1\".elasticsearch.version", "7") | ||
// Disable dev services, since they could interfere with runtime config (in particular the schema management settings). | ||
.overrideConfigKey("quarkus.devservices.enabled", "false") | ||
// Make runtime config accessible through CDI | ||
.overrideConfigKey("quarkus.arc.unremovable-types", HibernateSearchElasticsearchRuntimeConfig.class.getName()); | ||
|
||
@Test | ||
public void test() { | ||
// Check that runtime config for our PU is indeed missing. | ||
HibernateSearchElasticsearchRuntimeConfig config = Arc.container() | ||
.instance(HibernateSearchElasticsearchRuntimeConfig.class).get(); | ||
assertThat(config.persistenceUnits).isNullOrEmpty(); | ||
// Test that Hibernate was started correctly regardless. | ||
SearchMapping mapping = Arc.container() | ||
.instance(SearchMapping.class, new PersistenceUnitLiteral("pu-1")).get(); | ||
assertThat(mapping).isNotNull(); | ||
assertThat(mapping.allIndexedEntities()) | ||
.extracting(SearchIndexedEntity::javaClass) | ||
.containsExactlyInAnyOrder((Class) IndexedEntity.class); | ||
} | ||
} |