-
Notifications
You must be signed in to change notification settings - Fork 37
/
MongoBotContextManagerTest.kt
63 lines (53 loc) · 2.26 KB
/
MongoBotContextManagerTest.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.justai.jaicf.context.manager.test
import com.justai.jaicf.api.EventBotRequest
import com.justai.jaicf.context.BotContext
import com.justai.jaicf.context.RequestContext
import com.justai.jaicf.context.manager.BotContextManager
import com.justai.jaicf.context.manager.mongo.MongoBotContextManager
import com.justai.jaicf.core.test.managers.BotContextManagerBaseTest
import com.mongodb.client.MongoClients
import de.flapdoodle.embed.mongo.MongodExecutable
import de.flapdoodle.embed.mongo.MongodStarter
import de.flapdoodle.embed.mongo.config.MongodConfig
import de.flapdoodle.embed.mongo.config.Net
import de.flapdoodle.embed.mongo.distribution.Version
import de.flapdoodle.embed.process.runtime.Network
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
@EnabledIfEnvironmentVariable(named = "CI", matches = "true")
class MongoBotContextManagerTestWithExternalDatabase : BotContextManagerBaseTest() {
override lateinit var manager: BotContextManager
@BeforeAll
fun setup() {
val url = System.getenv("MONGO_URL")
val client = MongoClients.create(url)
manager = MongoBotContextManager(client.getDatabase("jaicf").getCollection("contexts"))
}
}
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
class MongoBotContextManagerTestWithEmbeddedMongo : BotContextManagerBaseTest() {
override lateinit var manager: BotContextManager
private lateinit var mongo: MongodExecutable
@BeforeAll
fun setup() {
val port = Network.getFreeServerPort()
MongodConfig.builder()
.version(Version.Main.PRODUCTION)
.net(Net(port, false))
.build().let { config ->
mongo = MongodStarter.getDefaultInstance().prepare(config)
mongo.start()
}
val client = MongoClients.create("mongodb://localhost:$port")
manager = MongoBotContextManager(client.getDatabase("jaicf").getCollection("contexts"))
}
@AfterAll
fun shutdown() {
mongo.stop()
}
}