Skip to content

Commit

Permalink
Test JDBC Dev services on a named datasource with an explicit usernam…
Browse files Browse the repository at this point in the history
…e/password
  • Loading branch information
yrodiere committed Jul 19, 2022
1 parent 8db6af3 commit e2e33be
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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()) {
}
}
}

0 comments on commit e2e33be

Please sign in to comment.