From e2e33beb86d00f77ed71a242d7dcdb2ec388d451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Tue, 19 Jul 2022 14:55:55 +0200 Subject: [PATCH] Test JDBC Dev services on a named datasource with an explicit username/password --- ...qlDatasourceNamedWithUsernameTestCase.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 extensions/jdbc/jdbc-postgresql/deployment/src/test/java/io/quarkus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceNamedWithUsernameTestCase.java diff --git a/extensions/jdbc/jdbc-postgresql/deployment/src/test/java/io/quarkus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceNamedWithUsernameTestCase.java b/extensions/jdbc/jdbc-postgresql/deployment/src/test/java/io/quarkus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceNamedWithUsernameTestCase.java new file mode 100644 index 0000000000000..e888609d19b6c --- /dev/null +++ b/extensions/jdbc/jdbc-postgresql/deployment/src/test/java/io/quarkus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceNamedWithUsernameTestCase.java @@ -0,0 +1,48 @@ +package io.quarkus.jdbc.postgresql.deployment; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.sql.Connection; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.agroal.api.AgroalDataSource; +import io.agroal.api.configuration.AgroalConnectionPoolConfiguration; +import io.quarkus.test.QuarkusUnitTest; + +public class DevServicesPostgresqlDatasourceNamedWithUsernameTestCase { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .withEmptyApplication() + .overrideConfigKey("quarkus.datasource.\"DB2\".db-kind", "postgresql") + .overrideConfigKey("quarkus.datasource.\"DB2\".username", "foo") + .overrideConfigKey("quarkus.datasource.\"DB2\".password", "foo"); + + @Inject + @Named("DB2") + AgroalDataSource dataSource; + + @Test + public void testDatasource() throws Exception { + AgroalConnectionPoolConfiguration configuration = null; + + try { + configuration = dataSource.getConfiguration().connectionPoolConfiguration(); + } catch (NullPointerException e) { + // we catch the NPE here as we have a proxycd and we can't test dataSource directly + fail("Datasource should not be null"); + } + assertTrue(configuration.connectionFactoryConfiguration().jdbcUrl().contains("jdbc:postgresql:")); + assertEquals("foo", configuration.connectionFactoryConfiguration().principal().getName()); + + try (Connection connection = dataSource.getConnection()) { + } + } +}