diff --git a/lib/stove-testing-e2e-mongodb/build.gradle.kts b/lib/stove-testing-e2e-mongodb/build.gradle.kts index 78e69c553..59765fea4 100644 --- a/lib/stove-testing-e2e-mongodb/build.gradle.kts +++ b/lib/stove-testing-e2e-mongodb/build.gradle.kts @@ -1,9 +1,6 @@ dependencies { api(projects.lib.stoveTestingE2e) api(libs.testcontainers.mongodb) - api(libs.mongojack) { - exclude(group = "org.mongodb", module = "mongodb-driver-sync") - } implementation(libs.mongodb.kotlin.coroutine) implementation(libs.kotlinx.io.reactor.extensions) implementation(libs.kotlinx.reactive) diff --git a/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystem.kt b/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystem.kt index eebaa8a22..35408f49d 100644 --- a/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystem.kt +++ b/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystem.kt @@ -10,8 +10,6 @@ import com.trendyol.stove.testing.e2e.system.abstractions.* import kotlinx.coroutines.flow.* import kotlinx.coroutines.runBlocking import org.bson.* -import org.bson.codecs.EncoderContext -import org.bson.codecs.configuration.CodecRegistry import org.bson.conversions.Bson import org.bson.types.ObjectId import org.slf4j.* @@ -53,7 +51,7 @@ class MongodbSystem internal constructor( ): MongodbSystem = mongoClient .getDatabase(context.options.databaseOptions.default.name) .getCollection(collection) - .withDocumentClass(T::class.java) + .withDocumentClass() .find(BsonDocument.parse(query)) .toList() .also(assertion) @@ -81,16 +79,15 @@ class MongodbSystem internal constructor( instance: T, objectId: String = ObjectId().toHexString(), collection: String = context.options.databaseOptions.default.collection, - codecRegistry: CodecRegistry = context.options.codecRegistry ): MongodbSystem = mongoClient .getDatabase(context.options.databaseOptions.default.name) .getCollection(collection) .also { coll -> - val bson = BsonDocument() - codecRegistry.get(T::class.java) - .encode(BsonDocumentWriter(bson), instance, EncoderContext.builder().build()) - val doc = Document(bson).append(RESERVED_ID, ObjectId(objectId)) - coll.insertOne(doc) + context.options.serde.serialize(instance) + .let { BsonDocument.parse(it) } + .let { doc -> Document(doc) } + .append(RESERVED_ID, ObjectId(objectId)) + .let { coll.insertOne(it) } } .let { this } @@ -152,7 +149,9 @@ class MongodbSystem internal constructor( .retryWrites(true) .readConcern(ReadConcern.MAJORITY) .writeConcern(WriteConcern.MAJORITY) - .build().let { MongoClient.create(it) } + .apply(context.options.configureClient) + .build() + .let { MongoClient.create(it) } companion object { const val RESERVED_ID = "_id" diff --git a/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystemOptions.kt b/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystemOptions.kt index f3f9e30b8..22d9f5d8f 100644 --- a/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystemOptions.kt +++ b/lib/stove-testing-e2e-mongodb/src/main/kotlin/com/trendyol/stove/testing/e2e/mongodb/MongodbSystemOptions.kt @@ -1,22 +1,17 @@ package com.trendyol.stove.testing.e2e.mongodb +import com.mongodb.MongoClientSettings import com.trendyol.stove.testing.e2e.serialization.StoveSerde import com.trendyol.stove.testing.e2e.system.abstractions.* import com.trendyol.stove.testing.e2e.system.annotations.StoveDsl -import org.bson.UuidRepresentation -import org.bson.codecs.configuration.CodecRegistry -import org.bson.codecs.pojo.PojoCodecProvider -import org.bson.internal.ProvidersCodecRegistry -import org.mongojack.JacksonCodecRegistry @StoveDsl data class MongodbSystemOptions( val databaseOptions: DatabaseOptions = DatabaseOptions(), val container: MongoContainerOptions = MongoContainerOptions(), - val codecRegistry: CodecRegistry = JacksonCodecRegistry( - StoveSerde.jackson.byConfiguring { addModule(ObjectIdModule()) }, - ProvidersCodecRegistry(listOf(PojoCodecProvider.builder().automatic(true).build())), - UuidRepresentation.STANDARD + val configureClient: (MongoClientSettings.Builder) -> Unit = { }, + val serde: StoveSerde = StoveSerde.jackson.anyJsonStringSerde( + StoveSerde.jackson.byConfiguring { addModule(ObjectIdModule()) } ), override val configureExposedConfiguration: (MongodbExposedConfiguration) -> List ) : SystemOptions, ConfiguresExposedConfiguration