-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from scireum/feature/mbo/OX-10357-7
JUnit: Migrate MongoStringNestedMapPropertyTest to Kotlin
- Loading branch information
Showing
2 changed files
with
65 additions
and
63 deletions.
There are no files selected for viewing
63 changes: 0 additions & 63 deletions
63
src/test/java/sirius/db/mongo/properties/MongoStringNestedMapPropertySpec.groovy
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.mongo.properties | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import sirius.db.mongo.Mango | ||
import sirius.db.mongo.Mongo | ||
import sirius.kernel.SiriusExtension | ||
import sirius.kernel.di.std.Part | ||
|
||
import java.time.LocalDateTime | ||
import java.time.temporal.ChronoUnit | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
@ExtendWith(SiriusExtension::class) | ||
class MongoStringNestedMapPropertyTest { | ||
@Test | ||
fun `reading and writing works`() { | ||
|
||
val mongoStringNestedMapEntity = MongoStringNestedMapEntity() | ||
val timestamp = LocalDateTime.now().minusDays(2) | ||
mongoStringNestedMapEntity.map.put( | ||
"X", | ||
MongoStringNestedMapEntity.NestedEntity().withValue1("Y").withValue2(timestamp) | ||
) | ||
mango.update(mongoStringNestedMapEntity) | ||
var resolved = mango.refreshOrFail(mongoStringNestedMapEntity) | ||
|
||
assertEquals(1, resolved.map.size()) | ||
|
||
assertTrue { resolved.map.containsKey("X") } | ||
assertEquals("Y", resolved.map.get("X").get().value1) | ||
assertEquals(timestamp.truncatedTo(ChronoUnit.MILLIS), resolved.map.get("X").get().value2) | ||
|
||
resolved.map.modify()["X"]?.withValue1("ZZZ") | ||
mango.update(resolved) | ||
resolved = mango.refreshOrFail(mongoStringNestedMapEntity) | ||
|
||
assertEquals(1, resolved.map.size()) | ||
assertTrue { resolved.map.containsKey("X") } | ||
assertEquals("ZZZ", resolved.map.get("X").get().value1) | ||
|
||
resolved.map.modify().remove("X") | ||
mango.update(resolved) | ||
resolved = mango.refreshOrFail(mongoStringNestedMapEntity) | ||
|
||
assertEquals(0, resolved.map.size()) | ||
} | ||
|
||
companion object { | ||
@Part | ||
private lateinit var mango: Mango | ||
|
||
@Part | ||
private lateinit var mongo: Mongo | ||
} | ||
} |