DATACOUCH-341 - Add kotlin extension functions

Motivation
----------
Add kotin extension methods to couchbase and reactive couchbase
operations as required.

Changes
-------
Extensions leveraging reified type has been added.

Results
-------
It is now possible to use reified types rather than passing the java
class reference to some operation functions.

Original pull request: #160.
This commit is contained in:
Subhashni Balakrishnan
2018-03-01 14:10:08 -08:00
parent a46f8160a9
commit 53e3285098
5 changed files with 216 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package org.springframework.data.couchbase.core
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.annotation.Id
import org.springframework.data.couchbase.ContainerResourceRunner
import org.springframework.data.couchbase.IntegrationTestApplicationConfig
import org.springframework.test.context.ContextConfiguration
import kotlin.test.assertEquals
@RunWith(ContainerResourceRunner::class)
@ContextConfiguration(classes = [IntegrationTestApplicationConfig::class])
class CouchbaseOperationsExtensionsTest {
@Autowired
lateinit var template: CouchbaseTemplate
@Test
fun `findById should call the reified extension`() {
val entityId = "CouchbaseOperationsExtensionsTestFindById"
val entity = Entity(entityId)
template.save(entity)
val stored = template.findById<Entity>(entityId)
assertEquals(entity.id, stored.id)
}
class Entity constructor(id: String) {
@Id
var id = id
}
}

View File

@@ -0,0 +1,35 @@
package org.springframework.data.couchbase.core
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.annotation.Id
import org.springframework.data.couchbase.ContainerResourceRunner
import org.springframework.data.couchbase.ReactiveIntegrationTestApplicationConfig
import org.springframework.data.couchbase.core.query.N1qlSecondaryIndexed
import org.springframework.test.context.ContextConfiguration
import kotlin.test.assertEquals
@RunWith(ContainerResourceRunner::class)
@ContextConfiguration(classes = [ReactiveIntegrationTestApplicationConfig::class])
class RxJavaCouchbaseOperationsExtensionsTest {
@Autowired
lateinit var template: RxJavaCouchbaseTemplate
@Test
fun `findById should call the reified extension`() {
val entityId = "RxJavaCouchbaseOperationsExtensionsTestFindById"
val entity = Entity(entityId)
template.save(entity).toBlocking().single()
val stored = template.findById<Entity>(entityId).toBlocking().single()
assertEquals(entity.id, stored.id)
}
class Entity constructor(id: String) {
@Id
var id = id
}
}