Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAMONGO-1689 - Add fluent extensions.
- Loading branch information
Showing
8 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
.../kotlin/org/springframework/data/mongodb/core/ExecutableAggregationOperationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.mongodb.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Extension for [ExecutableAggregationOperation.aggregateAndReturn] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
fun <T : Any> ExecutableAggregationOperation.aggregateAndReturn(entityClass: KClass<T>): ExecutableAggregationOperation.AggregationOperation<T> = | ||
aggregateAndReturn(entityClass.java) | ||
|
||
/** | ||
* Extension for [ExecutableAggregationOperation.aggregateAndReturn] leveraging reified type parameters. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
inline fun <reified T : Any> ExecutableAggregationOperation.aggregateAndReturn(): ExecutableAggregationOperation.AggregationOperation<T> = | ||
aggregateAndReturn(T::class.java) |
57 changes: 57 additions & 0 deletions
57
...rc/main/kotlin/org/springframework/data/mongodb/core/ExecutableFindOperationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.mongodb.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Extension for [ExecutableFindOperation.query] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
fun <T : Any> ExecutableFindOperation.query(entityClass: KClass<T>): ExecutableFindOperation.FindOperation<T> = | ||
query(entityClass.java) | ||
|
||
/** | ||
* Extension for [ExecutableFindOperation.query] leveraging reified type parameters. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
inline fun <reified T : Any> ExecutableFindOperation.query(): ExecutableFindOperation.FindOperation<T> = | ||
query(T::class.java) | ||
|
||
|
||
/** | ||
* Extension for [ExecutableFindOperation.FindOperationWithProjection.as] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
fun <T : Any> ExecutableFindOperation.FindOperationWithProjection<T>.asType(resultType: KClass<T>): ExecutableFindOperation.FindOperationWithQuery<T> = | ||
`as`(resultType.java) | ||
|
||
/** | ||
* Extension for [ExecutableFindOperation.FindOperationWithProjection.as] leveraging reified type parameters. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
inline fun <reified T : Any> ExecutableFindOperation.FindOperationWithProjection<T>.asType(): ExecutableFindOperation.FindOperationWithQuery<T> = | ||
`as`(T::class.java) | ||
|
||
|
36 changes: 36 additions & 0 deletions
36
.../main/kotlin/org/springframework/data/mongodb/core/ExecutableInsertOperationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.mongodb.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Extension for [ExecutableInsertOperation.insert] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
fun <T : Any> ExecutableInsertOperation.insert(entityClass: KClass<T>): ExecutableInsertOperation.InsertOperation<T> = | ||
insert(entityClass.java) | ||
|
||
/** | ||
* Extension for [ExecutableAggregationOperation.aggregateAndReturn] leveraging reified type parameters. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
inline fun <reified T : Any> ExecutableInsertOperation.insert(): ExecutableInsertOperation.InsertOperation<T> = | ||
insert(T::class.java) |
36 changes: 36 additions & 0 deletions
36
.../main/kotlin/org/springframework/data/mongodb/core/ExecutableRemoveOperationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.mongodb.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Extension for [ExecutableRemoveOperation.remove] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
fun <T : Any> ExecutableRemoveOperation.remove(entityClass: KClass<T>): ExecutableRemoveOperation.RemoveOperation<T> = | ||
remove(entityClass.java) | ||
|
||
/** | ||
* Extension for [ExecutableRemoveOperation.remove] leveraging reified type parameters. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 2.0 | ||
*/ | ||
inline fun <reified T : Any> ExecutableRemoveOperation.remove(): ExecutableRemoveOperation.RemoveOperation<T> = | ||
remove(T::class.java) |
32 changes: 32 additions & 0 deletions
32
...in/org/springframework/data/mongodb/core/ExecutableAggregationOperationExtensionsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.springframework.data.mongodb.core | ||
|
||
import example.first.First | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Answers | ||
import org.mockito.Mock | ||
import org.mockito.Mockito | ||
import org.mockito.junit.MockitoJUnitRunner | ||
|
||
/** | ||
* @author Sebastien Deleuze | ||
*/ | ||
@RunWith(MockitoJUnitRunner::class) | ||
class ExecutableAggregationOperationExtensionsTests { | ||
|
||
@Mock(answer = Answers.RETURNS_MOCKS) | ||
lateinit var operation: ExecutableAggregationOperation | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `aggregateAndReturn(KClass) extension should call its Java counterpart`() { | ||
operation.aggregateAndReturn(First::class) | ||
Mockito.verify(operation, Mockito.times(1)).aggregateAndReturn(First::class.java) | ||
} | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `aggregateAndReturn() with reified type parameter extension should call its Java counterpart`() { | ||
operation.aggregateAndReturn<First>() | ||
Mockito.verify(operation, Mockito.times(1)).aggregateAndReturn(First::class.java) | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...st/kotlin/org/springframework/data/mongodb/core/ExecutableFindOperationExtensionsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.springframework.data.mongodb.core | ||
|
||
import example.first.First | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Answers | ||
import org.mockito.Mock | ||
import org.mockito.Mockito | ||
import org.mockito.junit.MockitoJUnitRunner | ||
|
||
/** | ||
* @author Sebastien Deleuze | ||
*/ | ||
@RunWith(MockitoJUnitRunner::class) | ||
class ExecutableFindOperationExtensionsTests { | ||
|
||
@Mock(answer = Answers.RETURNS_MOCKS) | ||
lateinit var operation: ExecutableFindOperation | ||
|
||
@Mock(answer = Answers.RETURNS_MOCKS) | ||
lateinit var operationWithProjection: ExecutableFindOperation.FindOperationWithProjection<First> | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `ExecutableFindOperation#query(KClass) extension should call its Java counterpart`() { | ||
operation.query(First::class) | ||
Mockito.verify(operation, Mockito.times(1)).query(First::class.java) | ||
} | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `ExecutableFindOperation#query() with reified type parameter extension should call its Java counterpart`() { | ||
operation.query<First>() | ||
Mockito.verify(operation, Mockito.times(1)).query(First::class.java) | ||
} | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `ExecutableFindOperation#FindOperationWithProjection#asType(KClass) extension should call its Java counterpart`() { | ||
operationWithProjection.asType(First::class) | ||
Mockito.verify(operationWithProjection, Mockito.times(1)).`as`(First::class.java) | ||
} | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `ExecutableFindOperation#FindOperationWithProjection#asType() with reified type parameter extension should call its Java counterpart`() { | ||
operationWithProjection.asType() | ||
Mockito.verify(operationWithProjection, Mockito.times(1)).`as`(First::class.java) | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
.../kotlin/org/springframework/data/mongodb/core/ExecutableInsertOperationExtensionsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.springframework.data.mongodb.core | ||
|
||
import example.first.First | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Answers | ||
import org.mockito.Mock | ||
import org.mockito.Mockito | ||
import org.mockito.junit.MockitoJUnitRunner | ||
|
||
/** | ||
* @author Sebastien Deleuze | ||
*/ | ||
@RunWith(MockitoJUnitRunner::class) | ||
class ExecutableInsertOperationExtensionsTests { | ||
|
||
@Mock(answer = Answers.RETURNS_MOCKS) | ||
lateinit var operation: ExecutableInsertOperation | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `insert(KClass) extension should call its Java counterpart`() { | ||
operation.insert(First::class) | ||
Mockito.verify(operation, Mockito.times(1)).insert(First::class.java) | ||
} | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `insert() with reified type parameter extension should call its Java counterpart`() { | ||
operation.insert<First>() | ||
Mockito.verify(operation, Mockito.times(1)).insert(First::class.java) | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
.../kotlin/org/springframework/data/mongodb/core/ExecutableRemoveOperationExtensionsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.springframework.data.mongodb.core | ||
|
||
import example.first.First | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Answers | ||
import org.mockito.Mock | ||
import org.mockito.Mockito | ||
import org.mockito.junit.MockitoJUnitRunner | ||
|
||
/** | ||
* @author Sebastien Deleuze | ||
*/ | ||
@RunWith(MockitoJUnitRunner::class) | ||
class ExecutableRemoveOperationExtensionsTests { | ||
|
||
@Mock(answer = Answers.RETURNS_MOCKS) | ||
lateinit var operation: ExecutableRemoveOperation | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `remove(KClass) extension should call its Java counterpart`() { | ||
operation.remove(First::class) | ||
Mockito.verify(operation, Mockito.times(1)).remove(First::class.java) | ||
} | ||
|
||
@Test // DATAMONGO-1689 | ||
fun `remove() with reified type parameter extension should call its Java counterpart`() { | ||
operation.remove<First>() | ||
Mockito.verify(operation, Mockito.times(1)).remove(First::class.java) | ||
} | ||
|
||
} |