Skip to content

Instantly share code, notes, and snippets.

@netstart
Last active July 23, 2021 17:39
Show Gist options
  • Save netstart/ab50e4782cf0527487bc2a8c94f11e65 to your computer and use it in GitHub Desktop.
Save netstart/ab50e4782cf0527487bc2a8c94f11e65 to your computer and use it in GitHub Desktop.
OracleTestContainer
spring:
datasource:
url: jdbc:tc:oracle:thin@localhost:1521:xe
# url: jdbc:tc:oracle:thin:system/oracle@localhost:1521:xe
# username: system
# password: oracle
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
package matera.spi.qr;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.OracleContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.sql.SQLException;
import static org.junit.Assert.assertEquals;
@Testcontainers
@ActiveProfiles("oracle-test")
@SpringBootTest
public class OracleLiquibaseTest {
@Container
static OracleContainer container =
// new OracleContainer("harbor-dev.matera.com/docker-hub/pvargacl/oracle-xe-18.4.0");
new OracleContainer("harbor-dev.matera.com/docker-hub/gvenzl/oracle-xe:18.4.0")
.withEnv("ORACLE_PASSWORD", "oracle")
.withExposedPorts(1521);
// .waitingFor(Wait.forLogMessage("Completed: ALTER PLUGGABLE DATABASE XEPDB1 SAVE STATE", 1))
// .withStartupCheckStrategy(
// new IndefiniteWaitOneShotStartupCheckStrategy() // https://www.testcontainers.org/features/startup_and_waits
// );
// .withPassword("oracle")
// .withUsername("system")
// .withDatabaseName("xe");
// .withReuse(true);
@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", container::getJdbcUrl);
registry.add("spring.datasource.password", container::getPassword);
registry.add("spring.datasource.username", container::getUsername);
registry.add("spring.datasource.driver-class-name", container::getDriverClassName);
}
@Autowired
private JdbcTemplate jdbcTemplate;
// @Test
public void testSimple() throws SQLException {
assertEquals(jdbcTemplate.queryForObject("SELECT 1 FROM dual", Long.class), Long.valueOf(1L));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment