From b530b3e7fd13409b314968a068159552e6612069 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 30 Jan 2024 14:39:34 +0100 Subject: [PATCH 1/3] Moves MongoStringNestedMapPropertyTest to new file Fixes: OX-10357 --- .../MongoStringNestedMapPropertyTest.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt diff --git a/src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt b/src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt new file mode 100644 index 000000000..70aef10f2 --- /dev/null +++ b/src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt @@ -0,0 +1,63 @@ +/* + * Made with all the love in the world + * by scireum in Remshalden, Germany + * + * Copyright by scireum GmbH + * http://www.scireum.de - info@scireum.de + */ + +package sirius.db.mongo.properties + +import sirius.db.mongo.Mango +import sirius.db.mongo.Mongo +import sirius.kernel.BaseSpecification +import sirius.kernel.di.std.Part + +import java.time.LocalDateTime +import java.time.temporal.ChronoUnit + +class MongoStringNestedMapPropertySpec extends BaseSpecification { + + @Part + private static Mango mango + + @Part + private static Mongo mongo + + def "reading and writing works"() { + when: + def test = new MongoStringNestedMapEntity() + def timestamp = LocalDateTime.now().minusDays(2) + test.getMap().put("X", new MongoStringNestedMapEntity.NestedEntity().withValue1("Y").withValue2(timestamp)) + mango.update(test) + def resolved = mango.refreshOrFail(test) + then: + resolved.getMap().size() == 1 + and: + resolved.getMap().containsKey("X") + resolved.getMap().get("X").get().getValue1() == "Y" + resolved.getMap().get("X").get().getValue2() == timestamp.truncatedTo(ChronoUnit.MILLIS) + + when: + resolved.getMap().modify().get("X").withValue1("ZZZ") + and: + mango.update(resolved) + and: + resolved = mango.refreshOrFail(test) + then: + resolved.getMap().size() == 1 + and: + resolved.getMap().containsKey("X") + resolved.getMap().get("X").get().getValue1() == "ZZZ" + + when: + resolved.getMap().modify().remove("X") + and: + mango.update(resolved) + and: + resolved = mango.refreshOrFail(test) + then: + resolved.getMap().size() == 0 + } + +} From b4a67e175c17ef960df19bdb29ba7cf6f8f804dc Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 30 Jan 2024 14:44:56 +0100 Subject: [PATCH 2/3] Adapts to kotlin syntax Fixes: OX-10357 --- .../MongoStringNestedMapPropertyTest.kt | 84 ++++++++++--------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt b/src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt index 70aef10f2..6fd160de7 100644 --- a/src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt +++ b/src/test/kotlin/sirius/db/mongo/properties/MongoStringNestedMapPropertyTest.kt @@ -8,56 +8,58 @@ 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.BaseSpecification +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 -class MongoStringNestedMapPropertySpec extends BaseSpecification { - - @Part - private static Mango mango - - @Part - private static Mongo mongo - - def "reading and writing works"() { - when: - def test = new MongoStringNestedMapEntity() - def timestamp = LocalDateTime.now().minusDays(2) - test.getMap().put("X", new MongoStringNestedMapEntity.NestedEntity().withValue1("Y").withValue2(timestamp)) - mango.update(test) - def resolved = mango.refreshOrFail(test) - then: - resolved.getMap().size() == 1 - and: - resolved.getMap().containsKey("X") - resolved.getMap().get("X").get().getValue1() == "Y" - resolved.getMap().get("X").get().getValue2() == timestamp.truncatedTo(ChronoUnit.MILLIS) - - when: - resolved.getMap().modify().get("X").withValue1("ZZZ") - and: +@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) - and: - resolved = mango.refreshOrFail(test) - then: - resolved.getMap().size() == 1 - and: - resolved.getMap().containsKey("X") - resolved.getMap().get("X").get().getValue1() == "ZZZ" - - when: - resolved.getMap().modify().remove("X") - and: + 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) - and: - resolved = mango.refreshOrFail(test) - then: - resolved.getMap().size() == 0 + resolved = mango.refreshOrFail(mongoStringNestedMapEntity) + + assertEquals(0, resolved.map.size()) } + companion object { + @Part + private lateinit var mango: Mango + + @Part + private lateinit var mongo: Mongo + } } From ff24d4b72279929150783c975906253528a4ff6f Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 30 Jan 2024 14:45:16 +0100 Subject: [PATCH 3/3] Deletes old MongoStringNestedMapPropertySpec file Fixes: OX-10357 --- .../MongoStringNestedMapPropertySpec.groovy | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/test/java/sirius/db/mongo/properties/MongoStringNestedMapPropertySpec.groovy diff --git a/src/test/java/sirius/db/mongo/properties/MongoStringNestedMapPropertySpec.groovy b/src/test/java/sirius/db/mongo/properties/MongoStringNestedMapPropertySpec.groovy deleted file mode 100644 index 64944baea..000000000 --- a/src/test/java/sirius/db/mongo/properties/MongoStringNestedMapPropertySpec.groovy +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Made with all the love in the world - * by scireum in Remshalden, Germany - * - * Copyright by scireum GmbH - * http://www.scireum.de - info@scireum.de - */ - -package sirius.db.mongo.properties - -import sirius.db.mongo.Mango -import sirius.db.mongo.Mongo -import sirius.kernel.BaseSpecification -import sirius.kernel.di.std.Part - -import java.time.LocalDateTime -import java.time.temporal.ChronoUnit - -class MongoStringNestedMapPropertySpec extends BaseSpecification { - - @Part - private static Mango mango - - @Part - private static Mongo mongo - - def "reading and writing works"() { - when: - def test = new MongoStringNestedMapEntity() - def timestamp = LocalDateTime.now().minusDays(2) - test.getMap().put("X", new MongoStringNestedMapEntity.NestedEntity().withValue1("Y").withValue2(timestamp)) - mango.update(test) - def resolved = mango.refreshOrFail(test) - then: - resolved.getMap().size() == 1 - and: - resolved.getMap().containsKey("X") - resolved.getMap().get("X").get().getValue1() == "Y" - resolved.getMap().get("X").get().getValue2() == timestamp.truncatedTo(ChronoUnit.MILLIS) - - when: - resolved.getMap().modify().get("X").withValue1("ZZZ") - and: - mango.update(resolved) - and: - resolved = mango.refreshOrFail(test) - then: - resolved.getMap().size() == 1 - and: - resolved.getMap().containsKey("X") - resolved.getMap().get("X").get().getValue1() == "ZZZ" - - when: - resolved.getMap().modify().remove("X") - and: - mango.update(resolved) - and: - resolved = mango.refreshOrFail(test) - then: - resolved.getMap().size() == 0 - } - -}