4

I try to use Test Containers with Oracle-XE module and Spring Boot and so far, when I launch my test, I am confronted to exception :

Caused by: java.lang.IllegalArgumentException: JDBC URL matches jdbc:tc: prefix but the database or tag name could not be identified

In my src/test/application.properties, I declared the url datatasource as :

spring.datasource.url=jdbc:tc:oracle-xe://somehostname:someport/databasename?TC_INITSCRIPT=schema-test.sql

To indicate the docker image to pull for oracle-xe, I created the file testcontainers.properties in src/test/resources :

oracle.container.image=oracleinanutshell/oracle-xe-11g:1.0.0

Do you have any idea how to make this work ?

It works flawlessly with MySQL, with the datasource url :

spring.datasource.url=jdbc:tc:mysql:5.6.23://somehostname:someport/databasename?TC_INITSCRIPT=schema-test.sql
L. CWI
  • 952
  • 9
  • 15

1 Answers1

6

You can make a test configuration class that redefine datasource bean with oracle xe container configuration.

public class OracleIT  {

    @ClassRule
    public static OracleContainer oracleContainer = new OracleContainer();

    @BeforeAll
    public static void startup() {
        oracleContainer.start();
    }

    @TestConfiguration
        static class OracleTestConfiguration {

            @Bean
            DataSource dataSource() {
                HikariConfig hikariConfig = new HikariConfig();
                hikariConfig.setJdbcUrl(oracleContainer.getJdbcUrl());
                hikariConfig.setUsername(oracleContainer.getUsername());
                hikariConfig.setPassword(oracleContainer.getPassword());

                return new HikariDataSource(hikariConfig);
            }
      }

}
MC Ninjava
  • 214
  • 2
  • 7
  • Thank you ! That works. But is it possible to make it work only by configuration in application.properties (like MySQL) ? – L. CWI Aug 05 '19 at 13:20
  • 2
    I believe that you cannot know all oracle configuration before the container starts – MC Ninjava Aug 05 '19 at 13:28