-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test JDBC Dev services on a named datasource with an explicit usernam…
…e/password
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
.../jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceNamedWithUsernameTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()) { | ||
} | ||
} | ||
} |