Browse Source

Make Oracle tests work with Testcontainers 1.16.2.

The new Testcontainers version comes with a standard Oracle image configured and doesn't work with the one we used so far.
Making the standard image work required some tweaks to the setup so that the test user has the required privileges.

Closes #1081
pull/1092/head
Jens Schauder 4 years ago
parent
commit
baee76a46d
No known key found for this signature in database
GPG Key ID: 45CC872F17423DBF
  1. 18
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java

18
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java

@ -21,12 +21,13 @@ import org.slf4j.Logger; @@ -21,12 +21,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.testcontainers.containers.OracleContainer;
/**
* {@link DataSource} setup for Oracle Database XE. Starts a docker container with a Oracle database.
* {@link DataSource} setup for Oracle Database XE. Starts a docker container with an Oracle database.
*
* @see <a href=
* "https://blogs.oracle.com/oraclemagazine/deliver-oracle-database-18c-express-edition-in-containers">Oracle
@ -53,16 +54,25 @@ public class OracleDataSourceConfiguration extends DataSourceConfiguration { @@ -53,16 +54,25 @@ public class OracleDataSourceConfiguration extends DataSourceConfiguration {
if (ORACLE_CONTAINER == null) {
LOG.info("Oracle starting...");
OracleContainer container = new OracleContainer("springci/spring-data-oracle-xe-prebuild:18.4.0").withReuse(true);
OracleContainer container = new OracleContainer("gvenzl/oracle-xe:18.4.0-slim").withReuse(true);
container.start();
LOG.info("Oracle started");
ORACLE_CONTAINER = container;
}
String jdbcUrl = ORACLE_CONTAINER.getJdbcUrl().replace(":xe", "/XEPDB1");
initDb();
return new DriverManagerDataSource(jdbcUrl, ORACLE_CONTAINER.getUsername(), ORACLE_CONTAINER.getPassword());
return new DriverManagerDataSource(ORACLE_CONTAINER.getJdbcUrl(), ORACLE_CONTAINER.getUsername(),
ORACLE_CONTAINER.getPassword());
}
private void initDb() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource(ORACLE_CONTAINER.getJdbcUrl(), "SYSTEM",
ORACLE_CONTAINER.getPassword());
final JdbcTemplate jdbc = new JdbcTemplate(dataSource);
jdbc.execute("GRANT ALL PRIVILEGES TO " + ORACLE_CONTAINER.getUsername());
}
@Override

Loading…
Cancel
Save