Skip to content

Commit

Permalink
Merge pull request #631 from scireum/feature/mbo/OX-10357-6
Browse files Browse the repository at this point in the history
JUnit: Migrate UpdateStatementTest to Kotlin
  • Loading branch information
scireum-mbo authored Feb 6, 2024
2 parents f9244ed + 62a42de commit e114b34
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 73 deletions.
73 changes: 0 additions & 73 deletions src/test/java/sirius/db/jdbc/UpdateStatementSpec.groovy

This file was deleted.

77 changes: 77 additions & 0 deletions src/test/kotlin/sirius/db/jdbc/UpdateStatementTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/

package sirius.db.jdbc

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import sirius.kernel.SiriusExtension
import sirius.kernel.di.std.Part
import kotlin.test.assertEquals

@ExtendWith(SiriusExtension::class)
class UpdateStatementTest {
@Test
fun `an update statement updates the expected entities`() {
val generatedStatementTestEntity1 = GeneratedStatementTestEntity()
generatedStatementTestEntity1.testNumber = 1
generatedStatementTestEntity1.value = "2"
oma.update(generatedStatementTestEntity1)

val generatedStatementTestEntity2 = GeneratedStatementTestEntity()
generatedStatementTestEntity2.testNumber = 3
generatedStatementTestEntity2.value = "4"
oma.update(generatedStatementTestEntity2)

val changes = oma.updateStatement(
GeneratedStatementTestEntity::class.java
).set(GeneratedStatementTestEntity.VALUE, "5")
.where(GeneratedStatementTestEntity.TEST_NUMBER, 1).executeUpdate()

assertEquals(1, changes)
assertEquals("5", oma.refreshOrFail(generatedStatementTestEntity1).value)
assertEquals("4", oma.refreshOrFail(generatedStatementTestEntity2).value)
}

@Test
fun `an update statement reports illegal use (set after where)`() {
assertThrows<IllegalStateException> {
oma.updateStatement(
GeneratedStatementTestEntity::class.java
).where(GeneratedStatementTestEntity.TEST_NUMBER, 1)
.set(GeneratedStatementTestEntity.VALUE, "5").executeUpdate()
}
}

@Test
fun `an update statement ignores an empty update without errors`() {
val changes = oma.updateStatement(GeneratedStatementTestEntity::class.java).where(
GeneratedStatementTestEntity.TEST_NUMBER,
1
).executeUpdate()

assertEquals(0, changes)
}

@Test
fun `an update statement detects and reports join columns as errors`() {
assertThrows<IllegalArgumentException> {
oma.updateStatement(
SmartQueryTestChildEntity::class.java
).set(SmartQueryTestChildEntity.NAME, "X")
.where(SmartQueryTestChildEntity.PARENT.join(SmartQueryTestParentEntity.NAME), 1)
.executeUpdate()
}
}

companion object {
@Part
private lateinit var oma: OMA
}
}

0 comments on commit e114b34

Please sign in to comment.