/
DBTest.scala
40 lines (32 loc) · 1.01 KB
/
DBTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.typesafe.slick.testkit.util
import slick.dbio.DBIO
import scala.collection.JavaConverters._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import org.junit.{After, Before}
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters
@RunWith(classOf[Parameterized])
abstract class DBTest {
private[this] var dbInitialized = false
val tdb: JdbcTestDB
lazy val db = {
dbInitialized = true
tdb.createDB()
}
println("[Using test database "+tdb+"]")
def runBlocking[T](a: DBIO[T]): Unit = Await.result(db.run(a), Duration.Inf)
@Before def beforeDBTest = tdb.cleanUpBefore()
@After def afterDBTest = {
if(dbInitialized) db.close()
tdb.cleanUpAfter()
}
}
abstract class DBTestObject(dbs: TestDB*) {
val testClassName = {
val s = getClass.getName
s.substring(0, s.length-1)
}
@Parameters def parameters: java.util.List[Array[TestDB]] = dbs.filter(_.isEnabled).map(to => Array(to)).asJava
}