Add kodein separations
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
package services
|
||||
|
||||
import be.vandewalleh.mainModule
|
||||
import be.vandewalleh.migrations.Migration
|
||||
import be.vandewalleh.services.NotesService
|
||||
import be.vandewalleh.services.UserService
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import me.liuwj.ktorm.database.*
|
||||
import org.amshove.kluent.*
|
||||
import org.junit.jupiter.api.*
|
||||
import org.kodein.di.Kodein
|
||||
import org.kodein.di.generic.bind
|
||||
import org.kodein.di.generic.instance
|
||||
import org.kodein.di.generic.singleton
|
||||
import org.testcontainers.containers.MariaDBContainer
|
||||
import utils.KMariadbContainer
|
||||
import utils.testContainerDataSource
|
||||
import javax.sql.DataSource
|
||||
|
||||
|
||||
@@ -20,28 +18,11 @@ import javax.sql.DataSource
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
|
||||
class UserServiceTest {
|
||||
|
||||
class KMariadbContainer : MariaDBContainer<KMariadbContainer>()
|
||||
|
||||
private val mariadb = KMariadbContainer().apply {
|
||||
this.start()
|
||||
}
|
||||
|
||||
private val hikariConfig = HikariConfig().apply {
|
||||
jdbcUrl = mariadb.jdbcUrl
|
||||
username = mariadb.username
|
||||
password = mariadb.password
|
||||
}
|
||||
|
||||
private val dataSource = HikariDataSource(hikariConfig)
|
||||
|
||||
private val db = Database.Companion.connect(dataSource)
|
||||
private val mariadb = KMariadbContainer().apply { start() }
|
||||
|
||||
private val kodein = Kodein {
|
||||
bind<DataSource>() with singleton { dataSource }
|
||||
bind<Database>() with singleton { db }
|
||||
bind<Migration>() with singleton { Migration(this.kodein) }
|
||||
bind<UserService>() with singleton { UserService(this.kodein) }
|
||||
bind<NotesService>() with singleton { NotesService(this.kodein) }
|
||||
import(mainModule, allowOverride = true)
|
||||
bind<DataSource>(overrides = true) with singleton { testContainerDataSource(mariadb) }
|
||||
}
|
||||
|
||||
private val migration by kodein.instance<Migration>()
|
||||
|
||||
Reference in New Issue
Block a user