72 lines
1.8 KiB
Kotlin
72 lines
1.8 KiB
Kotlin
package integration.services
|
|
|
|
import be.vandewalleh.mainModule
|
|
import be.vandewalleh.migrations.Migration
|
|
import be.vandewalleh.services.UserService
|
|
import kotlinx.coroutines.runBlocking
|
|
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 utils.KMariadbContainer
|
|
import utils.testContainerDataSource
|
|
import javax.sql.DataSource
|
|
|
|
|
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
|
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
|
|
class UserServiceTest {
|
|
|
|
private val mariadb = KMariadbContainer().apply { start() }
|
|
|
|
private val kodein = Kodein {
|
|
import(mainModule, allowOverride = true)
|
|
bind<DataSource>(overrides = true) with singleton { testContainerDataSource(mariadb) }
|
|
}
|
|
|
|
private val migration by kodein.instance<Migration>()
|
|
|
|
init {
|
|
migration.migrate()
|
|
}
|
|
|
|
private val userService by kodein.instance<UserService>()
|
|
|
|
@Test
|
|
@Order(1)
|
|
fun `test create user`() {
|
|
runBlocking {
|
|
val username = "hubert"
|
|
val password = "password"
|
|
|
|
userService.create(username, password)
|
|
val user = userService.find(username)
|
|
user `should not be` null
|
|
user?.username `should be equal to` username
|
|
}
|
|
}
|
|
|
|
@Test
|
|
@Order(2)
|
|
fun `test create same user`() {
|
|
runBlocking {
|
|
userService.create(username = "hubert", password = "password") `should be` null
|
|
}
|
|
}
|
|
|
|
@Test
|
|
@Order(3)
|
|
fun `test delete user`() {
|
|
runBlocking {
|
|
val id = userService.find("hubert")!!.id
|
|
userService.delete(id)
|
|
|
|
userService.find("hubert") `should be` null
|
|
userService.find(id) `should be` null
|
|
}
|
|
}
|
|
|
|
}
|