Browse Source

DATAMONGO-1689 - Polishing.

Additionally format code, update license header, update JavaDoc and add issue reference to tests.

Original pull request: #463.
pull/468/head
Christoph Strobl 9 years ago committed by Oliver Gierke
parent
commit
7ed48f5e76
  1. 154
      spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensions.kt
  2. 118
      spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ReactiveMongoOperationsExtensions.kt
  3. 258
      spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensionsTests.kt
  4. 205
      spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveMongoOperationsExtensionsTests.kt

154
spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensions.kt

@ -38,7 +38,7 @@ import kotlin.reflect.KClass
* Extension for [MongoOperations.getCollectionName] providing a [KClass] based variant. * Extension for [MongoOperations.getCollectionName] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.getCollectionName(entityClass: KClass<T>): String = fun <T : Any> MongoOperations.getCollectionName(entityClass: KClass<T>): String =
getCollectionName(entityClass.java) getCollectionName(entityClass.java)
@ -48,7 +48,7 @@ fun <T : Any> MongoOperations.getCollectionName(entityClass: KClass<T>): String
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.getCollectionName(): String = inline fun <reified T : Any> MongoOperations.getCollectionName(): String =
getCollectionName(T::class.java) getCollectionName(T::class.java)
@ -58,7 +58,7 @@ inline fun <reified T : Any> MongoOperations.getCollectionName(): String =
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.execute(action: CollectionCallback<T>): T = inline fun <reified T : Any> MongoOperations.execute(action: CollectionCallback<T>): T =
execute(T::class.java, action) execute(T::class.java, action)
@ -68,7 +68,7 @@ inline fun <reified T : Any> MongoOperations.execute(action: CollectionCallback<
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.stream(query: Query): CloseableIterator<T> = inline fun <reified T : Any> MongoOperations.stream(query: Query): CloseableIterator<T> =
stream(query, T::class.java) stream(query, T::class.java)
@ -78,10 +78,9 @@ inline fun <reified T : Any> MongoOperations.stream(query: Query): CloseableIter
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.stream(query: Query, inline fun <reified T : Any> MongoOperations.stream(query: Query, collectionName: String? = null): CloseableIterator<T> =
collectionName: String? = null): CloseableIterator<T> =
if (collectionName != null) stream(query, T::class.java, collectionName) if (collectionName != null) stream(query, T::class.java, collectionName)
else stream(query, T::class.java) else stream(query, T::class.java)
@ -89,10 +88,9 @@ inline fun <reified T : Any> MongoOperations.stream(query: Query,
* Extension for [MongoOperations.createCollection] providing a [KClass] based variant. * Extension for [MongoOperations.createCollection] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.createCollection(entityClass: KClass<T>, fun <T : Any> MongoOperations.createCollection(entityClass: KClass<T>, collectionOptions: CollectionOptions? = null): MongoCollection<Document> =
collectionOptions: CollectionOptions? = null): MongoCollection<Document> =
if (collectionOptions != null) createCollection(entityClass.java, collectionOptions) if (collectionOptions != null) createCollection(entityClass.java, collectionOptions)
else createCollection(entityClass.java) else createCollection(entityClass.java)
@ -101,7 +99,7 @@ fun <T : Any> MongoOperations.createCollection(entityClass: KClass<T>,
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.createCollection( inline fun <reified T : Any> MongoOperations.createCollection(
collectionOptions: CollectionOptions? = null): MongoCollection<Document> = collectionOptions: CollectionOptions? = null): MongoCollection<Document> =
@ -112,7 +110,7 @@ inline fun <reified T : Any> MongoOperations.createCollection(
* Extension for [MongoOperations.collectionExists] providing a [KClass] based variant. * Extension for [MongoOperations.collectionExists] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.collectionExists(entityClass: KClass<T>): Boolean = fun <T : Any> MongoOperations.collectionExists(entityClass: KClass<T>): Boolean =
collectionExists(entityClass.java) collectionExists(entityClass.java)
@ -122,7 +120,7 @@ fun <T : Any> MongoOperations.collectionExists(entityClass: KClass<T>): Boolean
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.collectionExists(): Boolean = inline fun <reified T : Any> MongoOperations.collectionExists(): Boolean =
collectionExists(T::class.java) collectionExists(T::class.java)
@ -131,7 +129,7 @@ inline fun <reified T : Any> MongoOperations.collectionExists(): Boolean =
* Extension for [MongoOperations.dropCollection] providing a [KClass] based variant. * Extension for [MongoOperations.dropCollection] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.dropCollection(entityClass: KClass<T>) { fun <T : Any> MongoOperations.dropCollection(entityClass: KClass<T>) {
dropCollection(entityClass.java) dropCollection(entityClass.java)
@ -142,7 +140,7 @@ fun <T : Any> MongoOperations.dropCollection(entityClass: KClass<T>) {
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.dropCollection() { inline fun <reified T : Any> MongoOperations.dropCollection() {
dropCollection(T::class.java) dropCollection(T::class.java)
@ -152,7 +150,7 @@ inline fun <reified T : Any> MongoOperations.dropCollection() {
* Extension for [MongoOperations.indexOps] providing a [KClass] based variant. * Extension for [MongoOperations.indexOps] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.indexOps(entityClass: KClass<T>): IndexOperations = fun <T : Any> MongoOperations.indexOps(entityClass: KClass<T>): IndexOperations =
indexOps(entityClass.java) indexOps(entityClass.java)
@ -162,7 +160,7 @@ fun <T : Any> MongoOperations.indexOps(entityClass: KClass<T>): IndexOperations
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.indexOps(): IndexOperations = inline fun <reified T : Any> MongoOperations.indexOps(): IndexOperations =
indexOps(T::class.java) indexOps(T::class.java)
@ -171,10 +169,9 @@ inline fun <reified T : Any> MongoOperations.indexOps(): IndexOperations =
* Extension for [MongoOperations.bulkOps] providing a [KClass] based variant. * Extension for [MongoOperations.bulkOps] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.bulkOps(bulkMode: BulkMode, entityClass: KClass<T>, fun <T : Any> MongoOperations.bulkOps(bulkMode: BulkMode, entityClass: KClass<T>, collectionName: String? = null): BulkOperations =
collectionName: String? = null): BulkOperations =
if (collectionName != null) bulkOps(bulkMode, entityClass.java, collectionName) if (collectionName != null) bulkOps(bulkMode, entityClass.java, collectionName)
else bulkOps(bulkMode, entityClass.java) else bulkOps(bulkMode, entityClass.java)
@ -182,11 +179,10 @@ fun <T : Any> MongoOperations.bulkOps(bulkMode: BulkMode, entityClass: KClass<T>
* Extension for [MongoOperations.bulkOps] providing a [KClass] based variant. * Extension for [MongoOperations.bulkOps] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> MongoOperations.bulkOps(bulkMode: BulkMode, inline fun <reified T : Any> MongoOperations.bulkOps(bulkMode: BulkMode, collectionName: String? = null): BulkOperations =
collectionName: String? = null): BulkOperations =
if (collectionName != null) bulkOps(bulkMode, T::class.java, collectionName) if (collectionName != null) bulkOps(bulkMode, T::class.java, collectionName)
else bulkOps(bulkMode, T::class.java) else bulkOps(bulkMode, T::class.java)
@ -195,7 +191,7 @@ inline fun <reified T : Any> MongoOperations.bulkOps(bulkMode: BulkMode,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.findAll(collectionName: String? = null): List<T> = inline fun <reified T : Any> MongoOperations.findAll(collectionName: String? = null): List<T> =
if (collectionName != null) findAll(T::class.java, collectionName) else findAll(T::class.java) if (collectionName != null) findAll(T::class.java, collectionName) else findAll(T::class.java)
@ -205,7 +201,7 @@ inline fun <reified T : Any> MongoOperations.findAll(collectionName: String? = n
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.group(inputCollectionName: String, groupBy: GroupBy): GroupByResults<T> = inline fun <reified T : Any> MongoOperations.group(inputCollectionName: String, groupBy: GroupBy): GroupByResults<T> =
group(inputCollectionName, groupBy, T::class.java) group(inputCollectionName, groupBy, T::class.java)
@ -215,10 +211,9 @@ inline fun <reified T : Any> MongoOperations.group(inputCollectionName: String,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.group(criteria: Criteria, inline fun <reified T : Any> MongoOperations.group(criteria: Criteria, inputCollectionName: String, groupBy: GroupBy): GroupByResults<T> =
inputCollectionName: String, groupBy: GroupBy): GroupByResults<T> =
group(criteria, inputCollectionName, groupBy, T::class.java) group(criteria, inputCollectionName, groupBy, T::class.java)
/** /**
@ -226,10 +221,9 @@ inline fun <reified T : Any> MongoOperations.group(criteria: Criteria,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified O : Any> MongoOperations.aggregate(aggregation: Aggregation, inline fun <reified O : Any> MongoOperations.aggregate(aggregation: Aggregation, inputType: KClass<*>): AggregationResults<O> =
inputType: KClass<*>): AggregationResults<O> =
aggregate(aggregation, inputType.java, O::class.java) aggregate(aggregation, inputType.java, O::class.java)
/** /**
@ -237,10 +231,9 @@ inline fun <reified O : Any> MongoOperations.aggregate(aggregation: Aggregation,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified O : Any> MongoOperations.aggregate(aggregation: Aggregation, inline fun <reified O : Any> MongoOperations.aggregate(aggregation: Aggregation, collectionName: String): AggregationResults<O> =
collectionName: String): AggregationResults<O> =
aggregate(aggregation, collectionName, O::class.java) aggregate(aggregation, collectionName, O::class.java)
/** /**
@ -248,10 +241,9 @@ inline fun <reified O : Any> MongoOperations.aggregate(aggregation: Aggregation,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified O : Any> MongoOperations.aggregateStream(aggregation: Aggregation, inline fun <reified O : Any> MongoOperations.aggregateStream(aggregation: Aggregation, inputType: KClass<*>): CloseableIterator<O> =
inputType: KClass<*>): CloseableIterator<O> =
aggregateStream(aggregation, inputType.java, O::class.java) aggregateStream(aggregation, inputType.java, O::class.java)
/** /**
@ -259,10 +251,9 @@ inline fun <reified O : Any> MongoOperations.aggregateStream(aggregation: Aggreg
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified O : Any> MongoOperations.aggregateStream(aggregation: Aggregation, inline fun <reified O : Any> MongoOperations.aggregateStream(aggregation: Aggregation, collectionName: String): CloseableIterator<O> =
collectionName: String): CloseableIterator<O> =
aggregateStream(aggregation, collectionName, O::class.java) aggregateStream(aggregation, collectionName, O::class.java)
/** /**
@ -270,10 +261,9 @@ inline fun <reified O : Any> MongoOperations.aggregateStream(aggregation: Aggreg
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.mapReduce(collectionName: String, inline fun <reified T : Any> MongoOperations.mapReduce(collectionName: String, mapFunction: String, reduceFunction: String, options: MapReduceOptions? = null): MapReduceResults<T> =
mapFunction: String, reduceFunction: String, options: MapReduceOptions? = null): MapReduceResults<T> =
if (options != null) mapReduce(collectionName, mapFunction, reduceFunction, options, T::class.java) if (options != null) mapReduce(collectionName, mapFunction, reduceFunction, options, T::class.java)
else mapReduce(collectionName, mapFunction, reduceFunction, T::class.java) else mapReduce(collectionName, mapFunction, reduceFunction, T::class.java)
@ -282,10 +272,9 @@ inline fun <reified T : Any> MongoOperations.mapReduce(collectionName: String,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 52.0
*/ */
inline fun <reified T : Any> MongoOperations.mapReduce(query: Query, collectionName: String, inline fun <reified T : Any> MongoOperations.mapReduce(query: Query, collectionName: String, mapFunction: String, reduceFunction: String, options: MapReduceOptions? = null): MapReduceResults<T> =
mapFunction: String, reduceFunction: String, options: MapReduceOptions? = null): MapReduceResults<T> =
if (options != null) mapReduce(query, collectionName, mapFunction, reduceFunction, options, T::class.java) if (options != null) mapReduce(query, collectionName, mapFunction, reduceFunction, options, T::class.java)
else mapReduce(query, collectionName, mapFunction, reduceFunction, T::class.java) else mapReduce(query, collectionName, mapFunction, reduceFunction, T::class.java)
@ -294,10 +283,9 @@ inline fun <reified T : Any> MongoOperations.mapReduce(query: Query, collectionN
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.geoNear(near: NearQuery, inline fun <reified T : Any> MongoOperations.geoNear(near: NearQuery, collectionName: String? = null): GeoResults<T> =
collectionName: String? = null): GeoResults<T> =
if (collectionName != null) geoNear(near, T::class.java, collectionName) if (collectionName != null) geoNear(near, T::class.java, collectionName)
else geoNear(near, T::class.java) else geoNear(near, T::class.java)
@ -306,7 +294,7 @@ inline fun <reified T : Any> MongoOperations.geoNear(near: NearQuery,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.findOne(query: Query, collectionName: String? = null): T = inline fun <reified T : Any> MongoOperations.findOne(query: Query, collectionName: String? = null): T =
if (collectionName != null) findOne(query, T::class.java, collectionName) else findOne(query, T::class.java) if (collectionName != null) findOne(query, T::class.java, collectionName) else findOne(query, T::class.java)
@ -316,10 +304,9 @@ inline fun <reified T : Any> MongoOperations.findOne(query: Query, collectionNam
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.exists(query: Query, entityClass: KClass<T>, fun <T : Any> MongoOperations.exists(query: Query, entityClass: KClass<T>, collectionName: String? = null): Boolean =
collectionName: String? = null): Boolean =
if (collectionName != null) exists(query, entityClass.java, collectionName) if (collectionName != null) exists(query, entityClass.java, collectionName)
else exists(query, entityClass.java) else exists(query, entityClass.java)
@ -328,7 +315,7 @@ fun <T : Any> MongoOperations.exists(query: Query, entityClass: KClass<T>,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> MongoOperations.exists(query: Query, collectionName: String? = null): Boolean = inline fun <reified T : Any> MongoOperations.exists(query: Query, collectionName: String? = null): Boolean =
@ -340,7 +327,7 @@ inline fun <reified T : Any> MongoOperations.exists(query: Query, collectionName
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.find(query: Query, collectionName: String? = null): List<T> = inline fun <reified T : Any> MongoOperations.find(query: Query, collectionName: String? = null): List<T> =
if (collectionName != null) find(query, T::class.java, collectionName) if (collectionName != null) find(query, T::class.java, collectionName)
@ -351,7 +338,7 @@ inline fun <reified T : Any> MongoOperations.find(query: Query, collectionName:
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.findById(id: Any, collectionName: String? = null): T = inline fun <reified T : Any> MongoOperations.findById(id: Any, collectionName: String? = null): T =
if (collectionName != null) findById(id, T::class.java, collectionName) if (collectionName != null) findById(id, T::class.java, collectionName)
@ -362,10 +349,9 @@ inline fun <reified T : Any> MongoOperations.findById(id: Any, collectionName: S
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.findAndModify(query: Query, update: Update, inline fun <reified T : Any> MongoOperations.findAndModify(query: Query, update: Update, options: FindAndModifyOptions, collectionName: String? = null): T =
options: FindAndModifyOptions, collectionName: String? = null): T =
if (collectionName != null) findAndModify(query, update, options, T::class.java, collectionName) if (collectionName != null) findAndModify(query, update, options, T::class.java, collectionName)
else findAndModify(query, update, options, T::class.java) else findAndModify(query, update, options, T::class.java)
@ -374,7 +360,7 @@ inline fun <reified T : Any> MongoOperations.findAndModify(query: Query, update:
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.findAndRemove(query: Query, collectionName: String? = null): T = inline fun <reified T : Any> MongoOperations.findAndRemove(query: Query, collectionName: String? = null): T =
if (collectionName != null) findAndRemove(query, T::class.java, collectionName) if (collectionName != null) findAndRemove(query, T::class.java, collectionName)
@ -385,10 +371,9 @@ inline fun <reified T : Any> MongoOperations.findAndRemove(query: Query, collect
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.count(query: Query = Query(), entityClass: KClass<T>, fun <T : Any> MongoOperations.count(query: Query = Query(), entityClass: KClass<T>, collectionName: String? = null): Long =
collectionName: String? = null): Long =
if (collectionName != null) count(query, entityClass.java, collectionName) if (collectionName != null) count(query, entityClass.java, collectionName)
else count(query, entityClass.java) else count(query, entityClass.java)
@ -397,7 +382,7 @@ fun <T : Any> MongoOperations.count(query: Query = Query(), entityClass: KClass<
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> MongoOperations.count(query: Query = Query(), collectionName: String? = null): Long = inline fun <reified T : Any> MongoOperations.count(query: Query = Query(), collectionName: String? = null): Long =
@ -407,7 +392,7 @@ inline fun <reified T : Any> MongoOperations.count(query: Query = Query(), colle
* Extension for [MongoOperations.insert] providing a [KClass] based variant. * Extension for [MongoOperations.insert] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.insert(batchToSave: Collection<T>, entityClass: KClass<T>) { fun <T : Any> MongoOperations.insert(batchToSave: Collection<T>, entityClass: KClass<T>) {
insert(batchToSave, entityClass.java) insert(batchToSave, entityClass.java)
@ -417,10 +402,9 @@ fun <T : Any> MongoOperations.insert(batchToSave: Collection<T>, entityClass: KC
* Extension for [MongoOperations.upsert] providing a [KClass] based variant. * Extension for [MongoOperations.upsert] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.upsert(query: Query, update: Update, entityClass: KClass<T>, fun <T : Any> MongoOperations.upsert(query: Query, update: Update, entityClass: KClass<T>, collectionName: String? = null): UpdateResult =
collectionName: String? = null): UpdateResult =
if (collectionName != null) upsert(query, update, entityClass.java, collectionName) if (collectionName != null) upsert(query, update, entityClass.java, collectionName)
else upsert(query, update, entityClass.java) else upsert(query, update, entityClass.java)
@ -429,11 +413,10 @@ fun <T : Any> MongoOperations.upsert(query: Query, update: Update, entityClass:
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> MongoOperations.upsert(query: Query, update: Update, inline fun <reified T : Any> MongoOperations.upsert(query: Query, update: Update, collectionName: String? = null): UpdateResult =
collectionName: String? = null): UpdateResult =
if (collectionName != null) upsert(query, update, T::class.java, collectionName) if (collectionName != null) upsert(query, update, T::class.java, collectionName)
else upsert(query, update, T::class.java) else upsert(query, update, T::class.java)
@ -441,10 +424,9 @@ inline fun <reified T : Any> MongoOperations.upsert(query: Query, update: Update
* Extension for [MongoOperations.updateFirst] providing a [KClass] based variant. * Extension for [MongoOperations.updateFirst] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.updateFirst(query: Query, update: Update, entityClass: KClass<T>, fun <T : Any> MongoOperations.updateFirst(query: Query, update: Update, entityClass: KClass<T>, collectionName: String? = null): UpdateResult =
collectionName: String? = null): UpdateResult =
if (collectionName != null) updateFirst(query, update, entityClass.java, collectionName) if (collectionName != null) updateFirst(query, update, entityClass.java, collectionName)
else updateFirst(query, update, entityClass.java) else updateFirst(query, update, entityClass.java)
@ -453,11 +435,10 @@ fun <T : Any> MongoOperations.updateFirst(query: Query, update: Update, entityCl
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> MongoOperations.updateFirst(query: Query, update: Update, inline fun <reified T : Any> MongoOperations.updateFirst(query: Query, update: Update, collectionName: String? = null): UpdateResult =
collectionName: String? = null): UpdateResult =
if (collectionName != null) updateFirst(query, update, T::class.java, collectionName) if (collectionName != null) updateFirst(query, update, T::class.java, collectionName)
else updateFirst(query, update, T::class.java) else updateFirst(query, update, T::class.java)
@ -466,10 +447,9 @@ inline fun <reified T : Any> MongoOperations.updateFirst(query: Query, update: U
* Extension for [MongoOperations.updateMulti] providing a [KClass] based variant. * Extension for [MongoOperations.updateMulti] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.updateMulti(query: Query, update: Update, entityClass: KClass<T>, fun <T : Any> MongoOperations.updateMulti(query: Query, update: Update, entityClass: KClass<T>, collectionName: String? = null): UpdateResult =
collectionName: String? = null): UpdateResult =
if (collectionName != null) updateMulti(query, update, entityClass.java, collectionName) if (collectionName != null) updateMulti(query, update, entityClass.java, collectionName)
else updateMulti(query, update, entityClass.java) else updateMulti(query, update, entityClass.java)
@ -478,11 +458,10 @@ fun <T : Any> MongoOperations.updateMulti(query: Query, update: Update, entityCl
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> MongoOperations.updateMulti(query: Query, update: Update, inline fun <reified T : Any> MongoOperations.updateMulti(query: Query, update: Update, collectionName: String? = null): UpdateResult =
collectionName: String? = null): UpdateResult =
if (collectionName != null) updateMulti(query, update, T::class.java, collectionName) if (collectionName != null) updateMulti(query, update, T::class.java, collectionName)
else updateMulti(query, update, T::class.java) else updateMulti(query, update, T::class.java)
@ -490,10 +469,9 @@ inline fun <reified T : Any> MongoOperations.updateMulti(query: Query, update: U
* Extension for [MongoOperations.remove] providing a [KClass] based variant. * Extension for [MongoOperations.remove] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> MongoOperations.remove(query: Query, entityClass: KClass<T>, fun <T : Any> MongoOperations.remove(query: Query, entityClass: KClass<T>, collectionName: String? = null): DeleteResult =
collectionName: String? = null): DeleteResult =
if (collectionName != null) remove(query, entityClass.java, collectionName) if (collectionName != null) remove(query, entityClass.java, collectionName)
else remove(query, entityClass.java) else remove(query, entityClass.java)
@ -502,7 +480,7 @@ fun <T : Any> MongoOperations.remove(query: Query, entityClass: KClass<T>,
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> MongoOperations.remove(query: Query, collectionName: String? = null): DeleteResult = inline fun <reified T : Any> MongoOperations.remove(query: Query, collectionName: String? = null): DeleteResult =
@ -514,7 +492,7 @@ inline fun <reified T : Any> MongoOperations.remove(query: Query, collectionName
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> MongoOperations.findAllAndRemove(query: Query): List<T> = inline fun <reified T : Any> MongoOperations.findAllAndRemove(query: Query): List<T> =
findAllAndRemove(query, T::class.java) findAllAndRemove(query, T::class.java)

118
spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ReactiveMongoOperationsExtensions.kt

@ -31,7 +31,7 @@ import kotlin.reflect.KClass
* Extension for [ReactiveMongoOperations.indexOps] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.indexOps] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.indexOps(entityClass: KClass<T>): ReactiveIndexOperations = fun <T : Any> ReactiveMongoOperations.indexOps(entityClass: KClass<T>): ReactiveIndexOperations =
indexOps(entityClass.java) indexOps(entityClass.java)
@ -41,7 +41,7 @@ fun <T : Any> ReactiveMongoOperations.indexOps(entityClass: KClass<T>): Reactive
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.indexOps(): ReactiveIndexOperations = inline fun <reified T : Any> ReactiveMongoOperations.indexOps(): ReactiveIndexOperations =
indexOps(T::class.java) indexOps(T::class.java)
@ -51,7 +51,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.indexOps(): ReactiveIndexOp
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.execute(action: ReactiveCollectionCallback<T>): Flux<T> = inline fun <reified T : Any> ReactiveMongoOperations.execute(action: ReactiveCollectionCallback<T>): Flux<T> =
execute(T::class.java, action) execute(T::class.java, action)
@ -60,10 +60,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.execute(action: ReactiveCol
* Extension for [ReactiveMongoOperations.createCollection] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.createCollection] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.createCollection(entityClass: KClass<T>, fun <T : Any> ReactiveMongoOperations.createCollection(entityClass: KClass<T>, collectionOptions: CollectionOptions? = null): Mono<MongoCollection<Document>> =
collectionOptions: CollectionOptions? = null): Mono<MongoCollection<Document>> =
if (collectionOptions != null) createCollection(entityClass.java, collectionOptions) else createCollection(entityClass.java) if (collectionOptions != null) createCollection(entityClass.java, collectionOptions) else createCollection(entityClass.java)
/** /**
@ -71,17 +70,16 @@ fun <T : Any> ReactiveMongoOperations.createCollection(entityClass: KClass<T>,
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.createCollection( inline fun <reified T : Any> ReactiveMongoOperations.createCollection(collectionOptions: CollectionOptions? = null): Mono<MongoCollection<Document>> =
collectionOptions: CollectionOptions? = null): Mono<MongoCollection<Document>> =
if (collectionOptions != null) createCollection(T::class.java, collectionOptions) else createCollection(T::class.java) if (collectionOptions != null) createCollection(T::class.java, collectionOptions) else createCollection(T::class.java)
/** /**
* Extension for [ReactiveMongoOperations.collectionExists] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.collectionExists] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.collectionExists(entityClass: KClass<T>): Mono<Boolean> = fun <T : Any> ReactiveMongoOperations.collectionExists(entityClass: KClass<T>): Mono<Boolean> =
collectionExists(entityClass.java) collectionExists(entityClass.java)
@ -91,7 +89,7 @@ fun <T : Any> ReactiveMongoOperations.collectionExists(entityClass: KClass<T>):
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.collectionExists(): Mono<Boolean> = inline fun <reified T : Any> ReactiveMongoOperations.collectionExists(): Mono<Boolean> =
collectionExists(T::class.java) collectionExists(T::class.java)
@ -100,7 +98,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.collectionExists(): Mono<Bo
* Extension for [ReactiveMongoOperations.dropCollection] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.dropCollection] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.dropCollection(entityClass: KClass<T>): Mono<Void> = fun <T : Any> ReactiveMongoOperations.dropCollection(entityClass: KClass<T>): Mono<Void> =
dropCollection(entityClass.java) dropCollection(entityClass.java)
@ -110,7 +108,7 @@ fun <T : Any> ReactiveMongoOperations.dropCollection(entityClass: KClass<T>): Mo
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.dropCollection(): Mono<Void> = inline fun <reified T : Any> ReactiveMongoOperations.dropCollection(): Mono<Void> =
dropCollection(T::class.java) dropCollection(T::class.java)
@ -121,7 +119,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.dropCollection(): Mono<Void
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.findAll(collectionName: String? = null): Flux<T> = inline fun <reified T : Any> ReactiveMongoOperations.findAll(collectionName: String? = null): Flux<T> =
if (collectionName != null) findAll(T::class.java, collectionName) else findAll(T::class.java) if (collectionName != null) findAll(T::class.java, collectionName) else findAll(T::class.java)
@ -131,7 +129,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.findAll(collectionName: Str
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.findOne(query: Query, collectionName: String? = null): Mono<T> = inline fun <reified T : Any> ReactiveMongoOperations.findOne(query: Query, collectionName: String? = null): Mono<T> =
if (collectionName != null) findOne(query, T::class.java, collectionName) else findOne(query, T::class.java) if (collectionName != null) findOne(query, T::class.java, collectionName) else findOne(query, T::class.java)
@ -141,10 +139,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.findOne(query: Query, colle
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.exists(query: Query, entityClass: KClass<T>, fun <T : Any> ReactiveMongoOperations.exists(query: Query, entityClass: KClass<T>, collectionName: String? = null): Mono<Boolean> =
collectionName: String? = null): Mono<Boolean> =
if (collectionName != null) exists(query, entityClass.java, collectionName) else exists(query, entityClass.java) if (collectionName != null) exists(query, entityClass.java, collectionName) else exists(query, entityClass.java)
/** /**
@ -152,11 +149,10 @@ fun <T : Any> ReactiveMongoOperations.exists(query: Query, entityClass: KClass<T
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> ReactiveMongoOperations.exists(query: Query, inline fun <reified T : Any> ReactiveMongoOperations.exists(query: Query, collectionName: String? = null): Mono<Boolean> =
collectionName: String? = null): Mono<Boolean> =
if (collectionName != null) exists(query, T::class.java, collectionName) else exists(query, T::class.java) if (collectionName != null) exists(query, T::class.java, collectionName) else exists(query, T::class.java)
/** /**
@ -164,7 +160,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.exists(query: Query,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.find(query: Query, collectionName: String? = null): Flux<T> = inline fun <reified T : Any> ReactiveMongoOperations.find(query: Query, collectionName: String? = null): Flux<T> =
if (collectionName != null) find(query, T::class.java, collectionName) else find(query, T::class.java) if (collectionName != null) find(query, T::class.java, collectionName) else find(query, T::class.java)
@ -174,7 +170,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.find(query: Query, collecti
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.findById(id: Any, collectionName: String? = null): Mono<T> = inline fun <reified T : Any> ReactiveMongoOperations.findById(id: Any, collectionName: String? = null): Mono<T> =
if (collectionName != null) findById(id, T::class.java, collectionName) else findById(id, T::class.java) if (collectionName != null) findById(id, T::class.java, collectionName) else findById(id, T::class.java)
@ -184,10 +180,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.findById(id: Any, collectio
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.geoNear(near: NearQuery, inline fun <reified T : Any> ReactiveMongoOperations.geoNear(near: NearQuery, collectionName: String? = null): Flux<GeoResult<T>> =
collectionName: String? = null): Flux<GeoResult<T>> =
if (collectionName != null) geoNear(near, T::class.java, collectionName) else geoNear(near, T::class.java) if (collectionName != null) geoNear(near, T::class.java, collectionName) else geoNear(near, T::class.java)
/** /**
@ -195,10 +190,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.geoNear(near: NearQuery,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.findAndModify(query: Query, inline fun <reified T : Any> ReactiveMongoOperations.findAndModify(query: Query, update: Update, options: FindAndModifyOptions, collectionName: String? = null): Mono<T> =
update: Update, options: FindAndModifyOptions, collectionName: String? = null): Mono<T> =
if (collectionName != null) findAndModify(query, update, options, T::class.java, collectionName) else findAndModify(query, update, options, T::class.java) if (collectionName != null) findAndModify(query, update, options, T::class.java, collectionName) else findAndModify(query, update, options, T::class.java)
/** /**
@ -206,10 +200,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.findAndModify(query: Query,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.findAndRemove(query: Query, inline fun <reified T : Any> ReactiveMongoOperations.findAndRemove(query: Query, collectionName: String? = null): Mono<T> =
collectionName: String? = null): Mono<T> =
if (collectionName != null) findAndRemove(query, T::class.java, collectionName) if (collectionName != null) findAndRemove(query, T::class.java, collectionName)
else findAndRemove(query, T::class.java) else findAndRemove(query, T::class.java)
@ -218,10 +211,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.findAndRemove(query: Query,
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.count(query: Query = Query(), entityClass: KClass<T>, fun <T : Any> ReactiveMongoOperations.count(query: Query = Query(), entityClass: KClass<T>, collectionName: String? = null): Mono<Long> =
collectionName: String? = null): Mono<Long> =
if (collectionName != null) count(query, entityClass.java, collectionName) if (collectionName != null) count(query, entityClass.java, collectionName)
else count(query, entityClass.java) else count(query, entityClass.java)
@ -230,11 +222,10 @@ fun <T : Any> ReactiveMongoOperations.count(query: Query = Query(), entityClass:
* thanks to Kotlin reified type parameters * thanks to Kotlin reified type parameters
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> ReactiveMongoOperations.count(query: Query = Query(), inline fun <reified T : Any> ReactiveMongoOperations.count(query: Query = Query(), collectionName: String? = null): Mono<Long> =
collectionName: String? = null): Mono<Long> =
if (collectionName != null) count(query, T::class.java, collectionName) if (collectionName != null) count(query, T::class.java, collectionName)
else count(query, T::class.java) else count(query, T::class.java)
@ -242,7 +233,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.count(query: Query = Query(
* Extension for [ReactiveMongoOperations.insert] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.insert] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.insert(batchToSave: Collection<T>, entityClass: KClass<T>): Flux<T> = fun <T : Any> ReactiveMongoOperations.insert(batchToSave: Collection<T>, entityClass: KClass<T>): Flux<T> =
insert(batchToSave, entityClass.java) insert(batchToSave, entityClass.java)
@ -251,20 +242,18 @@ fun <T : Any> ReactiveMongoOperations.insert(batchToSave: Collection<T>, entityC
* Extension for [ReactiveMongoOperations.insertAll] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.insertAll] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.insertAll(batchToSave: Mono<out Collection<T>>, fun <T : Any> ReactiveMongoOperations.insertAll(batchToSave: Mono<out Collection<T>>, entityClass: KClass<T>): Flux<T> =
entityClass: KClass<T>): Flux<T> =
insertAll(batchToSave, entityClass.java) insertAll(batchToSave, entityClass.java)
/** /**
* Extension for [ReactiveMongoOperations.upsert] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.upsert] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.upsert(query: Query, update: Update, entityClass: KClass<T>, fun <T : Any> ReactiveMongoOperations.upsert(query: Query, update: Update, entityClass: KClass<T>, collectionName: String? = null): Mono<UpdateResult> =
collectionName: String? = null): Mono<UpdateResult> =
if (collectionName != null) upsert(query, update, entityClass.java, collectionName) else upsert(query, update, entityClass.java) if (collectionName != null) upsert(query, update, entityClass.java, collectionName) else upsert(query, update, entityClass.java)
/** /**
@ -272,11 +261,10 @@ fun <T : Any> ReactiveMongoOperations.upsert(query: Query, update: Update, entit
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> ReactiveMongoOperations.upsert(query: Query, update: Update, inline fun <reified T : Any> ReactiveMongoOperations.upsert(query: Query, update: Update, collectionName: String? = null): Mono<UpdateResult> =
collectionName: String? = null): Mono<UpdateResult> =
if (collectionName != null) upsert(query, update, T::class.java, collectionName) if (collectionName != null) upsert(query, update, T::class.java, collectionName)
else upsert(query, update, T::class.java) else upsert(query, update, T::class.java)
@ -284,10 +272,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.upsert(query: Query, update
* Extension for [ReactiveMongoOperations.updateFirst] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.updateFirst] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.updateFirst(query: Query, update: Update, fun <T : Any> ReactiveMongoOperations.updateFirst(query: Query, update: Update, entityClass: KClass<T>, collectionName: String? = null): Mono<UpdateResult> =
entityClass: KClass<T>, collectionName: String? = null): Mono<UpdateResult> =
if (collectionName != null) updateFirst(query, update, entityClass.java, collectionName) if (collectionName != null) updateFirst(query, update, entityClass.java, collectionName)
else updateFirst(query, update, entityClass.java) else updateFirst(query, update, entityClass.java)
@ -296,11 +283,10 @@ fun <T : Any> ReactiveMongoOperations.updateFirst(query: Query, update: Update,
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> ReactiveMongoOperations.updateFirst(query: Query, update: Update, inline fun <reified T : Any> ReactiveMongoOperations.updateFirst(query: Query, update: Update, collectionName: String? = null): Mono<UpdateResult> =
collectionName: String? = null): Mono<UpdateResult> =
if (collectionName != null) updateFirst(query, update, T::class.java, collectionName) if (collectionName != null) updateFirst(query, update, T::class.java, collectionName)
else updateFirst(query, update, T::class.java) else updateFirst(query, update, T::class.java)
@ -308,10 +294,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.updateFirst(query: Query, u
* Extension for [ReactiveMongoOperations.updateMulti] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.updateMulti] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.updateMulti(query: Query, update: Update, fun <T : Any> ReactiveMongoOperations.updateMulti(query: Query, update: Update, entityClass: KClass<T>, collectionName: String? = null): Mono<UpdateResult> =
entityClass: KClass<T>, collectionName: String? = null): Mono<UpdateResult> =
if (collectionName != null) updateMulti(query, update, entityClass.java, collectionName) if (collectionName != null) updateMulti(query, update, entityClass.java, collectionName)
else updateMulti(query, update, entityClass.java) else updateMulti(query, update, entityClass.java)
@ -320,11 +305,10 @@ fun <T : Any> ReactiveMongoOperations.updateMulti(query: Query, update: Update,
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> ReactiveMongoOperations.updateMulti(query: Query, update: Update, inline fun <reified T : Any> ReactiveMongoOperations.updateMulti(query: Query, update: Update, collectionName: String? = null): Mono<UpdateResult> =
collectionName: String? = null): Mono<UpdateResult> =
if (collectionName != null) updateMulti(query, update, T::class.java, collectionName) if (collectionName != null) updateMulti(query, update, T::class.java, collectionName)
else updateMulti(query, update, T::class.java) else updateMulti(query, update, T::class.java)
@ -332,10 +316,9 @@ inline fun <reified T : Any> ReactiveMongoOperations.updateMulti(query: Query, u
* Extension for [ReactiveMongoOperations.remove] providing a [KClass] based variant. * Extension for [ReactiveMongoOperations.remove] providing a [KClass] based variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
fun <T : Any> ReactiveMongoOperations.remove(query: Query, entityClass: KClass<T>, fun <T : Any> ReactiveMongoOperations.remove(query: Query, entityClass: KClass<T>, collectionName: String? = null): Mono<DeleteResult> =
collectionName: String? = null): Mono<DeleteResult> =
if (collectionName != null) remove(query, entityClass.java, collectionName) if (collectionName != null) remove(query, entityClass.java, collectionName)
else remove(query, entityClass.java) else remove(query, entityClass.java)
@ -344,11 +327,10 @@ fun <T : Any> ReactiveMongoOperations.remove(query: Query, entityClass: KClass<T
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> ReactiveMongoOperations.remove(query: Query, inline fun <reified T : Any> ReactiveMongoOperations.remove(query: Query, collectionName: String? = null): Mono<DeleteResult> =
collectionName: String? = null): Mono<DeleteResult> =
if (collectionName != null) remove(query, T::class.java, collectionName) if (collectionName != null) remove(query, T::class.java, collectionName)
else remove(query, T::class.java) else remove(query, T::class.java)
@ -357,7 +339,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.remove(query: Query,
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> ReactiveMongoOperations.findAllAndRemove(query: Query): Flux<T> = inline fun <reified T : Any> ReactiveMongoOperations.findAllAndRemove(query: Query): Flux<T> =
@ -368,7 +350,7 @@ inline fun <reified T : Any> ReactiveMongoOperations.findAllAndRemove(query: Que
* thanks to Kotlin reified type parameters. * thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 2.0
*/ */
inline fun <reified T : Any> ReactiveMongoOperations.tail(query: Query, collectionName: String? = null): Flux<T> = inline fun <reified T : Any> ReactiveMongoOperations.tail(query: Query, collectionName: String? = null): Flux<T> =
if (collectionName != null) tail(query, T::class.java, collectionName) else tail(query, T::class.java) if (collectionName != null) tail(query, T::class.java, collectionName) else tail(query, T::class.java)

258
spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensionsTests.kt

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2017 the original author or authors. * Copyright 2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,521 +42,639 @@ class MongoOperationsExtensionsTests {
@Mock(answer = Answers.RETURNS_MOCKS) @Mock(answer = Answers.RETURNS_MOCKS)
lateinit var operations: MongoOperations lateinit var operations: MongoOperations
@Test @Test // DATAMONGO-1689
fun `getCollectionName(KClass) extension should call its Java counterpart`() { fun `getCollectionName(KClass) extension should call its Java counterpart`() {
operations.getCollectionName(First::class) operations.getCollectionName(First::class)
verify(operations, times(1)).getCollectionName(First::class.java) verify(operations, times(1)).getCollectionName(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `getCollectionName() with reified type parameter extension should call its Java counterpart`() { fun `getCollectionName() with reified type parameter extension should call its Java counterpart`() {
operations.getCollectionName<First>() operations.getCollectionName<First>()
verify(operations, times(1)).getCollectionName(First::class.java) verify(operations, times(1)).getCollectionName(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `execute(CollectionCallback) with reified type parameter extension should call its Java counterpart`() { fun `execute(CollectionCallback) with reified type parameter extension should call its Java counterpart`() {
val collectionCallback = mock<CollectionCallback<First>>() val collectionCallback = mock<CollectionCallback<First>>()
operations.execute(collectionCallback) operations.execute(collectionCallback)
verify(operations, times(1)).execute(First::class.java, collectionCallback) verify(operations, times(1)).execute(First::class.java, collectionCallback)
} }
@Test @Test // DATAMONGO-1689
fun `stream(Query) with reified type parameter extension should call its Java counterpart`() { fun `stream(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.stream<First>(query) operations.stream<First>(query)
verify(operations, times(1)).stream(query, First::class.java) verify(operations, times(1)).stream(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `stream(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `stream(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.stream<First>(query, collectionName) operations.stream<First>(query, collectionName)
verify(operations, times(1)).stream(query, First::class.java, collectionName) verify(operations, times(1)).stream(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection(KClass) extension should call its Java counterpart`() { fun `createCollection(KClass) extension should call its Java counterpart`() {
operations.createCollection(First::class) operations.createCollection(First::class)
verify(operations, times(1)).createCollection(First::class.java) verify(operations, times(1)).createCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection(KClass, CollectionOptions) extension should call its Java counterpart`() { fun `createCollection(KClass, CollectionOptions) extension should call its Java counterpart`() {
val collectionOptions = mock<CollectionOptions>() val collectionOptions = mock<CollectionOptions>()
operations.createCollection(First::class, collectionOptions) operations.createCollection(First::class, collectionOptions)
verify(operations, times(1)).createCollection(First::class.java, collectionOptions) verify(operations, times(1)).createCollection(First::class.java, collectionOptions)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection() with reified type parameter extension should call its Java counterpart`() { fun `createCollection() with reified type parameter extension should call its Java counterpart`() {
operations.createCollection<First>() operations.createCollection<First>()
verify(operations, times(1)).createCollection(First::class.java) verify(operations, times(1)).createCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection(CollectionOptions) with reified type parameter extension should call its Java counterpart`() { fun `createCollection(CollectionOptions) with reified type parameter extension should call its Java counterpart`() {
val collectionOptions = mock<CollectionOptions>() val collectionOptions = mock<CollectionOptions>()
operations.createCollection<First>(collectionOptions) operations.createCollection<First>(collectionOptions)
verify(operations, times(1)).createCollection(First::class.java, collectionOptions) verify(operations, times(1)).createCollection(First::class.java, collectionOptions)
} }
@Test @Test // DATAMONGO-1689
fun `collectionExists(KClass) extension should call its Java counterpart`() { fun `collectionExists(KClass) extension should call its Java counterpart`() {
operations.collectionExists(First::class) operations.collectionExists(First::class)
verify(operations, times(1)).collectionExists(First::class.java) verify(operations, times(1)).collectionExists(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `collectionExists() with reified type parameter extension should call its Java counterpart`() { fun `collectionExists() with reified type parameter extension should call its Java counterpart`() {
operations.collectionExists<First>() operations.collectionExists<First>()
verify(operations, times(1)).collectionExists(First::class.java) verify(operations, times(1)).collectionExists(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `dropCollection(KClass) extension should call its Java counterpart`() { fun `dropCollection(KClass) extension should call its Java counterpart`() {
operations.dropCollection(First::class) operations.dropCollection(First::class)
verify(operations, times(1)).dropCollection(First::class.java) verify(operations, times(1)).dropCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `dropCollection() with reified type parameter extension should call its Java counterpart`() { fun `dropCollection() with reified type parameter extension should call its Java counterpart`() {
operations.dropCollection<First>() operations.dropCollection<First>()
verify(operations, times(1)).dropCollection(First::class.java) verify(operations, times(1)).dropCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `indexOps(KClass) extension should call its Java counterpart`() { fun `indexOps(KClass) extension should call its Java counterpart`() {
operations.indexOps(First::class) operations.indexOps(First::class)
verify(operations, times(1)).indexOps(First::class.java) verify(operations, times(1)).indexOps(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `indexOps() with reified type parameter extension should call its Java counterpart`() { fun `indexOps() with reified type parameter extension should call its Java counterpart`() {
operations.indexOps<First>() operations.indexOps<First>()
verify(operations, times(1)).indexOps(First::class.java) verify(operations, times(1)).indexOps(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `bulkOps(BulkMode, KClass) extension should call its Java counterpart`() { fun `bulkOps(BulkMode, KClass) extension should call its Java counterpart`() {
val bulkMode = BulkMode.ORDERED val bulkMode = BulkMode.ORDERED
operations.bulkOps(bulkMode, First::class) operations.bulkOps(bulkMode, First::class)
verify(operations, times(1)).bulkOps(bulkMode, First::class.java) verify(operations, times(1)).bulkOps(bulkMode, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `bulkOps(BulkMode, KClass, String) extension should call its Java counterpart`() { fun `bulkOps(BulkMode, KClass, String) extension should call its Java counterpart`() {
val bulkMode = BulkMode.ORDERED val bulkMode = BulkMode.ORDERED
val collectionName = "foo" val collectionName = "foo"
operations.bulkOps(bulkMode, First::class, collectionName) operations.bulkOps(bulkMode, First::class, collectionName)
verify(operations, times(1)).bulkOps(bulkMode, First::class.java, collectionName) verify(operations, times(1)).bulkOps(bulkMode, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `bulkOps(BulkMode) with reified type parameter extension should call its Java counterpart`() { fun `bulkOps(BulkMode) with reified type parameter extension should call its Java counterpart`() {
val bulkMode = BulkMode.ORDERED val bulkMode = BulkMode.ORDERED
operations.bulkOps<First>(bulkMode) operations.bulkOps<First>(bulkMode)
verify(operations, times(1)).bulkOps(bulkMode, First::class.java) verify(operations, times(1)).bulkOps(bulkMode, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `bulkOps(BulkMode, String) with reified type parameter extension should call its Java counterpart`() { fun `bulkOps(BulkMode, String) with reified type parameter extension should call its Java counterpart`() {
val bulkMode = BulkMode.ORDERED val bulkMode = BulkMode.ORDERED
val collectionName = "foo" val collectionName = "foo"
operations.bulkOps<First>(bulkMode, collectionName) operations.bulkOps<First>(bulkMode, collectionName)
verify(operations, times(1)).bulkOps(bulkMode, First::class.java, collectionName) verify(operations, times(1)).bulkOps(bulkMode, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findAll() with reified type parameter extension should call its Java counterpart`() { fun `findAll() with reified type parameter extension should call its Java counterpart`() {
operations.findAll<First>() operations.findAll<First>()
verify(operations, times(1)).findAll(First::class.java) verify(operations, times(1)).findAll(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findAll(String) with reified type parameter extension should call its Java counterpart`() { fun `findAll(String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
operations.findAll<First>(collectionName) operations.findAll<First>(collectionName)
verify(operations, times(1)).findAll(First::class.java, collectionName) verify(operations, times(1)).findAll(First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `group(String, GroupBy) with reified type parameter extension should call its Java counterpart`() { fun `group(String, GroupBy) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val groupBy = mock<GroupBy>() val groupBy = mock<GroupBy>()
operations.group<First>(collectionName, groupBy) operations.group<First>(collectionName, groupBy)
verify(operations, times(1)).group(collectionName, groupBy, First::class.java) verify(operations, times(1)).group(collectionName, groupBy, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `group(Criteria, String, GroupBy) with reified type parameter extension should call its Java counterpart`() { fun `group(Criteria, String, GroupBy) with reified type parameter extension should call its Java counterpart`() {
val criteria = mock<Criteria>() val criteria = mock<Criteria>()
val collectionName = "foo" val collectionName = "foo"
val groupBy = mock<GroupBy>() val groupBy = mock<GroupBy>()
operations.group<First>(criteria, collectionName, groupBy) operations.group<First>(criteria, collectionName, groupBy)
verify(operations, times(1)).group(criteria, collectionName, groupBy, First::class.java) verify(operations, times(1)).group(criteria, collectionName, groupBy, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `aggregate(Aggregation, KClass) with reified type parameter extension should call its Java counterpart`() { fun `aggregate(Aggregation, KClass) with reified type parameter extension should call its Java counterpart`() {
val aggregation = mock<Aggregation>() val aggregation = mock<Aggregation>()
operations.aggregate<First>(aggregation, Second::class) operations.aggregate<First>(aggregation, Second::class)
verify(operations, times(1)).aggregate(aggregation, Second::class.java, First::class.java) verify(operations, times(1)).aggregate(aggregation, Second::class.java, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `aggregate(Aggregation, String) with reified type parameter extension should call its Java counterpart`() { fun `aggregate(Aggregation, String) with reified type parameter extension should call its Java counterpart`() {
val aggregation = mock<Aggregation>() val aggregation = mock<Aggregation>()
val collectionName = "foo" val collectionName = "foo"
operations.aggregate<First>(aggregation, collectionName) operations.aggregate<First>(aggregation, collectionName)
verify(operations, times(1)).aggregate(aggregation, collectionName, First::class.java) verify(operations, times(1)).aggregate(aggregation, collectionName, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `aggregateStream(Aggregation, KClass) with reified type parameter extension should call its Java counterpart`() { fun `aggregateStream(Aggregation, KClass) with reified type parameter extension should call its Java counterpart`() {
val aggregation = mock<Aggregation>() val aggregation = mock<Aggregation>()
operations.aggregateStream<First>(aggregation, Second::class) operations.aggregateStream<First>(aggregation, Second::class)
verify(operations, times(1)).aggregateStream(aggregation, Second::class.java, First::class.java) verify(operations, times(1)).aggregateStream(aggregation, Second::class.java, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `aggregateStream(Aggregation, String) with reified type parameter extension should call its Java counterpart`() { fun `aggregateStream(Aggregation, String) with reified type parameter extension should call its Java counterpart`() {
val aggregation = mock<Aggregation>() val aggregation = mock<Aggregation>()
val collectionName = "foo" val collectionName = "foo"
operations.aggregateStream<First>(aggregation, collectionName) operations.aggregateStream<First>(aggregation, collectionName)
verify(operations, times(1)).aggregateStream(aggregation, collectionName, First::class.java) verify(operations, times(1)).aggregateStream(aggregation, collectionName, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `mapReduce(String, String, String) with reified type parameter extension should call its Java counterpart`() { fun `mapReduce(String, String, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val mapFunction = "bar" val mapFunction = "bar"
val reduceFunction = "baz" val reduceFunction = "baz"
operations.mapReduce<First>(collectionName, mapFunction, reduceFunction) operations.mapReduce<First>(collectionName, mapFunction, reduceFunction)
verify(operations, times(1)).mapReduce(collectionName, mapFunction, reduceFunction, First::class.java) verify(operations, times(1)).mapReduce(collectionName, mapFunction, reduceFunction, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `mapReduce(String, String, String, MapReduceOptions) with reified type parameter extension should call its Java counterpart`() { fun `mapReduce(String, String, String, MapReduceOptions) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val mapFunction = "bar" val mapFunction = "bar"
val reduceFunction = "baz" val reduceFunction = "baz"
val options = mock<MapReduceOptions>() val options = mock<MapReduceOptions>()
operations.mapReduce<First>(collectionName, mapFunction, reduceFunction, options) operations.mapReduce<First>(collectionName, mapFunction, reduceFunction, options)
verify(operations, times(1)).mapReduce(collectionName, mapFunction, reduceFunction, options, First::class.java) verify(operations, times(1)).mapReduce(collectionName, mapFunction, reduceFunction, options, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `mapReduce(Query, String, String, String) with reified type parameter extension should call its Java counterpart`() { fun `mapReduce(Query, String, String, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
val mapFunction = "bar" val mapFunction = "bar"
val reduceFunction = "baz" val reduceFunction = "baz"
operations.mapReduce<First>(query, collectionName, mapFunction, reduceFunction) operations.mapReduce<First>(query, collectionName, mapFunction, reduceFunction)
verify(operations, times(1)).mapReduce(query, collectionName, mapFunction, reduceFunction, First::class.java) verify(operations, times(1)).mapReduce(query, collectionName, mapFunction, reduceFunction, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `mapReduce(Query, String, String, String, MapReduceOptions) with reified type parameter extension should call its Java counterpart`() { fun `mapReduce(Query, String, String, String, MapReduceOptions) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
val mapFunction = "bar" val mapFunction = "bar"
val reduceFunction = "baz" val reduceFunction = "baz"
val options = mock<MapReduceOptions>() val options = mock<MapReduceOptions>()
operations.mapReduce<First>(query, collectionName, mapFunction, reduceFunction, options) operations.mapReduce<First>(query, collectionName, mapFunction, reduceFunction, options)
verify(operations, times(1)).mapReduce(query, collectionName, mapFunction, reduceFunction, options, First::class.java) verify(operations, times(1)).mapReduce(query, collectionName, mapFunction, reduceFunction, options, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `geoNear(Query) with reified type parameter extension should call its Java counterpart`() { fun `geoNear(Query) with reified type parameter extension should call its Java counterpart`() {
val query = NearQuery.near(0.0, 0.0) val query = NearQuery.near(0.0, 0.0)
operations.geoNear<First>(query) operations.geoNear<First>(query)
verify(operations, times(1)).geoNear(query, First::class.java) verify(operations, times(1)).geoNear(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `geoNear(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `geoNear(Query, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = NearQuery.near(0.0, 0.0) val query = NearQuery.near(0.0, 0.0)
operations.geoNear<First>(query, collectionName) operations.geoNear<First>(query, collectionName)
verify(operations, times(1)).geoNear(query, First::class.java, collectionName) verify(operations, times(1)).geoNear(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findOne(Query) with reified type parameter extension should call its Java counterpart`() { fun `findOne(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.findOne<First>(query) operations.findOne<First>(query)
verify(operations, times(1)).findOne(query, First::class.java) verify(operations, times(1)).findOne(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findOne(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `findOne(Query, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = mock<Query>() val query = mock<Query>()
operations.findOne<First>(query, collectionName) operations.findOne<First>(query, collectionName)
verify(operations, times(1)).findOne(query, First::class.java, collectionName) verify(operations, times(1)).findOne(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `exists(Query, KClass) extension should call its Java counterpart`() { fun `exists(Query, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.exists(query, First::class) operations.exists(query, First::class)
verify(operations, times(1)).exists(query, First::class.java) verify(operations, times(1)).exists(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `exists(Query) with reified type parameter extension should call its Java counterpart`() { fun `exists(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.exists<First>(query) operations.exists<First>(query)
verify(operations, times(1)).exists(query, First::class.java) verify(operations, times(1)).exists(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `find(Query) with reified type parameter extension should call its Java counterpart`() { fun `find(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.find<First>(query) operations.find<First>(query)
verify(operations, times(1)).find(query, First::class.java) verify(operations, times(1)).find(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `find(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `find(Query, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = mock<Query>() val query = mock<Query>()
operations.find<First>(query, collectionName) operations.find<First>(query, collectionName)
verify(operations, times(1)).find(query, First::class.java, collectionName) verify(operations, times(1)).find(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findById(Any) with reified type parameter extension should call its Java counterpart`() { fun `findById(Any) with reified type parameter extension should call its Java counterpart`() {
val id = 1L val id = 1L
operations.findById<First>(id) operations.findById<First>(id)
verify(operations, times(1)).findById(id, First::class.java) verify(operations, times(1)).findById(id, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findById(Any, String) with reified type parameter extension should call its Java counterpart`() { fun `findById(Any, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val id = 1L val id = 1L
operations.findById<First>(id, collectionName) operations.findById<First>(id, collectionName)
verify(operations, times(1)).findById(id, First::class.java, collectionName) verify(operations, times(1)).findById(id, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findAndModify(Query, Update, FindAndModifyOptions) with reified type parameter extension should call its Java counterpart`() { fun `findAndModify(Query, Update, FindAndModifyOptions) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val options = mock<FindAndModifyOptions>() val options = mock<FindAndModifyOptions>()
operations.findAndModify<First>(query, update, options) operations.findAndModify<First>(query, update, options)
verify(operations, times(1)).findAndModify(query, update, options, First::class.java) verify(operations, times(1)).findAndModify(query, update, options, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findAndModify(Query, Update, FindAndModifyOptions, String) with reified type parameter extension should call its Java counterpart`() { fun `findAndModify(Query, Update, FindAndModifyOptions, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val options = mock<FindAndModifyOptions>() val options = mock<FindAndModifyOptions>()
operations.findAndModify<First>(query, update, options, collectionName) operations.findAndModify<First>(query, update, options, collectionName)
verify(operations, times(1)).findAndModify(query, update, options, First::class.java, collectionName) verify(operations, times(1)).findAndModify(query, update, options, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findAndRemove(Query) with reified type parameter extension should call its Java counterpart`() { fun `findAndRemove(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.findAndRemove<First>(query) operations.findAndRemove<First>(query)
verify(operations, times(1)).findAndRemove(query, First::class.java) verify(operations, times(1)).findAndRemove(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findAndRemove(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `findAndRemove(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.findAndRemove<First>(query, collectionName) operations.findAndRemove<First>(query, collectionName)
verify(operations, times(1)).findAndRemove(query, First::class.java, collectionName) verify(operations, times(1)).findAndRemove(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `count() with reified type parameter extension should call its Java counterpart`() { fun `count() with reified type parameter extension should call its Java counterpart`() {
operations.count<First>() operations.count<First>()
verify(operations, times(1)).count(any<Query>(), eq(First::class.java)) verify(operations, times(1)).count(any<Query>(), eq(First::class.java))
} }
@Test @Test // DATAMONGO-1689
fun `count(Query) with reified type parameter extension should call its Java counterpart`() { fun `count(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.count<First>(query) operations.count<First>(query)
verify(operations, times(1)).count(query, First::class.java) verify(operations, times(1)).count(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `count(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `count(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.count<First>(query, collectionName) operations.count<First>(query, collectionName)
verify(operations, times(1)).count(query, First::class.java, collectionName) verify(operations, times(1)).count(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `count(Query, KClass) with reified type parameter extension should call its Java counterpart`() { fun `count(Query, KClass) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.count(query, First::class) operations.count(query, First::class)
verify(operations, times(1)).count(query, First::class.java) verify(operations, times(1)).count(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `count(Query, KClass, String) with reified type parameter extension should call its Java counterpart`() { fun `count(Query, KClass, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.count(query, First::class, collectionName) operations.count(query, First::class, collectionName)
verify(operations, times(1)).count(query, First::class.java, collectionName) verify(operations, times(1)).count(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `insert(Collection, KClass) extension should call its Java counterpart`() { fun `insert(Collection, KClass) extension should call its Java counterpart`() {
val collection = listOf(First(), First()) val collection = listOf(First(), First())
operations.insert(collection, First::class) operations.insert(collection, First::class)
verify(operations, times(1)).insert(collection, First::class.java) verify(operations, times(1)).insert(collection, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update, KClass) extension should call its Java counterpart`() { fun `upsert(Query, Update, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.upsert(query, update, First::class) operations.upsert(query, update, First::class)
verify(operations, times(1)).upsert(query, update, First::class.java) verify(operations, times(1)).upsert(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update, KClass, String) extension should call its Java counterpart`() { fun `upsert(Query, Update, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.upsert(query, update, First::class, collectionName) operations.upsert(query, update, First::class, collectionName)
verify(operations, times(1)).upsert(query, update, First::class.java, collectionName) verify(operations, times(1)).upsert(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update) with reified type parameter extension should call its Java counterpart`() { fun `upsert(Query, Update) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.upsert<First>(query, update) operations.upsert<First>(query, update)
verify(operations, times(1)).upsert(query, update, First::class.java) verify(operations, times(1)).upsert(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update, String) with reified type parameter extension should call its Java counterpart`() { fun `upsert(Query, Update, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.upsert<First>(query, update, collectionName) operations.upsert<First>(query, update, collectionName)
verify(operations, times(1)).upsert(query, update, First::class.java, collectionName) verify(operations, times(1)).upsert(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update, KClass) extension should call its Java counterpart`() { fun `updateFirst(Query, Update, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateFirst(query, update, First::class) operations.updateFirst(query, update, First::class)
verify(operations, times(1)).updateFirst(query, update, First::class.java) verify(operations, times(1)).updateFirst(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update, KClass, String) extension should call its Java counterpart`() { fun `updateFirst(Query, Update, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateFirst(query, update, First::class, collectionName) operations.updateFirst(query, update, First::class, collectionName)
verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName) verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update) with reified type parameter extension should call its Java counterpart`() { fun `updateFirst(Query, Update) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateFirst<First>(query, update) operations.updateFirst<First>(query, update)
verify(operations, times(1)).updateFirst(query, update, First::class.java) verify(operations, times(1)).updateFirst(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update, String) with reified type parameter extension should call its Java counterpart`() { fun `updateFirst(Query, Update, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateFirst<First>(query, update, collectionName) operations.updateFirst<First>(query, update, collectionName)
verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName) verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update, KClass) extension should call its Java counterpart`() { fun `updateMulti(Query, Update, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateMulti(query, update, First::class) operations.updateMulti(query, update, First::class)
verify(operations, times(1)).updateMulti(query, update, First::class.java) verify(operations, times(1)).updateMulti(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update, KClass, String) extension should call its Java counterpart`() { fun `updateMulti(Query, Update, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateMulti(query, update, First::class, collectionName) operations.updateMulti(query, update, First::class, collectionName)
verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName) verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update) with reified type parameter extension should call its Java counterpart`() { fun `updateMulti(Query, Update) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateMulti<First>(query, update) operations.updateMulti<First>(query, update)
verify(operations, times(1)).updateMulti(query, update, First::class.java) verify(operations, times(1)).updateMulti(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update, String) with reified type parameter extension should call its Java counterpart`() { fun `updateMulti(Query, Update, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateMulti<First>(query, update, collectionName) operations.updateMulti<First>(query, update, collectionName)
verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName) verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query, KClass) extension should call its Java counterpart`() { fun `remove(Query, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.remove(query, First::class) operations.remove(query, First::class)
verify(operations, times(1)).remove(query, First::class.java) verify(operations, times(1)).remove(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query, KClass, String) extension should call its Java counterpart`() { fun `remove(Query, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.remove(query, First::class, collectionName) operations.remove(query, First::class, collectionName)
verify(operations, times(1)).remove(query, First::class.java, collectionName) verify(operations, times(1)).remove(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query) with reified type parameter extension should call its Java counterpart`() { fun `remove(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.remove<First>(query) operations.remove<First>(query)
verify(operations, times(1)).remove(query, First::class.java) verify(operations, times(1)).remove(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `remove(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.remove<First>(query, collectionName) operations.remove<First>(query, collectionName)
verify(operations, times(1)).remove(query, First::class.java, collectionName) verify(operations, times(1)).remove(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findAllAndRemove(Query) with reified type parameter extension should call its Java counterpart`() { fun `findAllAndRemove(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.findAllAndRemove<First>(query) operations.findAllAndRemove<First>(query)
verify(operations, times(1)).findAllAndRemove(query, First::class.java) verify(operations, times(1)).findAllAndRemove(query, First::class.java)
} }
} }

205
spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveMongoOperationsExtensionsTests.kt

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2017 the original author or authors. * Copyright 2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,398 +37,493 @@ class ReactiveMongoOperationsExtensionsTests {
@Mock(answer = Answers.RETURNS_MOCKS) @Mock(answer = Answers.RETURNS_MOCKS)
lateinit var operations: ReactiveMongoOperations lateinit var operations: ReactiveMongoOperations
@Test @Test // DATAMONGO-1689
fun `indexOps(KClass) extension should call its Java counterpart`() { fun `indexOps(KClass) extension should call its Java counterpart`() {
operations.indexOps(First::class) operations.indexOps(First::class)
verify(operations, times(1)).indexOps(First::class.java) verify(operations, times(1)).indexOps(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `indexOps() with reified type parameter extension should call its Java counterpart`() { fun `indexOps() with reified type parameter extension should call its Java counterpart`() {
operations.indexOps<First>() operations.indexOps<First>()
verify(operations, times(1)).indexOps(First::class.java) verify(operations, times(1)).indexOps(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `execute(ReactiveCollectionCallback) with reified type parameter extension should call its Java counterpart`() { fun `execute(ReactiveCollectionCallback) with reified type parameter extension should call its Java counterpart`() {
val collectionCallback = mock<ReactiveCollectionCallback<First>>() val collectionCallback = mock<ReactiveCollectionCallback<First>>()
operations.execute(collectionCallback) operations.execute(collectionCallback)
verify(operations, times(1)).execute(First::class.java, collectionCallback) verify(operations, times(1)).execute(First::class.java, collectionCallback)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection(KClass) extension should call its Java counterpart`() { fun `createCollection(KClass) extension should call its Java counterpart`() {
operations.createCollection(First::class) operations.createCollection(First::class)
verify(operations, times(1)).createCollection(First::class.java) verify(operations, times(1)).createCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection(KClass, CollectionOptions) extension should call its Java counterpart`() { fun `createCollection(KClass, CollectionOptions) extension should call its Java counterpart`() {
val collectionOptions = mock<CollectionOptions>() val collectionOptions = mock<CollectionOptions>()
operations.createCollection(First::class, collectionOptions) operations.createCollection(First::class, collectionOptions)
verify(operations, times(1)).createCollection(First::class.java, collectionOptions) verify(operations, times(1)).createCollection(First::class.java, collectionOptions)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection() with reified type parameter extension should call its Java counterpart`() { fun `createCollection() with reified type parameter extension should call its Java counterpart`() {
operations.createCollection<First>() operations.createCollection<First>()
verify(operations, times(1)).createCollection(First::class.java) verify(operations, times(1)).createCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `createCollection(CollectionOptions) with reified type parameter extension should call its Java counterpart`() { fun `createCollection(CollectionOptions) with reified type parameter extension should call its Java counterpart`() {
val collectionOptions = mock<CollectionOptions>() val collectionOptions = mock<CollectionOptions>()
operations.createCollection<First>(collectionOptions) operations.createCollection<First>(collectionOptions)
verify(operations, times(1)).createCollection(First::class.java, collectionOptions) verify(operations, times(1)).createCollection(First::class.java, collectionOptions)
} }
@Test @Test // DATAMONGO-1689
fun `collectionExists(KClass) extension should call its Java counterpart`() { fun `collectionExists(KClass) extension should call its Java counterpart`() {
operations.collectionExists(First::class) operations.collectionExists(First::class)
verify(operations, times(1)).collectionExists(First::class.java) verify(operations, times(1)).collectionExists(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `collectionExists() with reified type parameter extension should call its Java counterpart`() { fun `collectionExists() with reified type parameter extension should call its Java counterpart`() {
operations.collectionExists<First>() operations.collectionExists<First>()
verify(operations, times(1)).collectionExists(First::class.java) verify(operations, times(1)).collectionExists(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `dropCollection(KClass) extension should call its Java counterpart`() { fun `dropCollection(KClass) extension should call its Java counterpart`() {
operations.dropCollection(First::class) operations.dropCollection(First::class)
verify(operations, times(1)).dropCollection(First::class.java) verify(operations, times(1)).dropCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `dropCollection() with reified type parameter extension should call its Java counterpart`() { fun `dropCollection() with reified type parameter extension should call its Java counterpart`() {
operations.dropCollection<First>() operations.dropCollection<First>()
verify(operations, times(1)).dropCollection(First::class.java) verify(operations, times(1)).dropCollection(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findAll() with reified type parameter extension should call its Java counterpart`() { fun `findAll() with reified type parameter extension should call its Java counterpart`() {
operations.findAll<First>() operations.findAll<First>()
verify(operations, times(1)).findAll(First::class.java) verify(operations, times(1)).findAll(First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findAll(String) with reified type parameter extension should call its Java counterpart`() { fun `findAll(String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
operations.findAll<First>(collectionName) operations.findAll<First>(collectionName)
verify(operations, times(1)).findAll(First::class.java, collectionName) verify(operations, times(1)).findAll(First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findOne(Query) with reified type parameter extension should call its Java counterpart`() { fun `findOne(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.findOne<First>(query) operations.findOne<First>(query)
verify(operations, times(1)).findOne(query, First::class.java) verify(operations, times(1)).findOne(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findOne(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `findOne(Query, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = mock<Query>() val query = mock<Query>()
operations.findOne<First>(query, collectionName) operations.findOne<First>(query, collectionName)
verify(operations, times(1)).findOne(query, First::class.java, collectionName) verify(operations, times(1)).findOne(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `exists(Query, KClass) extension should call its Java counterpart`() { fun `exists(Query, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.exists(query, First::class) operations.exists(query, First::class)
verify(operations, times(1)).exists(query, First::class.java) verify(operations, times(1)).exists(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `exists(Query) with reified type parameter extension should call its Java counterpart`() { fun `exists(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.exists<First>(query) operations.exists<First>(query)
verify(operations, times(1)).exists(query, First::class.java) verify(operations, times(1)).exists(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `find(Query) with reified type parameter extension should call its Java counterpart`() { fun `find(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.find<First>(query) operations.find<First>(query)
verify(operations, times(1)).find(query, First::class.java) verify(operations, times(1)).find(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `find(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `find(Query, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = mock<Query>() val query = mock<Query>()
operations.find<First>(query, collectionName) operations.find<First>(query, collectionName)
verify(operations, times(1)).find(query, First::class.java, collectionName) verify(operations, times(1)).find(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findById(Any) with reified type parameter extension should call its Java counterpart`() { fun `findById(Any) with reified type parameter extension should call its Java counterpart`() {
val id = 1L val id = 1L
operations.findById<First>(id) operations.findById<First>(id)
verify(operations, times(1)).findById(id, First::class.java) verify(operations, times(1)).findById(id, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findById(Any, String) with reified type parameter extension should call its Java counterpart`() { fun `findById(Any, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val id = 1L val id = 1L
operations.findById<First>(id, collectionName) operations.findById<First>(id, collectionName)
verify(operations, times(1)).findById(id, First::class.java, collectionName) verify(operations, times(1)).findById(id, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `geoNear(Query) with reified type parameter extension should call its Java counterpart`() { fun `geoNear(Query) with reified type parameter extension should call its Java counterpart`() {
val query = NearQuery.near(0.0, 0.0) val query = NearQuery.near(0.0, 0.0)
operations.geoNear<First>(query) operations.geoNear<First>(query)
verify(operations, times(1)).geoNear(query, First::class.java) verify(operations, times(1)).geoNear(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `geoNear(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `geoNear(Query, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = NearQuery.near(0.0, 0.0) val query = NearQuery.near(0.0, 0.0)
operations.geoNear<First>(query, collectionName) operations.geoNear<First>(query, collectionName)
verify(operations, times(1)).geoNear(query, First::class.java, collectionName) verify(operations, times(1)).geoNear(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findAndModify(Query, Update, FindAndModifyOptions) with reified type parameter extension should call its Java counterpart`() { fun `findAndModify(Query, Update, FindAndModifyOptions) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val options = mock<FindAndModifyOptions>() val options = mock<FindAndModifyOptions>()
operations.findAndModify<First>(query, update, options) operations.findAndModify<First>(query, update, options)
verify(operations, times(1)).findAndModify(query, update, options, First::class.java) verify(operations, times(1)).findAndModify(query, update, options, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findAndModify(Query, Update, FindAndModifyOptions, String) with reified type parameter extension should call its Java counterpart`() { fun `findAndModify(Query, Update, FindAndModifyOptions, String) with reified type parameter extension should call its Java counterpart`() {
val collectionName = "foo" val collectionName = "foo"
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val options = mock<FindAndModifyOptions>() val options = mock<FindAndModifyOptions>()
operations.findAndModify<First>(query, update, options, collectionName) operations.findAndModify<First>(query, update, options, collectionName)
verify(operations, times(1)).findAndModify(query, update, options, First::class.java, collectionName) verify(operations, times(1)).findAndModify(query, update, options, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findAndRemove(Query) with reified type parameter extension should call its Java counterpart`() { fun `findAndRemove(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.findAndRemove<First>(query) operations.findAndRemove<First>(query)
verify(operations, times(1)).findAndRemove(query, First::class.java) verify(operations, times(1)).findAndRemove(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `findAndRemove(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `findAndRemove(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.findAndRemove<First>(query, collectionName) operations.findAndRemove<First>(query, collectionName)
verify(operations, times(1)).findAndRemove(query, First::class.java, collectionName) verify(operations, times(1)).findAndRemove(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `count() with reified type parameter extension should call its Java counterpart`() { fun `count() with reified type parameter extension should call its Java counterpart`() {
operations.count<First>() operations.count<First>()
verify(operations, times(1)).count(any<Query>(), eq(First::class.java)) verify(operations, times(1)).count(any<Query>(), eq(First::class.java))
} }
@Test @Test // DATAMONGO-1689
fun `count(Query) with reified type parameter extension should call its Java counterpart`() { fun `count(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.count<First>(query) operations.count<First>(query)
verify(operations, times(1)).count(query, First::class.java) verify(operations, times(1)).count(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `count(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `count(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.count<First>(query, collectionName) operations.count<First>(query, collectionName)
verify(operations, times(1)).count(query, First::class.java, collectionName) verify(operations, times(1)).count(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `count(Query, KClass) with reified type parameter extension should call its Java counterpart`() { fun `count(Query, KClass) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.count(query, First::class) operations.count(query, First::class)
verify(operations, times(1)).count(query, First::class.java) verify(operations, times(1)).count(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `count(Query, KClass, String) with reified type parameter extension should call its Java counterpart`() { fun `count(Query, KClass, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.count(query, First::class, collectionName) operations.count(query, First::class, collectionName)
verify(operations, times(1)).count(query, First::class.java, collectionName) verify(operations, times(1)).count(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `insert(Collection, KClass) extension should call its Java counterpart`() { fun `insert(Collection, KClass) extension should call its Java counterpart`() {
val collection = listOf(First(), First()) val collection = listOf(First(), First())
operations.insert(collection, First::class) operations.insert(collection, First::class)
verify(operations, times(1)).insert(collection, First::class.java) verify(operations, times(1)).insert(collection, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `insertAll(Mono, KClass) extension should call its Java counterpart`() { fun `insertAll(Mono, KClass) extension should call its Java counterpart`() {
val collection = Mono.just(listOf(First(), First())) val collection = Mono.just(listOf(First(), First()))
operations.insertAll(collection, First::class) operations.insertAll(collection, First::class)
verify(operations, times(1)).insertAll(collection, First::class.java) verify(operations, times(1)).insertAll(collection, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update, KClass) extension should call its Java counterpart`() { fun `upsert(Query, Update, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.upsert(query, update, First::class) operations.upsert(query, update, First::class)
verify(operations, times(1)).upsert(query, update, First::class.java) verify(operations, times(1)).upsert(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update, KClass, String) extension should call its Java counterpart`() { fun `upsert(Query, Update, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.upsert(query, update, First::class, collectionName) operations.upsert(query, update, First::class, collectionName)
verify(operations, times(1)).upsert(query, update, First::class.java, collectionName) verify(operations, times(1)).upsert(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update) with reified type parameter extension should call its Java counterpart`() { fun `upsert(Query, Update) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.upsert<First>(query, update) operations.upsert<First>(query, update)
verify(operations, times(1)).upsert(query, update, First::class.java) verify(operations, times(1)).upsert(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `upsert(Query, Update, String) with reified type parameter extension should call its Java counterpart`() { fun `upsert(Query, Update, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.upsert<First>(query, update, collectionName) operations.upsert<First>(query, update, collectionName)
verify(operations, times(1)).upsert(query, update, First::class.java, collectionName) verify(operations, times(1)).upsert(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update, KClass) extension should call its Java counterpart`() { fun `updateFirst(Query, Update, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateFirst(query, update, First::class) operations.updateFirst(query, update, First::class)
verify(operations, times(1)).updateFirst(query, update, First::class.java) verify(operations, times(1)).updateFirst(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update, KClass, String) extension should call its Java counterpart`() { fun `updateFirst(Query, Update, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateFirst(query, update, First::class, collectionName) operations.updateFirst(query, update, First::class, collectionName)
verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName) verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update) with reified type parameter extension should call its Java counterpart`() { fun `updateFirst(Query, Update) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateFirst<First>(query, update) operations.updateFirst<First>(query, update)
verify(operations, times(1)).updateFirst(query, update, First::class.java) verify(operations, times(1)).updateFirst(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateFirst(Query, Update, String) with reified type parameter extension should call its Java counterpart`() { fun `updateFirst(Query, Update, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateFirst<First>(query, update, collectionName) operations.updateFirst<First>(query, update, collectionName)
verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName) verify(operations, times(1)).updateFirst(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update, KClass) extension should call its Java counterpart`() { fun `updateMulti(Query, Update, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateMulti(query, update, First::class) operations.updateMulti(query, update, First::class)
verify(operations, times(1)).updateMulti(query, update, First::class.java) verify(operations, times(1)).updateMulti(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update, KClass, String) extension should call its Java counterpart`() { fun `updateMulti(Query, Update, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateMulti(query, update, First::class, collectionName) operations.updateMulti(query, update, First::class, collectionName)
verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName) verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update) with reified type parameter extension should call its Java counterpart`() { fun `updateMulti(Query, Update) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
operations.updateMulti<First>(query, update) operations.updateMulti<First>(query, update)
verify(operations, times(1)).updateMulti(query, update, First::class.java) verify(operations, times(1)).updateMulti(query, update, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `updateMulti(Query, Update, String) with reified type parameter extension should call its Java counterpart`() { fun `updateMulti(Query, Update, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val update = mock<Update>() val update = mock<Update>()
val collectionName = "foo" val collectionName = "foo"
operations.updateMulti<First>(query, update, collectionName) operations.updateMulti<First>(query, update, collectionName)
verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName) verify(operations, times(1)).updateMulti(query, update, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query, KClass) extension should call its Java counterpart`() { fun `remove(Query, KClass) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.remove(query, First::class) operations.remove(query, First::class)
verify(operations, times(1)).remove(query, First::class.java) verify(operations, times(1)).remove(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query, KClass, String) extension should call its Java counterpart`() { fun `remove(Query, KClass, String) extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.remove(query, First::class, collectionName) operations.remove(query, First::class, collectionName)
verify(operations, times(1)).remove(query, First::class.java, collectionName) verify(operations, times(1)).remove(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query) with reified type parameter extension should call its Java counterpart`() { fun `remove(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.remove<First>(query) operations.remove<First>(query)
verify(operations, times(1)).remove(query, First::class.java) verify(operations, times(1)).remove(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `remove(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `remove(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.remove<First>(query, collectionName) operations.remove<First>(query, collectionName)
verify(operations, times(1)).remove(query, First::class.java, collectionName) verify(operations, times(1)).remove(query, First::class.java, collectionName)
} }
@Test @Test // DATAMONGO-1689
fun `findAllAndRemove(Query) with reified type parameter extension should call its Java counterpart`() { fun `findAllAndRemove(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.findAllAndRemove<First>(query) operations.findAllAndRemove<First>(query)
verify(operations, times(1)).findAllAndRemove(query, First::class.java) verify(operations, times(1)).findAllAndRemove(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `tail(Query) with reified type parameter extension should call its Java counterpart`() { fun `tail(Query) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
operations.tail<First>(query) operations.tail<First>(query)
verify(operations, times(1)).tail(query, First::class.java) verify(operations, times(1)).tail(query, First::class.java)
} }
@Test @Test // DATAMONGO-1689
fun `tail(Query, String) with reified type parameter extension should call its Java counterpart`() { fun `tail(Query, String) with reified type parameter extension should call its Java counterpart`() {
val query = mock<Query>() val query = mock<Query>()
val collectionName = "foo" val collectionName = "foo"
operations.tail<First>(query, collectionName) operations.tail<First>(query, collectionName)
verify(operations, times(1)).tail(query, First::class.java, collectionName) verify(operations, times(1)).tail(query, First::class.java, collectionName)
} }
} }

Loading…
Cancel
Save