Skip to content

Commit

Permalink
Merge pull request #23466 from famod/ora-devservice-test
Browse files Browse the repository at this point in the history
Add `DevServicesOracleDatasourceTestCase`
  • Loading branch information
Sanne authored Feb 7, 2022
2 parents 9e2c886 + 368a808 commit 9899274
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
49 changes: 49 additions & 0 deletions extensions/jdbc/jdbc-oracle/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devservices-oracle</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -49,6 +64,40 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/DevServices*TestCase.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>test-devservices</id>
<activation>
<property>
<name>test-containers</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<!-- force the default, overriding the DevServices exclude -->
<exclude>**/*$*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.quarkus.jdbc.oracle.deployment;

import static org.assertj.core.api.Assertions.assertThat;
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 java.util.logging.Level;
import java.util.logging.LogRecord;

import javax.inject.Inject;

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.agroal.api.exceptionsorter.OracleExceptionSorter;
import io.quarkus.test.QuarkusUnitTest;

public class DevServicesOracleDatasourceTestCase {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withEmptyApplication()
// Expect no warnings (in particular from Agroal)
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()
// There are other warnings: JDK8, TestContainers, drivers, ...
// Ignore them: we're only interested in Agroal here.
&& record.getMessage().contains("Agroal"))
.assertLogRecords(records -> assertThat(records)
// This is just to get meaningful error messages, as LogRecord doesn't have a toString()
.extracting(LogRecord::getMessage)
.isEmpty());

@Inject
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:oracle:"));
assertEquals("quarkus", configuration.connectionFactoryConfiguration().principal().getName());
assertEquals(20, configuration.maxSize());
assertThat(configuration.exceptionSorter()).isInstanceOf(OracleExceptionSorter.class);

try (Connection connection = dataSource.getConnection()) {
}
}
}

0 comments on commit 9899274

Please sign in to comment.