Skip to content

Commit

Permalink
test internal changed properties for nested binding
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlauvlwj committed Jul 8, 2024
1 parent 8f0390e commit 91730de
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ktorm-core/src/test/kotlin/org/ktorm/entity/EntityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,41 @@ class EntityTest : BaseTest() {
companion object : Entity.Factory<GrandChild>()
var id: Int?
var name: String?
var job: String?
}

object Parents : Table<Parent>("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
Expand Down

0 comments on commit 91730de

Please sign in to comment.