simple failing delegation test
@@ -6,7 +6,9 @@ import dev.morphia.annotations.Version
import org.bson.types.ObjectId
import org.testng.Assert.assertEquals
import org.testng.Assert.assertFalse
+import org.testng.Assert.assertNotNull
import org.testng.annotations.Test
+import kotlin.properties.Delegates
class TestKotlinMapping : TestBase() {
@Test
@@ -32,6 +34,19 @@ class TestKotlinMapping : TestBase() {
assertEquals(loaded, versioned)
assertEquals(loaded.version, 1)
}
+
+ @Test
+ fun delegated() {
+ ds.mapper.map(DelegatedNull::class.java)
+ val delegated = DelegatedNull()
+ delegated.status = "I'm all set"
+ ds.save(delegated)
+ val first = ds.find(DelegatedNull::class.java)
+ .first()
+
+ assertNotNull(first)
+ assertEquals(first.status, delegated.status)
+ }
}
@Entity
@@ -39,3 +54,10 @@ private data class MyClass(@Id val id: ObjectId, val value: Int = 0)
@Entity
private data class VersionedDataClass(@Id val id: ObjectId?, val name: String, @Version val version: Long = 0)
+
+@Entity
+private class DelegatedNull {
+ @Id
+ lateinit var id: ObjectId
+ var status: String by Delegates.notNull()
+}
