11package org.ktorm.support.oracle
22
3+ import org.junit.ClassRule
34import org.ktorm.BaseTest
45import org.ktorm.database.Database
56import org.testcontainers.containers.OracleContainer
6- import java.sql.Connection
7- import java.sql.DriverManager
8- import kotlin.concurrent.thread
97
108abstract class BaseOracleTest : BaseTest () {
119
1210 override fun init () {
13- database = Database .connect(alwaysQuoteIdentifiers = true ) {
14- object : Connection by connection {
15- override fun close () {
16- // do nothing...
17- }
18- }
19- }
11+ database = Database .connect(
12+ url = container.jdbcUrl,
13+ driver = container.driverClassName,
14+ user = container.username,
15+ password = container.password,
16+ alwaysQuoteIdentifiers = true
17+ )
2018
2119 execSqlScript(" init-oracle-data.sql" )
2220 }
@@ -25,28 +23,11 @@ abstract class BaseOracleTest : BaseTest() {
2523 execSqlScript(" drop-oracle-data.sql" )
2624 }
2725
28- companion object : OracleContainer ( " zerda/oracle-database:11.2.0.2-xe " ) {
29- lateinit var connection : Connection
30-
31- init {
26+ companion object {
27+ @JvmField
28+ @ClassRule
29+ val container = OracleContainer ( " zerda/oracle-database:11.2.0.2-xe " )
3230 // At least 1 GB memory is required by Oracle.
33- withCreateContainerCmdModifier { cmd -> cmd.hostConfig?.withShmSize((1 * 1024 * 1024 * 1024 ).toLong()) }
34- // Start the container when it's first used.
35- start()
36- // Stop the container when the process exits.
37- Runtime .getRuntime().addShutdownHook(thread(start = false ) { stop() })
38- }
39-
40- override fun start () {
41- super .start()
42-
43- Class .forName(driverClassName)
44- connection = DriverManager .getConnection(jdbcUrl, username, password)
45- }
46-
47- override fun stop () {
48- connection.close()
49- super .stop()
50- }
31+ .withCreateContainerCmdModifier { cmd -> cmd.hostConfig?.withShmSize((1 * 1024 * 1024 * 1024 ).toLong()) }
5132 }
5233}
0 commit comments