From 90a86bdd9d1304cebe60cfaa86f6dd65621cbdbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Thu, 26 Sep 2024 17:12:55 +0200 Subject: [PATCH] Refine datasource tests related to "empty config" and health checks To be completely sure of what we'll change exactly in further changes. This is only a refactoring and doesn't change existing test expectations (though it adds some). "Empty config" actually means "missing JDBC/reactive URL". Testing what happens when named datasources are not defined at build time, in particular, is beside the point. For health checks, it's just that some configurations were not being tested, and the next commits may affect the behavior. --- ...alseDefaultDatasourceHealthCheckTest.java} | 13 ++-- ...veFalseNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...DefaultDatasourceDynamicInjectionTest.java | 53 +++++++++++++ ...ssingDefaultDatasourceHealthCheckTest.java | 28 +++++++ ...gDefaultDatasourceStaticInjectionTest.java | 44 +++++++++++ ...ngNamedDatasourceDynamicInjectionTest.java | 59 ++++++++++++++ ...MissingNamedDatasourceHealthCheckTest.java | 31 ++++++++ ...ingNamedDatasourceStaticInjectionTest.java | 49 ++++++++++++ ...DefaultDatasourceDynamicInjectionTest.java | 38 ++++++++++ ...DefaultDatasourceStaticInjectionTest.java} | 23 +----- ...gNamedDataSourceDynamicInjectionTest.java} | 23 ++++-- ...ingNamedDataSourceStaticInjectionTest.java | 56 ++++++++++++++ ...StartDefaultDatasourceUrlMissingTest.java} | 4 +- ...tNamedDatasourceConfigUrlMissingTest.java} | 21 +++-- ...xplicitDatasourceConfigUrlMissingTest.java | 40 ++++++++++ ...tPUWithExplicitDatasourceMissingTest.java} | 2 +- ...plicitDatasourceConfigUrlMissingTest.java} | 4 +- ...xplicitDatasourceConfigUrlMissingTest.java | 40 ++++++++++ ...dPUWithExplicitDatasourceMissingTest.java} | 2 +- ...tensionConfigEmptyNamedDatasourceTest.java | 40 ---------- ...onfigUrlMissingDefaultDatasourceTest.java} | 6 +- ...onConfigUrlMissingNamedDatasourceTest.java | 39 ++++++++++ ...efaultDatasourceConfigUrlMissingTest.java} | 6 +- ...AtStartNamedDatasourceConfigEmptyTest.java | 44 ----------- ...rtNamedDatasourceConfigUrlMissingTest.java | 42 ++++++++++ ...alseDefaultDatasourceHealthCheckTest.java} | 13 ++-- ...veFalseNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...lseNamedDatasourceStaticInjectionTest.java | 2 +- ...ssingDefaultDatasourceHealthCheckTest.java | 29 +++++++ ...gDefaultDatasourceStaticInjectionTest.java | 46 +++++++++++ ...ngNamedDatasourceDynamicInjectionTest.java | 76 +++++++++++++++++++ ...MissingNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...alseDefaultDatasourceHealthCheckTest.java} | 13 ++-- ...veFalseNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...ssingDefaultDatasourceHealthCheckTest.java | 29 +++++++ ...gDefaultDatasourceStaticInjectionTest.java | 46 +++++++++++ ...ngNamedDatasourceDynamicInjectionTest.java | 76 +++++++++++++++++++ ...MissingNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...alseDefaultDatasourceHealthCheckTest.java} | 13 ++-- ...veFalseNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...ssingDefaultDatasourceHealthCheckTest.java | 29 +++++++ ...gDefaultDatasourceStaticInjectionTest.java | 46 +++++++++++ ...ngNamedDatasourceDynamicInjectionTest.java | 76 +++++++++++++++++++ ...MissingNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...alseDefaultDatasourceHealthCheckTest.java} | 13 ++-- ...veFalseNamedDatasourceHealthCheckTest.java | 32 ++++++++ ...ssingDefaultDatasourceHealthCheckTest.java | 29 +++++++ ...gDefaultDatasourceStaticInjectionTest.java | 46 +++++++++++ ...ngNamedDatasourceDynamicInjectionTest.java | 76 +++++++++++++++++++ ...MissingNamedDatasourceHealthCheckTest.java | 32 ++++++++ 50 files changed, 1486 insertions(+), 167 deletions(-) rename extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/{DataSourceHealthCheckConfigActiveFalseTest.java => ConfigActiveFalseDefaultDatasourceHealthCheckTest.java} (58%) create mode 100644 extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigActiveFalseNamedDatasourceHealthCheckTest.java create mode 100644 extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java create mode 100644 extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java create mode 100644 extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java create mode 100644 extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java create mode 100644 extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceHealthCheckTest.java create mode 100644 extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceStaticInjectionTest.java create mode 100644 extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java rename extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/{FlywayExtensionConfigEmptyDefaultDatasourceTest.java => FlywayExtensionConfigUrlMissingDefaultDatasourceStaticInjectionTest.java} (55%) rename extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/{FlywayExtensionConfigEmptyNamedDataSourceTest.java => FlywayExtensionConfigUrlMissingNamedDataSourceDynamicInjectionTest.java} (57%) create mode 100644 extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingNamedDataSourceStaticInjectionTest.java rename extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/{FlywayExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java => FlywayExtensionMigrateAtStartDefaultDatasourceUrlMissingTest.java} (90%) rename extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/{FlywayExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java => FlywayExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java} (64%) create mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitDatasourceConfigUrlMissingTest.java rename extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/{EntitiesInDefaultPUWithExplicitUnconfiguredDatasourceTest.java => EntitiesInDefaultPUWithExplicitDatasourceMissingTest.java} (94%) rename extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/{EntitiesInDefaultPUWithImplicitUnconfiguredDatasourceTest.java => EntitiesInDefaultPUWithImplicitDatasourceConfigUrlMissingTest.java} (88%) create mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitDatasourceConfigUrlMissingTest.java rename extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/{EntitiesInNamedPUWithExplicitUnconfiguredDatasourceTest.java => EntitiesInNamedPUWithExplicitDatasourceMissingTest.java} (95%) delete mode 100644 extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigEmptyNamedDatasourceTest.java rename extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/{LiquibaseExtensionConfigEmptyDefaultDatasourceTest.java => LiquibaseExtensionConfigUrlMissingDefaultDatasourceTest.java} (83%) create mode 100644 extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigUrlMissingNamedDatasourceTest.java rename extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/{LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java => LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigUrlMissingTest.java} (89%) delete mode 100644 extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java create mode 100644 extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java rename extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/{DataSourceHealthCheckConfigActiveFalseTest.java => ConfigActiveFalseDefaultDatasourceHealthCheckTest.java} (58%) create mode 100644 extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java create mode 100644 extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java create mode 100644 extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java rename extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/{DataSourceHealthCheckConfigActiveFalseTest.java => ConfigActiveFalseDefaultDatasourceHealthCheckTest.java} (58%) create mode 100644 extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java create mode 100644 extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java create mode 100644 extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java rename extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/{DataSourceHealthCheckConfigActiveFalseTest.java => ConfigActiveFalseDefaultDatasourceHealthCheckTest.java} (58%) create mode 100644 extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java create mode 100644 extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java create mode 100644 extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java rename extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/{DataSourceHealthCheckConfigActiveFalseTest.java => ConfigActiveFalseDefaultDatasourceHealthCheckTest.java} (58%) create mode 100644 extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java create mode 100644 extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java create mode 100644 extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java create mode 100644 extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/DataSourceHealthCheckConfigActiveFalseTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java similarity index 58% rename from extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/DataSourceHealthCheckConfigActiveFalseTest.java rename to extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java index a6a4fe8f5c03e1..2bcc9ea38fc8be 100644 --- a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/DataSourceHealthCheckConfigActiveFalseTest.java +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java @@ -7,24 +7,23 @@ import io.quarkus.test.QuarkusUnitTest; import io.restassured.RestAssured; -public class DataSourceHealthCheckConfigActiveFalseTest { +public class ConfigActiveFalseDefaultDatasourceHealthCheckTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - .withEmptyApplication() - .withConfigurationResource("application-default-datasource.properties") .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.active", "false") // this data source is broken, but will be deactivated, // so the overall check should pass - .overrideConfigKey("quarkus.datasource.brokenDS.db-kind", "h2") - .overrideConfigKey("quarkus.datasource.brokenDS.jdbc.url", "BROKEN") - .overrideConfigKey("quarkus.datasource.brokenDS.active", "false"); + .overrideConfigKey("quarkus.datasource.jdbc.url", "BROKEN"); @Test public void testDataSourceHealthCheckExclusion() { RestAssured.when().get("/q/health/ready") .then() - .body("status", CoreMatchers.equalTo("UP")); + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"\"", CoreMatchers.nullValue()); } } diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigActiveFalseNamedDatasourceHealthCheckTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigActiveFalseNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..ad587dccd82e44 --- /dev/null +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigActiveFalseNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.agroal.test; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigActiveFalseNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.users.active", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2") + // this data source is broken, but will be deactivated, + // so the overall check should pass + .overrideConfigKey("quarkus.datasource.users.jdbc.url", "BROKEN"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"users\"", CoreMatchers.nullValue()); + } + +} diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java new file mode 100644 index 00000000000000..074b0c28b692d6 --- /dev/null +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java @@ -0,0 +1,53 @@ +package io.quarkus.agroal.test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import javax.sql.DataSource; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.agroal.api.AgroalDataSource; +import io.quarkus.arc.InjectableInstance; +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class ConfigUrlMissingDefaultDatasourceDynamicInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Inject + InjectableInstance dataSource; + + @Inject + InjectableInstance agroalDataSource; + + @Test + public void dataSource() { + doTest(dataSource); + } + + @Test + public void agroalDataSource() { + doTest(agroalDataSource); + } + + private void doTest(InjectableInstance instance) { + // The bean is always available to be injected during static init + // since we don't know whether the datasource will be active at runtime. + // So the bean proxy cannot be null. + var ds = instance.get(); + assertThat(ds).isNotNull(); + // However, any attempt to use it at runtime will fail. + assertThatThrownBy(() -> ds.getConnection()) + .isInstanceOf(ConfigurationException.class) + .hasMessageContainingAll("quarkus.datasource.jdbc.url has not been defined"); + ; + } +} diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..bfe53bdf9c4630 --- /dev/null +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java @@ -0,0 +1,28 @@ +package io.quarkus.agroal.test; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingDefaultDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // UnconfiguredDataSource always reports as healthy... + // https://github.com/quarkusio/quarkus/issues/36666 + .body("status", CoreMatchers.equalTo("UP")) + .body("checks[0].data.\"\"", CoreMatchers.equalTo("UP")); + } + +} diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java new file mode 100644 index 00000000000000..7413575685c634 --- /dev/null +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java @@ -0,0 +1,44 @@ +package io.quarkus.agroal.test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.sql.SQLException; + +import javax.sql.DataSource; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class ConfigUrlMissingDefaultDatasourceStaticInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Inject + MyBean myBean; + + @Test + public void test() { + assertThatThrownBy(() -> myBean.useDatasource()) + .isInstanceOf(ConfigurationException.class) + .hasMessageContainingAll("quarkus.datasource.jdbc.url has not been defined"); + } + + @ApplicationScoped + public static class MyBean { + @Inject + DataSource ds; + + public void useDatasource() throws SQLException { + ds.getConnection(); + } + } +} diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java new file mode 100644 index 00000000000000..f7b505a4658505 --- /dev/null +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java @@ -0,0 +1,59 @@ +package io.quarkus.agroal.test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import javax.sql.DataSource; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.agroal.api.AgroalDataSource; +import io.quarkus.arc.InjectableInstance; +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class ConfigUrlMissingNamedDatasourceDynamicInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2"); + + @Inject + @io.quarkus.agroal.DataSource("users") + InjectableInstance dataSource; + + @Inject + @io.quarkus.agroal.DataSource("users") + InjectableInstance agroalDataSource; + + @Test + public void dataSource() { + doTest(dataSource); + } + + @Test + public void agroalDataSource() { + doTest(agroalDataSource); + } + + private void doTest(InjectableInstance instance) { + // The bean is always available to be injected during static init + // since we don't know whether the datasource will be active at runtime. + // So the bean cannot be null. + var ds = instance.get(); + assertThat(ds).isNotNull(); + // However, any attempt to use it at runtime will fail. + assertThatThrownBy(() -> ds.getConnection()) + .isInstanceOf(ConfigurationException.class) + .hasMessageContainingAll("quarkus.datasource.\"users\".jdbc.url has not been defined"); + ; + ; + } +} diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceHealthCheckTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..b12f402689ee6d --- /dev/null +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceHealthCheckTest.java @@ -0,0 +1,31 @@ +package io.quarkus.agroal.test; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // UnconfiguredDataSource always reports as healthy... + // https://github.com/quarkusio/quarkus/issues/36666 + .body("status", CoreMatchers.equalTo("UP")) + .body("checks[0].data.\"users\"", CoreMatchers.equalTo("UP")); + } + +} diff --git a/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceStaticInjectionTest.java b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceStaticInjectionTest.java new file mode 100644 index 00000000000000..3721e7a824e605 --- /dev/null +++ b/extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/ConfigUrlMissingNamedDatasourceStaticInjectionTest.java @@ -0,0 +1,49 @@ +package io.quarkus.agroal.test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.sql.SQLException; + +import javax.sql.DataSource; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class ConfigUrlMissingNamedDatasourceStaticInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2"); + + @Inject + MyBean myBean; + + @Test + public void test() { + assertThatThrownBy(() -> myBean.useDatasource()) + .isInstanceOf(ConfigurationException.class) + .hasMessageContainingAll("quarkus.datasource.\"users\".jdbc.url has not been defined"); + ; + } + + @ApplicationScoped + public static class MyBean { + @Inject + @io.quarkus.agroal.DataSource("users") + DataSource ds; + + public void useDatasource() throws SQLException { + ds.getConnection(); + } + } +} diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java new file mode 100644 index 00000000000000..76864cc578b918 --- /dev/null +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingDefaultDatasourceDynamicInjectionTest.java @@ -0,0 +1,38 @@ +package io.quarkus.flyway.test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import jakarta.enterprise.inject.CreationException; +import jakarta.enterprise.inject.Instance; +import jakarta.inject.Inject; + +import org.flywaydb.core.Flyway; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class FlywayExtensionConfigUrlMissingDefaultDatasourceDynamicInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Inject + Instance flyway; + + @Test + @DisplayName("If the URL is missing for the default datasource, the application should boot, but Flyway should be deactivated for that datasource") + public void testBootSucceedsButFlywayDeactivated() { + assertThatThrownBy(flyway::get) + .isInstanceOf(CreationException.class) + .cause() + .hasMessageContainingAll("Unable to find datasource '' for Flyway", + "Datasource '' is not configured.", + "To solve this, configure datasource ''.", + "Refer to https://quarkus.io/guides/datasource for guidance."); + } + +} diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigEmptyDefaultDatasourceTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingDefaultDatasourceStaticInjectionTest.java similarity index 55% rename from extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigEmptyDefaultDatasourceTest.java rename to extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingDefaultDatasourceStaticInjectionTest.java index 409d1416b6223c..2393a0fbffb6a4 100644 --- a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigEmptyDefaultDatasourceTest.java +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingDefaultDatasourceStaticInjectionTest.java @@ -3,8 +3,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.inject.CreationException; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.flywaydb.core.Flyway; @@ -14,34 +12,19 @@ import io.quarkus.test.QuarkusUnitTest; -public class FlywayExtensionConfigEmptyDefaultDatasourceTest { +public class FlywayExtensionConfigUrlMissingDefaultDatasourceStaticInjectionTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - // The datasource won't be truly "unconfigured" if dev services are enabled + // The URL won't be missing if dev services are enabled .overrideConfigKey("quarkus.devservices.enabled", "false"); - @Inject - Instance flyway; - @Inject MyBean myBean; @Test - @DisplayName("If there is no config for the default datasource, the application should boot, but Flyway should be deactivated for that datasource") + @DisplayName("If the URL is missing for the default datasource, the application should boot, but Flyway should be deactivated for that datasource") public void testBootSucceedsButFlywayDeactivated() { - assertThatThrownBy(flyway::get) - .isInstanceOf(CreationException.class) - .cause() - .hasMessageContainingAll("Unable to find datasource '' for Flyway", - "Datasource '' is not configured.", - "To solve this, configure datasource ''.", - "Refer to https://quarkus.io/guides/datasource for guidance."); - } - - @Test - @DisplayName("If there is no config for the default datasource, the application should boot even if we inject a bean that depends on Flyway, but actually using Flyway should fail") - public void testBootSucceedsWithInjectedBeanDependingOnFlywayButFlywayDeactivated() { assertThatThrownBy(() -> myBean.useFlyway()) .cause() .hasMessageContainingAll("Unable to find datasource '' for Flyway", diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigEmptyNamedDataSourceTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingNamedDataSourceDynamicInjectionTest.java similarity index 57% rename from extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigEmptyNamedDataSourceTest.java rename to extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingNamedDataSourceDynamicInjectionTest.java index 416dfd4ab7e3ff..6f1bc9bd8ed8ad 100644 --- a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigEmptyNamedDataSourceTest.java +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingNamedDataSourceDynamicInjectionTest.java @@ -2,8 +2,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; +import jakarta.enterprise.inject.CreationException; import jakarta.enterprise.inject.Instance; -import jakarta.enterprise.inject.UnsatisfiedResolutionException; import jakarta.inject.Inject; import org.flywaydb.core.Flyway; @@ -14,28 +14,35 @@ import io.quarkus.flyway.FlywayDataSource; import io.quarkus.test.QuarkusUnitTest; -public class FlywayExtensionConfigEmptyNamedDataSourceTest { +public class FlywayExtensionConfigUrlMissingNamedDataSourceDynamicInjectionTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2") // We need this otherwise the *default* datasource may impact this test .overrideConfigKey("quarkus.datasource.db-kind", "h2") .overrideConfigKey("quarkus.datasource.username", "sa") .overrideConfigKey("quarkus.datasource.password", "sa") .overrideConfigKey("quarkus.datasource.jdbc.url", - "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1") - // The datasource won't be truly "unconfigured" if dev services are enabled - .overrideConfigKey("quarkus.devservices.enabled", "false"); + "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1"); @Inject @FlywayDataSource("users") Instance flyway; @Test - @DisplayName("If there is no config for a named datasource, the application should boot, but Flyway should be deactivated for that datasource") + @DisplayName("If the URL is missing for a named datasource, the application should boot, but Flyway should be deactivated for that datasource") public void testBootSucceedsButFlywayDeactivated() { assertThatThrownBy(flyway::get) - .isInstanceOf(UnsatisfiedResolutionException.class) - .hasMessageContaining("No bean found"); + .isInstanceOf(CreationException.class) + .cause() + .hasMessageContainingAll("Unable to find datasource 'users' for Flyway", + "Datasource 'users' is not configured.", + "To solve this, configure datasource 'users'.", + "Refer to https://quarkus.io/guides/datasource for guidance."); } } diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingNamedDataSourceStaticInjectionTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingNamedDataSourceStaticInjectionTest.java new file mode 100644 index 00000000000000..abe1a7bc9bdcbd --- /dev/null +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionConfigUrlMissingNamedDataSourceStaticInjectionTest.java @@ -0,0 +1,56 @@ +package io.quarkus.flyway.test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import org.flywaydb.core.Flyway; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.flyway.FlywayDataSource; +import io.quarkus.test.QuarkusUnitTest; + +public class FlywayExtensionConfigUrlMissingNamedDataSourceStaticInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2") + // We need this otherwise the *default* datasource may impact this test + .overrideConfigKey("quarkus.datasource.db-kind", "h2") + .overrideConfigKey("quarkus.datasource.username", "sa") + .overrideConfigKey("quarkus.datasource.password", "sa") + .overrideConfigKey("quarkus.datasource.jdbc.url", + "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1"); + + @Inject + MyBean myBean; + + @Test + @DisplayName("If the URL is missing for a named datasource, the application should boot, but Flyway should be deactivated for that datasource") + public void testBootSucceedsButFlywayDeactivated() { + assertThatThrownBy(() -> myBean.useFlyway()) + .cause() + .hasMessageContainingAll("Unable to find datasource 'users' for Flyway", + "Datasource 'users' is not configured.", + "To solve this, configure datasource 'users'.", + "Refer to https://quarkus.io/guides/datasource for guidance."); + } + + @ApplicationScoped + public static class MyBean { + @Inject + @FlywayDataSource("users") + Flyway flyway; + + public void useFlyway() { + flyway.getConfiguration(); + } + } +} diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartDefaultDatasourceUrlMissingTest.java similarity index 90% rename from extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java rename to extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartDefaultDatasourceUrlMissingTest.java index a558af70e4947a..4cfaab211de128 100644 --- a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartDefaultDatasourceUrlMissingTest.java @@ -13,14 +13,14 @@ import io.quarkus.test.QuarkusUnitTest; -public class FlywayExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest { +public class FlywayExtensionMigrateAtStartDefaultDatasourceUrlMissingTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar .addAsResource("db/migration/V1.0.0__Quarkus.sql")) .overrideConfigKey("quarkus.flyway.migrate-at-start", "true") - // The datasource won't be truly "unconfigured" if dev services are enabled + // The URL won't be missing if dev services are enabled .overrideConfigKey("quarkus.devservices.enabled", "false"); @Inject diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java similarity index 64% rename from extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java rename to extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java index 6f97323378f57a..db55982bde28f2 100644 --- a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java @@ -2,8 +2,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; +import jakarta.enterprise.inject.CreationException; import jakarta.enterprise.inject.Instance; -import jakarta.enterprise.inject.UnsatisfiedResolutionException; import jakarta.inject.Inject; import org.flywaydb.core.Flyway; @@ -14,21 +14,24 @@ import io.quarkus.flyway.FlywayDataSource; import io.quarkus.test.QuarkusUnitTest; -public class FlywayExtensionMigrateAtStartNamedDatasourceConfigEmptyTest { +public class FlywayExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar .addAsResource("db/migration/V1.0.0__Quarkus.sql")) .overrideConfigKey("quarkus.flyway.users.migrate-at-start", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2") // We need this otherwise the *default* datasource may impact this test .overrideConfigKey("quarkus.datasource.db-kind", "h2") .overrideConfigKey("quarkus.datasource.username", "sa") .overrideConfigKey("quarkus.datasource.password", "sa") .overrideConfigKey("quarkus.datasource.jdbc.url", - "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1") - // The datasource won't be truly "unconfigured" if dev services are enabled - .overrideConfigKey("quarkus.devservices.enabled", "false"); + "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1"); @Inject @FlywayDataSource("users") @@ -38,7 +41,11 @@ public class FlywayExtensionMigrateAtStartNamedDatasourceConfigEmptyTest { @DisplayName("If there is no config for a named datasource, even if migrate-at-start is enabled, the application should boot, but Flyway should be deactivated for that datasource") public void testBootSucceedsButFlywayDeactivated() { assertThatThrownBy(flyway::get) - .isInstanceOf(UnsatisfiedResolutionException.class) - .hasMessageContaining("No bean found"); + .isInstanceOf(CreationException.class) + .cause() + .hasMessageContainingAll("Unable to find datasource 'users' for Flyway", + "Datasource 'users' is not configured.", + "To solve this, configure datasource 'users'.", + "Refer to https://quarkus.io/guides/datasource for guidance."); } } diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitDatasourceConfigUrlMissingTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitDatasourceConfigUrlMissingTest.java new file mode 100644 index 00000000000000..b0837e60ef0695 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitDatasourceConfigUrlMissingTest.java @@ -0,0 +1,40 @@ +package io.quarkus.hibernate.orm.config.datasource; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.config.MyEntity; +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class EntitiesInDefaultPUWithExplicitDatasourceConfigUrlMissingTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClass(MyEntity.class)) + .overrideConfigKey("quarkus.hibernate-orm.datasource", "ds-1") + .overrideConfigKey("quarkus.hibernate-orm.database.generation", "drop-and-create") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "h2") + .assertException(t -> assertThat(t) + .isInstanceOf(ConfigurationException.class) + .hasMessageContainingAll( + "Unable to find datasource 'ds-1' for persistence unit ''", + "Datasource 'ds-1' is not configured.", + "To solve this, configure datasource 'ds-1'.", + "Refer to https://quarkus.io/guides/datasource for guidance.")); + + @Test + public void testInvalidConfiguration() { + // deployment exception should happen first + Assertions.fail(); + } + +} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitUnconfiguredDatasourceTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitDatasourceMissingTest.java similarity index 94% rename from extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitUnconfiguredDatasourceTest.java rename to extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitDatasourceMissingTest.java index 95da1754282784..134c09c40fed23 100644 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitUnconfiguredDatasourceTest.java +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithExplicitDatasourceMissingTest.java @@ -10,7 +10,7 @@ import io.quarkus.runtime.configuration.ConfigurationException; import io.quarkus.test.QuarkusUnitTest; -public class EntitiesInDefaultPUWithExplicitUnconfiguredDatasourceTest { +public class EntitiesInDefaultPUWithExplicitDatasourceMissingTest { @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithImplicitUnconfiguredDatasourceTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithImplicitDatasourceConfigUrlMissingTest.java similarity index 88% rename from extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithImplicitUnconfiguredDatasourceTest.java rename to extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithImplicitDatasourceConfigUrlMissingTest.java index 5e301b02be941a..384bf913693901 100644 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithImplicitUnconfiguredDatasourceTest.java +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInDefaultPUWithImplicitDatasourceConfigUrlMissingTest.java @@ -10,13 +10,13 @@ import io.quarkus.runtime.configuration.ConfigurationException; import io.quarkus.test.QuarkusUnitTest; -public class EntitiesInDefaultPUWithImplicitUnconfiguredDatasourceTest { +public class EntitiesInDefaultPUWithImplicitDatasourceConfigUrlMissingTest { @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar .addClass(MyEntity.class)) - // The datasource won't be truly "unconfigured" if dev services are enabled + // The URL won't be missing if dev services are enabled .overrideConfigKey("quarkus.devservices.enabled", "false") .assertException(t -> assertThat(t) .isInstanceOf(ConfigurationException.class) diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitDatasourceConfigUrlMissingTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitDatasourceConfigUrlMissingTest.java new file mode 100644 index 00000000000000..5161bfd2e4cf21 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitDatasourceConfigUrlMissingTest.java @@ -0,0 +1,40 @@ +package io.quarkus.hibernate.orm.config.datasource; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.config.namedpu.MyEntity; +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class EntitiesInNamedPUWithExplicitDatasourceConfigUrlMissingTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addPackage(MyEntity.class.getPackage().getName())) + .overrideConfigKey("quarkus.hibernate-orm.pu-1.datasource", "ds-1") + .overrideConfigKey("quarkus.hibernate-orm.pu-1.database.generation", "drop-and-create") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "h2") + .assertException(t -> assertThat(t) + .isInstanceOf(ConfigurationException.class) + .hasMessageContainingAll( + "Unable to find datasource 'ds-1' for persistence unit 'pu-1'", + "Datasource 'ds-1' is not configured.", + "To solve this, configure datasource 'ds-1'.", + "Refer to https://quarkus.io/guides/datasource for guidance.")); + + @Test + public void testInvalidConfiguration() { + // deployment exception should happen first + Assertions.fail(); + } + +} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitUnconfiguredDatasourceTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitDatasourceMissingTest.java similarity index 95% rename from extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitUnconfiguredDatasourceTest.java rename to extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitDatasourceMissingTest.java index bc7f76483c09ae..f59962e11570c6 100644 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitUnconfiguredDatasourceTest.java +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/datasource/EntitiesInNamedPUWithExplicitDatasourceMissingTest.java @@ -10,7 +10,7 @@ import io.quarkus.runtime.configuration.ConfigurationException; import io.quarkus.test.QuarkusUnitTest; -public class EntitiesInNamedPUWithExplicitUnconfiguredDatasourceTest { +public class EntitiesInNamedPUWithExplicitDatasourceMissingTest { @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() diff --git a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigEmptyNamedDatasourceTest.java b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigEmptyNamedDatasourceTest.java deleted file mode 100644 index ee9c88272b5ffc..00000000000000 --- a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigEmptyNamedDatasourceTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.quarkus.liquibase.test; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import jakarta.enterprise.inject.Instance; -import jakarta.enterprise.inject.UnsatisfiedResolutionException; -import jakarta.inject.Inject; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.liquibase.LiquibaseDataSource; -import io.quarkus.liquibase.LiquibaseFactory; -import io.quarkus.test.QuarkusUnitTest; - -public class LiquibaseExtensionConfigEmptyNamedDatasourceTest { - - @RegisterExtension - static final QuarkusUnitTest config = new QuarkusUnitTest() - // The datasource won't be truly "unconfigured" if dev services are enabled - .overrideConfigKey("quarkus.devservices.enabled", "false") - // We need this otherwise it's going to be the *default* datasource making everything fail - .overrideConfigKey("quarkus.datasource.db-kind", "h2") - .overrideConfigKey("quarkus.datasource.username", "sa") - .overrideConfigKey("quarkus.datasource.password", "sa") - .overrideConfigKey("quarkus.datasource.jdbc.url", - "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1"); - @Inject - @LiquibaseDataSource("users") - Instance liquibase; - - @Test - @DisplayName("If there is no config for a named datasource, the application should boot, but Liquibase should be deactivated for that datasource") - public void testBootSucceedsButLiquibaseDeactivated() { - assertThatThrownBy(() -> liquibase.get().getConfiguration()) - .isInstanceOf(UnsatisfiedResolutionException.class) - .hasMessageContaining("No bean found"); - } -} diff --git a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigEmptyDefaultDatasourceTest.java b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigUrlMissingDefaultDatasourceTest.java similarity index 83% rename from extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigEmptyDefaultDatasourceTest.java rename to extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigUrlMissingDefaultDatasourceTest.java index ac28eb20acf10f..705a8dfc64c0e7 100644 --- a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigEmptyDefaultDatasourceTest.java +++ b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigUrlMissingDefaultDatasourceTest.java @@ -9,11 +9,11 @@ import io.quarkus.test.QuarkusUnitTest; -public class LiquibaseExtensionConfigEmptyDefaultDatasourceTest { +public class LiquibaseExtensionConfigUrlMissingDefaultDatasourceTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - // The datasource won't be truly "unconfigured" if dev services are enabled + // The URL won't be missing if dev services are enabled .overrideConfigKey("quarkus.devservices.enabled", "false") .assertException(t -> assertThat(t).cause().cause() .hasMessageContainingAll("Unable to find datasource '' for Liquibase", @@ -22,7 +22,7 @@ public class LiquibaseExtensionConfigEmptyDefaultDatasourceTest { "Refer to https://quarkus.io/guides/datasource for guidance.")); @Test - @DisplayName("If there is no config for the default datasource, the application should fail to boot") + @DisplayName("If the URL is missing for the default datasource, the application should fail to boot") public void testBootFails() { // Should not be reached because boot should fail. assertTrue(false); diff --git a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigUrlMissingNamedDatasourceTest.java b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigUrlMissingNamedDatasourceTest.java new file mode 100644 index 00000000000000..8c42d114326b93 --- /dev/null +++ b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionConfigUrlMissingNamedDatasourceTest.java @@ -0,0 +1,39 @@ +package io.quarkus.liquibase.test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class LiquibaseExtensionConfigUrlMissingNamedDatasourceTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2") + // We need this otherwise it's going to be the *default* datasource making everything fail + .overrideConfigKey("quarkus.datasource.db-kind", "h2") + .overrideConfigKey("quarkus.datasource.username", "sa") + .overrideConfigKey("quarkus.datasource.password", "sa") + .overrideConfigKey("quarkus.datasource.jdbc.url", + "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1") + .assertException(t -> assertThat(t).cause().cause() + .hasMessageContainingAll("Unable to find datasource 'users' for Liquibase", + "Datasource 'users' is not configured.", + "To solve this, configure datasource 'users'.", + "Refer to https://quarkus.io/guides/datasource for guidance.")); + + @Test + @DisplayName("If the URL is missing for a named datasource, the application should fail to boot") + public void testBootSucceedsButLiquibaseDeactivated() { + // Should not be reached because boot should fail. + assertTrue(false); + } +} diff --git a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigUrlMissingTest.java similarity index 89% rename from extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java rename to extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigUrlMissingTest.java index bad255b85ccf30..edba6f37261659 100644 --- a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest.java +++ b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigUrlMissingTest.java @@ -9,14 +9,14 @@ import io.quarkus.test.QuarkusUnitTest; -public class LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest { +public class LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigUrlMissingTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar .addAsResource("db/changeLog.xml", "db/changeLog.xml")) .overrideConfigKey("quarkus.liquibase.migrate-at-start", "true") - // The datasource won't be truly "unconfigured" if dev services are enabled + // The URL won't be missing if dev services are enabled .overrideConfigKey("quarkus.devservices.enabled", "false") .assertException(t -> assertThat(t).cause().cause() .hasMessageContainingAll("Unable to find datasource '' for Liquibase", @@ -25,7 +25,7 @@ public class LiquibaseExtensionMigrateAtStartDefaultDatasourceConfigEmptyTest { "Refer to https://quarkus.io/guides/datasource for guidance.")); @Test - @DisplayName("If there is no config for the default datasource, and if migrate-at-start is enabled, the application should fail to boot") + @DisplayName("If the URL is missing for the default datasource, and if migrate-at-start is enabled, the application should fail to boot") public void testBootFails() { // Should not be reached because boot should fail. assertTrue(false); diff --git a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java deleted file mode 100644 index 8353a2b22a8490..00000000000000 --- a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigEmptyTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.quarkus.liquibase.test; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import jakarta.enterprise.inject.Instance; -import jakarta.enterprise.inject.UnsatisfiedResolutionException; -import jakarta.inject.Inject; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.liquibase.LiquibaseDataSource; -import io.quarkus.liquibase.LiquibaseFactory; -import io.quarkus.test.QuarkusUnitTest; - -public class LiquibaseExtensionMigrateAtStartNamedDatasourceConfigEmptyTest { - - @RegisterExtension - static final QuarkusUnitTest config = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addAsResource("db/changeLog.xml", "db/changeLog.xml")) - .overrideConfigKey("quarkus.liquibase.users.migrate-at-start", "true") - // The datasource won't be truly "unconfigured" if dev services are enabled - .overrideConfigKey("quarkus.devservices.enabled", "false") - // We need this otherwise it's going to be the *default* datasource making everything fail - .overrideConfigKey("quarkus.datasource.db-kind", "h2") - .overrideConfigKey("quarkus.datasource.username", "sa") - .overrideConfigKey("quarkus.datasource.password", "sa") - .overrideConfigKey("quarkus.datasource.jdbc.url", - "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1"); - - @Inject - @LiquibaseDataSource("users") - Instance liquibase; - - @Test - @DisplayName("If there is no config for a named datasource, even if migrate-at-start is enabled, the application should boot, but Liquibase should be deactivated for that datasource") - public void testBootSucceedsButLiquibaseDeactivated() { - assertThatThrownBy(() -> liquibase.get().getConfiguration()) - .isInstanceOf(UnsatisfiedResolutionException.class) - .hasMessageContaining("No bean found"); - } -} diff --git a/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java new file mode 100644 index 00000000000000..2ebc29ac30650f --- /dev/null +++ b/extensions/liquibase/deployment/src/test/java/io/quarkus/liquibase/test/LiquibaseExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest.java @@ -0,0 +1,42 @@ +package io.quarkus.liquibase.test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class LiquibaseExtensionMigrateAtStartNamedDatasourceConfigUrlMissingTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addAsResource("db/changeLog.xml", "db/changeLog.xml")) + .overrideConfigKey("quarkus.liquibase.users.migrate-at-start", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.users.db-kind", "h2") + // We need this otherwise it's going to be the *default* datasource making everything fail + .overrideConfigKey("quarkus.datasource.db-kind", "h2") + .overrideConfigKey("quarkus.datasource.username", "sa") + .overrideConfigKey("quarkus.datasource.password", "sa") + .overrideConfigKey("quarkus.datasource.jdbc.url", + "jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1") + .assertException(t -> assertThat(t).cause().cause() + .hasMessageContainingAll("Unable to find datasource 'users' for Liquibase", + "Datasource 'users' is not configured.", + "To solve this, configure datasource 'users'.", + "Refer to https://quarkus.io/guides/datasource for guidance.")); + + @Test + @DisplayName("If the URL is missing for a named datasource, and if migrate-at-start is enabled, the application should fail to boot") + public void testBootFails() { + // Should not be reached because boot should fail. + assertTrue(false); + } +} diff --git a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/DataSourceHealthCheckConfigActiveFalseTest.java b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java similarity index 58% rename from extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/DataSourceHealthCheckConfigActiveFalseTest.java rename to extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java index 08f702e03f64dc..4f1c66304616c6 100644 --- a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/DataSourceHealthCheckConfigActiveFalseTest.java +++ b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java @@ -7,24 +7,23 @@ import io.quarkus.test.QuarkusUnitTest; import io.restassured.RestAssured; -public class DataSourceHealthCheckConfigActiveFalseTest { +public class ConfigActiveFalseDefaultDatasourceHealthCheckTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - .withEmptyApplication() - .withConfigurationResource("application-default-datasource.properties") .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.active", "false") // this data source is broken, but will be deactivated, // so the overall check should pass - .overrideConfigKey("quarkus.datasource.brokenDS.db-kind", "mssql") - .overrideConfigKey("quarkus.datasource.brokenDS.reactive.url", "BROKEN") - .overrideConfigKey("quarkus.datasource.brokenDS.active", "false"); + .overrideConfigKey("quarkus.datasource.reactive.url", "BROKEN"); @Test public void testDataSourceHealthCheckExclusion() { RestAssured.when().get("/q/health/ready") .then() - .body("status", CoreMatchers.equalTo("UP")); + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"\"", CoreMatchers.nullValue()); } } diff --git a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..1f6b4aa776aa39 --- /dev/null +++ b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.mssql.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigActiveFalseNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.ds-1.active", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "mssql") + // this data source is broken, but will be deactivated, + // so the overall check should pass + .overrideConfigKey("quarkus.datasource.ds-1.reactive.url", "BROKEN"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"users\"", CoreMatchers.nullValue()); + } + +} diff --git a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceStaticInjectionTest.java b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceStaticInjectionTest.java index 0c5ac6034a3c8e..ff80fe8b84745c 100644 --- a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceStaticInjectionTest.java +++ b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigActiveFalseNamedDatasourceStaticInjectionTest.java @@ -37,7 +37,7 @@ public void test() { .hasMessageContainingAll("Datasource 'ds-1' was deactivated through configuration properties.", "To solve this, avoid accessing this datasource at runtime, for instance by deactivating consumers (persistence units, ...).", "Alternatively, activate the datasource by setting configuration property 'quarkus.datasource.\"ds-1\".active'" - + " to 'true' and configure datasource 'ds-1'", + + " to 'true' and configure datasource 'ds-1'", "Refer to https://quarkus.io/guides/datasource for guidance."); } diff --git a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..bc8f8cd210979d --- /dev/null +++ b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java @@ -0,0 +1,29 @@ +package io.quarkus.reactive.mssql.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingDefaultDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.\"\"", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +} diff --git a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java new file mode 100644 index 00000000000000..1171055d4838eb --- /dev/null +++ b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java @@ -0,0 +1,46 @@ +package io.quarkus.reactive.mssql.client; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.net.ConnectException; +import java.util.concurrent.CompletionStage; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingDefaultDatasourceStaticInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Inject + MyBean myBean; + + @Test + public void test() { + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> myBean.usePool().toCompletableFuture().join()) + .cause() + .isInstanceOf(ConnectException.class); + } + + @ApplicationScoped + public static class MyBean { + @Inject + Pool pool; + + public CompletionStage usePool() { + return pool.getConnection().toCompletionStage().toCompletableFuture(); + } + } +} diff --git a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java new file mode 100644 index 00000000000000..3d715cc0148b26 --- /dev/null +++ b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java @@ -0,0 +1,76 @@ +package io.quarkus.reactive.mssql.client; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.net.ConnectException; +import java.util.function.Consumer; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.InjectableInstance; +import io.quarkus.reactive.datasource.ReactiveDataSource; +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.mssqlclient.MSSQLPool; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingNamedDatasourceDynamicInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "mssql"); + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance pool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance vendorPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyVendorPool; + + @Test + public void pool() { + doTest(pool, pool1 -> pool1.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyPool() { + doTest(mutinyPool, pool1 -> pool1.getConnection().subscribe().asCompletionStage().join()); + } + + @Test + public void vendorPool() { + doTest(vendorPool, MSSQLPool -> MSSQLPool.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyVendorPool() { + doTest(mutinyVendorPool, MSSQLPool -> MSSQLPool.getConnection().subscribe().asCompletionStage().join()); + } + + private void doTest(InjectableInstance instance, Consumer action) { + var pool = instance.get(); + assertThat(pool).isNotNull(); + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> action.accept(pool)) + .cause() + .isInstanceOf(ConnectException.class); + } +} diff --git a/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..74fcd4f25744be --- /dev/null +++ b/extensions/reactive-mssql-client/deployment/src/test/java/io/quarkus/reactive/mssql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.mssql.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "mssql"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.ds-1", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +} diff --git a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/DataSourceHealthCheckConfigActiveFalseTest.java b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java similarity index 58% rename from extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/DataSourceHealthCheckConfigActiveFalseTest.java rename to extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java index 40f9830df37878..ca55c8fd072de2 100644 --- a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/DataSourceHealthCheckConfigActiveFalseTest.java +++ b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java @@ -7,24 +7,23 @@ import io.quarkus.test.QuarkusUnitTest; import io.restassured.RestAssured; -public class DataSourceHealthCheckConfigActiveFalseTest { +public class ConfigActiveFalseDefaultDatasourceHealthCheckTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - .withEmptyApplication() - .withConfigurationResource("application-default-datasource.properties") .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.active", "false") // this data source is broken, but will be deactivated, // so the overall check should pass - .overrideConfigKey("quarkus.datasource.brokenDS.db-kind", "mysql") - .overrideConfigKey("quarkus.datasource.brokenDS.reactive.url", "BROKEN") - .overrideConfigKey("quarkus.datasource.brokenDS.active", "false"); + .overrideConfigKey("quarkus.datasource.reactive.url", "BROKEN"); @Test public void testDataSourceHealthCheckExclusion() { RestAssured.when().get("/q/health/ready") .then() - .body("status", CoreMatchers.equalTo("UP")); + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"\"", CoreMatchers.nullValue()); } } diff --git a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..a8482821f7a057 --- /dev/null +++ b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.mysql.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigActiveFalseNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.ds-1.active", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "mysql") + // this data source is broken, but will be deactivated, + // so the overall check should pass + .overrideConfigKey("quarkus.datasource.ds-1.reactive.url", "BROKEN"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"users\"", CoreMatchers.nullValue()); + } + +} diff --git a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..0c68d63a3a3c1e --- /dev/null +++ b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java @@ -0,0 +1,29 @@ +package io.quarkus.reactive.mysql.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingDefaultDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.\"\"", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +} diff --git a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java new file mode 100644 index 00000000000000..206b61928b60a3 --- /dev/null +++ b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java @@ -0,0 +1,46 @@ +package io.quarkus.reactive.mysql.client; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.net.ConnectException; +import java.util.concurrent.CompletionStage; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingDefaultDatasourceStaticInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Inject + MyBean myBean; + + @Test + public void test() { + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> myBean.usePool().toCompletableFuture().join()) + .cause() + .isInstanceOf(ConnectException.class); + } + + @ApplicationScoped + public static class MyBean { + @Inject + Pool pool; + + public CompletionStage usePool() { + return pool.getConnection().toCompletionStage().toCompletableFuture(); + } + } +} diff --git a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java new file mode 100644 index 00000000000000..09e8a178ef59e4 --- /dev/null +++ b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java @@ -0,0 +1,76 @@ +package io.quarkus.reactive.mysql.client; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.net.ConnectException; +import java.util.function.Consumer; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.InjectableInstance; +import io.quarkus.reactive.datasource.ReactiveDataSource; +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.mysqlclient.MySQLPool; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingNamedDatasourceDynamicInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "mysql"); + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance pool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance vendorPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyVendorPool; + + @Test + public void pool() { + doTest(pool, pool1 -> pool1.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyPool() { + doTest(mutinyPool, pool1 -> pool1.getConnection().subscribe().asCompletionStage().join()); + } + + @Test + public void vendorPool() { + doTest(vendorPool, mySQLPool -> mySQLPool.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyVendorPool() { + doTest(mutinyVendorPool, mySQLPool -> mySQLPool.getConnection().subscribe().asCompletionStage().join()); + } + + private void doTest(InjectableInstance instance, Consumer action) { + var pool = instance.get(); + assertThat(pool).isNotNull(); + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> action.accept(pool)) + .cause() + .isInstanceOf(ConnectException.class); + } +} diff --git a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..23b7e93b73cf42 --- /dev/null +++ b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.mysql.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "mysql"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.ds-1", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +} diff --git a/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/DataSourceHealthCheckConfigActiveFalseTest.java b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java similarity index 58% rename from extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/DataSourceHealthCheckConfigActiveFalseTest.java rename to extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java index 77917281002116..562a1b56dc94d1 100644 --- a/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/DataSourceHealthCheckConfigActiveFalseTest.java +++ b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java @@ -7,24 +7,23 @@ import io.quarkus.test.QuarkusUnitTest; import io.restassured.RestAssured; -public class DataSourceHealthCheckConfigActiveFalseTest { +public class ConfigActiveFalseDefaultDatasourceHealthCheckTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - .withEmptyApplication() - .withConfigurationResource("application-default-datasource.properties") .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.active", "false") // this data source is broken, but will be deactivated, // so the overall check should pass - .overrideConfigKey("quarkus.datasource.brokenDS.db-kind", "oracle") - .overrideConfigKey("quarkus.datasource.brokenDS.reactive.url", "BROKEN") - .overrideConfigKey("quarkus.datasource.brokenDS.active", "false"); + .overrideConfigKey("quarkus.datasource.reactive.url", "BROKEN"); @Test public void testDataSourceHealthCheckExclusion() { RestAssured.when().get("/q/health/ready") .then() - .body("status", CoreMatchers.equalTo("UP")); + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"\"", CoreMatchers.nullValue()); } } diff --git a/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..9636be1efdfd01 --- /dev/null +++ b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.oracle.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigActiveFalseNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.ds-1.active", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "oracle") + // this data source is broken, but will be deactivated, + // so the overall check should pass + .overrideConfigKey("quarkus.datasource.ds-1.reactive.url", "BROKEN"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"users\"", CoreMatchers.nullValue()); + } + +} diff --git a/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..d7fb1b8bdef004 --- /dev/null +++ b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java @@ -0,0 +1,29 @@ +package io.quarkus.reactive.oracle.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingDefaultDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.\"\"", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +} diff --git a/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java new file mode 100644 index 00000000000000..1abbc848c5b9eb --- /dev/null +++ b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java @@ -0,0 +1,46 @@ +package io.quarkus.reactive.oracle.client; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.concurrent.CompletionStage; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.oracleclient.OracleException; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingDefaultDatasourceStaticInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Inject + MyBean myBean; + + @Test + public void test() { + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> myBean.usePool().toCompletableFuture().join()) + .cause() + .isInstanceOf(OracleException.class); + } + + @ApplicationScoped + public static class MyBean { + @Inject + Pool pool; + + public CompletionStage usePool() { + return pool.getConnection().toCompletionStage().toCompletableFuture(); + } + } +} diff --git a/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java new file mode 100644 index 00000000000000..b143a597a06575 --- /dev/null +++ b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java @@ -0,0 +1,76 @@ +package io.quarkus.reactive.oracle.client; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.function.Consumer; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.InjectableInstance; +import io.quarkus.reactive.datasource.ReactiveDataSource; +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.oracleclient.OracleException; +import io.vertx.oracleclient.OraclePool; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingNamedDatasourceDynamicInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "oracle"); + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance pool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance vendorPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyVendorPool; + + @Test + public void pool() { + doTest(pool, pool1 -> pool1.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyPool() { + doTest(mutinyPool, pool1 -> pool1.getConnection().subscribe().asCompletionStage().join()); + } + + @Test + public void vendorPool() { + doTest(vendorPool, oraclePool -> oraclePool.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyVendorPool() { + doTest(mutinyVendorPool, oraclePool -> oraclePool.getConnection().subscribe().asCompletionStage().join()); + } + + private void doTest(InjectableInstance instance, Consumer action) { + var pool = instance.get(); + assertThat(pool).isNotNull(); + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> action.accept(pool)) + .cause() + .isInstanceOf(OracleException.class); + } +} diff --git a/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..0857ac9fb261dd --- /dev/null +++ b/extensions/reactive-oracle-client/deployment/src/test/java/io/quarkus/reactive/oracle/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.oracle.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "oracle"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.ds-1", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +} diff --git a/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/DataSourceHealthCheckConfigActiveFalseTest.java b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java similarity index 58% rename from extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/DataSourceHealthCheckConfigActiveFalseTest.java rename to extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java index 1b9c7d61639ff4..a2f594622fd6cf 100644 --- a/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/DataSourceHealthCheckConfigActiveFalseTest.java +++ b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigActiveFalseDefaultDatasourceHealthCheckTest.java @@ -7,24 +7,23 @@ import io.quarkus.test.QuarkusUnitTest; import io.restassured.RestAssured; -public class DataSourceHealthCheckConfigActiveFalseTest { +public class ConfigActiveFalseDefaultDatasourceHealthCheckTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - .withEmptyApplication() - .withConfigurationResource("application-default-datasource.properties") .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.active", "false") // this data source is broken, but will be deactivated, // so the overall check should pass - .overrideConfigKey("quarkus.datasource.brokenDS.db-kind", "postgresql") - .overrideConfigKey("quarkus.datasource.brokenDS.reactive.url", "BROKEN") - .overrideConfigKey("quarkus.datasource.brokenDS.active", "false"); + .overrideConfigKey("quarkus.datasource.reactive.url", "BROKEN"); @Test public void testDataSourceHealthCheckExclusion() { RestAssured.when().get("/q/health/ready") .then() - .body("status", CoreMatchers.equalTo("UP")); + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"\"", CoreMatchers.nullValue()); } } diff --git a/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..8a176414a55a12 --- /dev/null +++ b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigActiveFalseNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.pg.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigActiveFalseNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + .overrideConfigKey("quarkus.datasource.ds-1.active", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "pg") + // this data source is broken, but will be deactivated, + // so the overall check should pass + .overrideConfigKey("quarkus.datasource.ds-1.reactive.url", "BROKEN"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + .body("status", CoreMatchers.equalTo("UP")) + // If the datasource is inactive, there should not be a health check + .body("checks[0].data.\"users\"", CoreMatchers.nullValue()); + } + +} diff --git a/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..dde82b176d34ef --- /dev/null +++ b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceHealthCheckTest.java @@ -0,0 +1,29 @@ +package io.quarkus.reactive.pg.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingDefaultDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.\"\"", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +} diff --git a/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java new file mode 100644 index 00000000000000..56d3c2cda7224a --- /dev/null +++ b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingDefaultDatasourceStaticInjectionTest.java @@ -0,0 +1,46 @@ +package io.quarkus.reactive.pg.client; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.net.ConnectException; +import java.util.concurrent.CompletionStage; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingDefaultDatasourceStaticInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false"); + + @Inject + MyBean myBean; + + @Test + public void test() { + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> myBean.usePool().toCompletableFuture().join()) + .cause() + .isInstanceOf(ConnectException.class); + } + + @ApplicationScoped + public static class MyBean { + @Inject + Pool pool; + + public CompletionStage usePool() { + return pool.getConnection().toCompletionStage().toCompletableFuture(); + } + } +} diff --git a/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java new file mode 100644 index 00000000000000..fd28bc7ac09a38 --- /dev/null +++ b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceDynamicInjectionTest.java @@ -0,0 +1,76 @@ +package io.quarkus.reactive.pg.client; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.net.ConnectException; +import java.util.function.Consumer; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.InjectableInstance; +import io.quarkus.reactive.datasource.ReactiveDataSource; +import io.quarkus.test.QuarkusUnitTest; +import io.vertx.pgclient.PgPool; +import io.vertx.sqlclient.Pool; + +public class ConfigUrlMissingNamedDatasourceDynamicInjectionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "pg"); + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance pool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance vendorPool; + + @Inject + @ReactiveDataSource("ds-1") + InjectableInstance mutinyVendorPool; + + @Test + public void pool() { + doTest(pool, pool1 -> pool1.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyPool() { + doTest(mutinyPool, pool1 -> pool1.getConnection().subscribe().asCompletionStage().join()); + } + + @Test + public void vendorPool() { + doTest(vendorPool, pgPool -> pgPool.getConnection().toCompletionStage().toCompletableFuture().join()); + } + + @Test + public void mutinyVendorPool() { + doTest(mutinyVendorPool, pgPool -> pgPool.getConnection().subscribe().asCompletionStage().join()); + } + + private void doTest(InjectableInstance instance, Consumer action) { + var pool = instance.get(); + assertThat(pool).isNotNull(); + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a connection exception. + assertThatThrownBy(() -> action.accept(pool)) + .cause() + .isInstanceOf(ConnectException.class); + } +} diff --git a/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java new file mode 100644 index 00000000000000..e345e322d925db --- /dev/null +++ b/extensions/reactive-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/ConfigUrlMissingNamedDatasourceHealthCheckTest.java @@ -0,0 +1,32 @@ +package io.quarkus.reactive.pg.client; + +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class ConfigUrlMissingNamedDatasourceHealthCheckTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.datasource.health.enabled", "true") + // The URL won't be missing if dev services are enabled + .overrideConfigKey("quarkus.devservices.enabled", "false") + // We need at least one build-time property for the datasource, + // otherwise it's considered unconfigured at build time... + .overrideConfigKey("quarkus.datasource.ds-1.db-kind", "pg"); + + @Test + public void testDataSourceHealthCheckExclusion() { + RestAssured.when().get("/q/health/ready") + .then() + // When the URL is missing, the client assumes a default one. + // See https://github.com/quarkusio/quarkus/issues/43517 + // In this case the default won't work, resulting in a failing health check. + .body("status", CoreMatchers.equalTo("DOWN")) + .body("checks[0].data.ds-1", CoreMatchers.startsWithIgnoringCase("DOWN")); + } + +}