Skip to content

Commit

Permalink
Began work on new “base” test
Browse files Browse the repository at this point in the history
  • Loading branch information
kurbaniec committed Jan 14, 2024
1 parent 0184e42 commit d529a93
Showing 1 changed file with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.beeproduced.bee.persistent.test.base

import com.beeproduced.bee.persistent.blaze.selection.BeeSelection
import com.beeproduced.datasource.test.dsl.RootDSL
import com.beeproduced.datasource.test.onetoone.Branch
import com.beeproduced.datasource.test.onetoone.BranchRepository
import com.beeproduced.datasource.test.onetoone.Root
Expand All @@ -17,6 +19,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.support.TransactionTemplate
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull

/**
*
Expand Down Expand Up @@ -53,6 +58,120 @@ class OneToOneTest(

@Test
fun `select with relations not loaded`() {
// TODO
var rootId: Long = -1
var branchAId: Long
var branchBId: Long
var branchAAId: Long
var branchABId: Long
transaction.executeWithoutResult {
val root = rootRepo.persist(Root())
rootId = root.id
val branchA = branchRepo.persist(Branch())
branchAId = branchA.id
branchBId = branchRepo.persist(Branch()).id
branchAAId = branchRepo.persist(Branch()).id
branchABId = branchRepo.persist(Branch()).id

rootRepo.update(
root.copy(branchAKey = branchAId, branchBKey = branchBId)
)
branchRepo.update(
branchA.copy(branchAKey = branchAAId, branchBKey = branchABId)
)
}

transaction.executeWithoutResult {
val selection = BeeSelection.empty()
// TODO: Replace with selectById
val root = rootRepo.select(selection) {
where(RootDSL.id.eq(rootId))
}.firstOrNull()

assertNotNull(root)
assertNull(root.branchA)
assertNull(root.branchB)
}
}

@Test
fun `select with relations loaded`() {
var rootId: Long = -1
var branchAId: Long = -1
var branchBId: Long = -1
var branchAAId: Long = -1
var branchABId: Long = -1
transaction.executeWithoutResult {
val root = rootRepo.persist(Root())
rootId = root.id
val branchA = branchRepo.persist(Branch())
branchAId = branchA.id
branchBId = branchRepo.persist(Branch()).id
branchAAId = branchRepo.persist(Branch()).id
branchABId = branchRepo.persist(Branch()).id

rootRepo.update(
root.copy(branchAKey = branchAId, branchBKey = branchBId)
)
branchRepo.update(
branchA.copy(branchAKey = branchAAId, branchBKey = branchABId)
)
}

transaction.executeWithoutResult {
val selection = RootDSL.select {
this.branchA {
this.branchA {
this.branchA { }
this.branchB { }
}
this.branchB {
this.branchA { }
this.branchB { }
}
}
this.branchB {
this.branchA {
this.branchA { }
this.branchB { }
}
this.branchB {
this.branchA { }
this.branchB { }
}
}
}

// TODO: Replace with selectById
val root = rootRepo.select(selection) {
where(RootDSL.id.eq(rootId))
}.firstOrNull()

assertNotNull(root)
assertEquals(rootId, root.id)
val branchA = root.branchA
assertNotNull(branchA)
assertEquals(branchAId, branchA.id)
val branchAA = branchA.branchA
assertNotNull(branchAA)
assertEquals(branchAAId, branchAA.id)
assertNull(branchAA.branchA)
assertNull(branchAA.branchB)
val branchAB = branchA.branchB
assertNotNull(branchAB)
assertEquals(branchABId, branchAB.id)
assertNull(branchAB.branchA)
assertNull(branchAB.branchB)

val branchB = root.branchB
assertNotNull(branchB)
assertEquals(branchBId, branchB.id)
assertNull(branchB.branchA)
assertNull(branchB.branchB)
}
}

@Test
fun `select recursive selection`() {

}
}

0 comments on commit d529a93

Please sign in to comment.