Skip to content

Commit

Permalink
Working on splitting BeePersistentTestA & BeePersistentTestB into…
Browse files Browse the repository at this point in the history
… multiple test classes

Added `SelectOrderByATest`.
  • Loading branch information
kurbaniec committed Jan 15, 2024
1 parent 10c89f2 commit 3b4f18e
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class BeePersistentTestA(
}
} */

@Test
/* @Test
fun `test where`() {
transaction.executeWithoutResult {
val id1 = UUID.randomUUID()
Expand Down Expand Up @@ -595,10 +595,10 @@ class BeePersistentTestA(
println("baum")
}
}
} */


@Test
/* @Test
fun `more where`() {
val clazz = Foxtrot::class.java
val method = clazz.getDeclaredMethod("unbox-impl")
Expand Down Expand Up @@ -658,7 +658,7 @@ class BeePersistentTestA(
// assertEquals(fooBar, w.fooBar)
// assertEquals(foxtrot, w.foxtrot)
}
}
} */

/* fun addSong() {
transaction.executeWithoutResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.beeproduced.bee.persistent.test.select

import com.beeproduced.bee.persistent.test.config.ATestConfig
import com.beeproduced.datasource.a.*
import com.beeproduced.datasource.a.dsl.WeirdClassDSL
import jakarta.persistence.EntityManager
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.support.TransactionTemplate
import java.util.*
import kotlin.test.Test
import kotlin.test.assertEquals

/**
*
*
* @author Kacper Urbaniec
* @version 2024-01-15
*/
@ExtendWith(SpringExtension::class)
@SpringBootTest(classes = [ATestConfig::class])
@TestPropertySource("classpath:application.properties")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SelectOrderByATest(
@Qualifier("aEM")
val em: EntityManager,
@Qualifier("aTM")
transactionManager: PlatformTransactionManager,
@Autowired
val weirdRepo: WeirdClassRepository
) {
private val transaction = TransactionTemplate(transactionManager)

@BeforeAll
fun beforeAll() = clear()

@AfterEach
fun afterEach() = clear()

fun clear() {
transaction.executeWithoutResult {
weirdRepo.cbf.delete(em, WeirdClass::class.java).executeUpdate()
}
}

@Test
fun `order by asc`() {
transaction.executeWithoutResult {
val id = UUID.randomUUID()
val fooBar = FooBar("foo", "bar")
val foxtrot = Foxtrot("Foxtrot")
weirdRepo.persist(WeirdClass(id, fooBar, foxtrot))
val id2 = UUID.randomUUID()
val fooBar2 = FooBar("foo", "bar2")
val foxtrot2 = Foxtrot("Foxtrot2")
weirdRepo.persist(WeirdClass(id2, fooBar2, foxtrot2))
val id3 = UUID.randomUUID()
val fooBar3 = FooBar("foo", "bar3")
val foxtrot3 = Foxtrot("Foxtrot3")
weirdRepo.persist(WeirdClass(id3, fooBar3, foxtrot3))

val ws = weirdRepo.select {
orderBy(WeirdClassDSL.foxtrot.asc())
}
assertEquals(id, ws[0].id)
assertEquals(id2, ws[1].id)
assertEquals(id3, ws[2].id)
}
}

@Test
fun `order by desc`() {
transaction.executeWithoutResult {
val id = UUID.randomUUID()
val fooBar = FooBar("foo", "bar")
val foxtrot = Foxtrot("Foxtrot")
weirdRepo.persist(WeirdClass(id, fooBar, foxtrot))
val id2 = UUID.randomUUID()
val fooBar2 = FooBar("foo", "bar2")
val foxtrot2 = Foxtrot("Foxtrot2")
weirdRepo.persist(WeirdClass(id2, fooBar2, foxtrot2))
val id3 = UUID.randomUUID()
val fooBar3 = FooBar("foo", "bar3")
val foxtrot3 = Foxtrot("Foxtrot3")
weirdRepo.persist(WeirdClass(id3, fooBar3, foxtrot3))

val ws = weirdRepo.select {
orderBy(WeirdClassDSL.foxtrot.desc())
}
assertEquals(id3, ws[0].id)
assertEquals(id2, ws[1].id)
assertEquals(id, ws[2].id)
}
}

@Test
fun `order by multiple columns desc`() {
transaction.executeWithoutResult {
val id = UUID.randomUUID()
val fooBar = FooBar("foo", "bar")
val foxtrot = Foxtrot("Foxtrot")
weirdRepo.persist(WeirdClass(id, fooBar, foxtrot))
val id2 = UUID.randomUUID()
val fooBar2 = FooBar("foo", "bar2")
val foxtrot2 = Foxtrot("FoxtrotDuplicate")
weirdRepo.persist(WeirdClass(id2, fooBar2, foxtrot2))
val id3 = UUID.randomUUID()
val fooBar3 = FooBar("foo", "bar3")
val foxtrot3 = Foxtrot("FoxtrotDuplicate")
weirdRepo.persist(WeirdClass(id3, fooBar3, foxtrot3))

val ws = weirdRepo.select {
orderBy(
WeirdClassDSL.foxtrot.desc(),
WeirdClassDSL.fooBar.desc()
)
}
assertEquals(id3, ws[0].id)
assertEquals(id2, ws[1].id)
assertEquals(id, ws[2].id)
}
}
}

0 comments on commit 3b4f18e

Please sign in to comment.