From 91730deec8ce7c763a681488c274b7948f430e18 Mon Sep 17 00:00:00 2001 From: vince Date: Mon, 8 Jul 2024 14:39:08 +0800 Subject: [PATCH] test internal changed properties for nested binding --- .../kotlin/org/ktorm/entity/EntityTest.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ktorm-core/src/test/kotlin/org/ktorm/entity/EntityTest.kt b/ktorm-core/src/test/kotlin/org/ktorm/entity/EntityTest.kt index a89f95f5..5fc753a3 100644 --- a/ktorm-core/src/test/kotlin/org/ktorm/entity/EntityTest.kt +++ b/ktorm-core/src/test/kotlin/org/ktorm/entity/EntityTest.kt @@ -315,10 +315,41 @@ class EntityTest : BaseTest() { companion object : Entity.Factory() var id: Int? var name: String? + var job: String? } object Parents : Table("t_employee") { val id = int("id").primaryKey().bindTo { it.child?.grandChild?.id } + val name = varchar("name").bindTo { it.child?.grandChild?.name } + val job = varchar("job").bindTo { it.child?.grandChild?.job } + } + + @Test + fun testInternalChangedPropertiesForNestedBinding1() { + val p1 = database.sequenceOf(Parents).find { it.id eq 1 } ?: throw AssertionError() + p1.child?.grandChild?.job = "Senior Engineer" + p1.child?.grandChild?.job = "Expert Engineer" + + assert(p1.implementation.changedProperties.size == 0) + assert(p1.child?.implementation?.changedProperties?.size == 0) + assert(p1.child?.grandChild?.implementation?.changedProperties?.size == 1) + assert(p1.child?.grandChild?.implementation?.changedProperties?.get("job") == "engineer") + assert(p1.flushChanges() == 1) + } + + @Test + fun testInternalChangedPropertiesForNestedBinding2() { + val p2 = database.sequenceOf(Parents).find { it.id eq 1 } ?: throw AssertionError() + p2.child?.grandChild?.name = "Vincent" + p2.child?.grandChild?.job = "Senior Engineer" + p2.child?.grandChild?.job = "Expert Engineer" + + assert(p2.implementation.changedProperties.size == 0) + assert(p2.child?.implementation?.changedProperties?.size == 0) + assert(p2.child?.grandChild?.implementation?.changedProperties?.size == 2) + assert(p2.child?.grandChild?.implementation?.changedProperties?.get("name") == "vince") + assert(p2.child?.grandChild?.implementation?.changedProperties?.get("job") == "engineer") + assert(p2.flushChanges() == 1) } @Test