Skip to content

Commit

Permalink
MongoBotContextManagerTest embedded mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
morfeusys committed Jan 27, 2021
1 parent 6234e41 commit df77e5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions managers/mongo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
api("com.fasterxml.jackson.module:jackson-module-kotlin" version {jackson})

testImplementation("org.junit.jupiter:junit-jupiter-api" version {jUnit})
testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo:3.0.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine" version {jUnit})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,44 @@ import com.justai.jaicf.api.EventBotRequest
import com.justai.jaicf.context.BotContext
import com.justai.jaicf.context.manager.mongo.MongoBotContextManager
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.Disabled
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.TestInstance

@Disabled
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MongoBotContextManagerTest {

private val client = MongoClients.create("mongodb://test:[email protected]:25385/jaicf")
private val manager = MongoBotContextManager(client.getDatabase("jaicf").getCollection("contexts"))
private lateinit var mongo: MongodExecutable
private lateinit var manager: MongoBotContextManager

@BeforeAll
internal 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
internal fun shutdown() {
mongo.stop()
}

@Test
fun testSave() {
Expand Down

0 comments on commit df77e5d

Please sign in to comment.