com.trendyol.stove.testing.e2e.couchbase.ClusterExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stove-testing-e2e-couchbase Show documentation
Show all versions of stove-testing-e2e-couchbase Show documentation
The easiest way of e2e testing in Kotlin
package com.trendyol.stove.testing.e2e.couchbase
import com.couchbase.client.java.ReactiveCluster
import com.couchbase.client.java.json.JsonObject
import com.couchbase.client.java.query.QueryOptions
import com.couchbase.client.java.query.QueryProfile
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.reactive.asFlow
object ClusterExtensions {
fun QueryOptions.withParams(vararg params: Pair): QueryOptions {
val jObject = JsonObject.create()
params.forEach { jObject.put(it.first, it.second) }
this.parameters(jObject)
return this
}
suspend inline fun ReactiveCluster.executeQueryAs(
query: String,
queryOptionsConfigurer: (QueryOptions) -> Unit = {}
): List {
val options = createDefaultQueryOptions()
queryOptionsConfigurer(options)
return this.query(query, options).flatMapMany { it.rowsAs(T::class.java) }.asFlow().toList()
}
fun createDefaultQueryOptions(): QueryOptions {
return QueryOptions.queryOptions().profile(QueryProfile.OFF).readonly(true)
}
}