-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomCodecTest.kt
39 lines (31 loc) · 1.23 KB
/
CustomCodecTest.kt
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
import com.lotto.database.CurrencyCodec
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import org.junit.platform.commons.logging.LoggerFactory
import org.litote.kmongo.coroutine.coroutine
import org.litote.kmongo.coroutine.updateOne
import org.litote.kmongo.reactivestreams.KMongo
import org.litote.kmongo.util.ObjectMappingConfiguration
import java.util.*
class CustomCodecTest {
private val logger = LoggerFactory.getLogger(CustomCodecTest::class.java)
@Test
fun testCustomCodec() = runBlocking {
ObjectMappingConfiguration.customCodecProviders.add(CurrencyCodec())
val coroutineClient = KMongo.createClient().coroutine
val database = coroutineClient.getDatabase("test")
val account = Account(currency = Currency.getInstance("USD"))
val collection = database.getCollection<Account>()
logger.info { "Saving" }
collection.insertOne(account)
logger.info { "finding" }
assert(collection.findOneById(account.id)?.currency == Currency.getInstance("USD"))
logger.info { "Updating" }
collection.updateOne(
account.copy(
currency = Currency.getInstance("EUR")
)
)
Unit
}
}