Skip to content

Commit baee76a

Browse files
committed
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
1 parent b1b5fe9 commit baee76a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
import org.slf4j.LoggerFactory;
2222
import org.springframework.context.annotation.Configuration;
2323
import org.springframework.context.annotation.Profile;
24+
import org.springframework.jdbc.core.JdbcTemplate;
2425
import org.springframework.jdbc.datasource.DriverManagerDataSource;
2526
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
2627
import org.testcontainers.containers.OracleContainer;
2728

2829
/**
29-
* {@link DataSource} setup for Oracle Database XE. Starts a docker container with a Oracle database.
30+
* {@link DataSource} setup for Oracle Database XE. Starts a docker container with an Oracle database.
3031
*
3132
* @see <a href=
3233
* "https://blogs.oracle.com/oraclemagazine/deliver-oracle-database-18c-express-edition-in-containers">Oracle
@@ -53,16 +54,25 @@ protected DataSource createDataSource() {
5354
if (ORACLE_CONTAINER == null) {
5455

5556
LOG.info("Oracle starting...");
56-
OracleContainer container = new OracleContainer("springci/spring-data-oracle-xe-prebuild:18.4.0").withReuse(true);
57+
OracleContainer container = new OracleContainer("gvenzl/oracle-xe:18.4.0-slim").withReuse(true);
5758
container.start();
5859
LOG.info("Oracle started");
5960

6061
ORACLE_CONTAINER = container;
6162
}
6263

63-
String jdbcUrl = ORACLE_CONTAINER.getJdbcUrl().replace(":xe", "/XEPDB1");
64+
initDb();
6465

65-
return new DriverManagerDataSource(jdbcUrl, ORACLE_CONTAINER.getUsername(), ORACLE_CONTAINER.getPassword());
66+
return new DriverManagerDataSource(ORACLE_CONTAINER.getJdbcUrl(), ORACLE_CONTAINER.getUsername(),
67+
ORACLE_CONTAINER.getPassword());
68+
}
69+
70+
private void initDb() {
71+
72+
final DriverManagerDataSource dataSource = new DriverManagerDataSource(ORACLE_CONTAINER.getJdbcUrl(), "SYSTEM",
73+
ORACLE_CONTAINER.getPassword());
74+
final JdbcTemplate jdbc = new JdbcTemplate(dataSource);
75+
jdbc.execute("GRANT ALL PRIVILEGES TO " + ORACLE_CONTAINER.getUsername());
6676
}
6777

6878
@Override

0 commit comments

Comments
 (0)