test: GTDT e2e, v2 write-path guards, and PG test env support

Add JacksonXmlCodec/GtdtHandler/Pipeline tests, PgTestSupport for MSGX_PG_*,
and update smoke/poller expectations for real decode semantics.
This commit is contained in:
windyboy
2026-09-08 11:26:21 +08:00
parent a936238368
commit c432492a81
13 changed files with 688 additions and 33 deletions
@@ -0,0 +1,109 @@
package com.gzzn.omms.msgexchange.domain.flight
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
class FlightStateEngineTest {
@Test
fun `scalar unchanged does not modify existing value`() {
val current = FlightNextState("F1", mapOf("FLNO" to "CA100"), emptyMap(), 1L, "m1")
val next = FlightStateEngine.apply(
current,
FlightFieldCommands("F1", scalars = emptyMap()),
"m2",
bumpVersion = true,
)
assertEquals("CA100", next.scalars["FLNO"])
assertEquals(2L, next.stateVersion)
}
@Test
fun `collection replace preserves order and source sequence`() {
val items = listOf(
mapOf("GTNO" to "1", "GATE" to "A1"),
mapOf("GTNO" to "3", "GATE" to "B2"),
mapOf("GTNO" to "7", "GATE" to "C3"),
)
val next = FlightStateEngine.apply(
null,
FlightFieldCommands("F1", collections = mapOf("GTDT" to CollectionCommand.Replace(items))),
"m1",
bumpVersion = true,
)
assertEquals(3, next.collections["GTDT"]!!.size)
assertEquals("3", next.collections["GTDT"]!![1]["GTNO"])
assertEquals("C3", next.collections["GTDT"]!![2]["GATE"])
}
@Test
fun `collection clear removes prior entries`() {
val current = FlightNextState(
"F1",
emptyMap(),
mapOf("GTDT" to listOf(mapOf("GTNO" to "1", "GATE" to "A1"))),
1L,
"m1",
)
val next = FlightStateEngine.apply(
current,
FlightFieldCommands("F1", collections = mapOf("GTDT" to CollectionCommand.Clear)),
"m2",
bumpVersion = true,
)
assertFalse(next.collections.containsKey("GTDT"))
}
@Test
fun `same gate number different attributes both retained on replace`() {
val items = listOf(
mapOf("GTNO" to "1", "GATE" to "A1", "GTYP" to "D"),
mapOf("GTNO" to "1", "GATE" to "A1", "GTYP" to "I"),
)
val next = FlightStateEngine.apply(
null,
FlightFieldCommands("F1", collections = mapOf("GTDT" to CollectionCommand.Replace(items))),
"m1",
bumpVersion = true,
)
assertEquals("D", next.collections["GTDT"]!![0]["GTYP"])
assertEquals("I", next.collections["GTDT"]!![1]["GTYP"])
}
@Test
fun `incremental apply bumps state version from persisted value`() {
val current = FlightNextState("F1", mapOf("FLNO" to "CA100"), emptyMap(), 5L, "m1")
val next = FlightStateEngine.apply(
current,
FlightFieldCommands("F1", scalars = mapOf("STAT" to ScalarCommand.Set("DEP"))),
"m2",
bumpVersion = true,
)
assertEquals(6L, next.stateVersion)
}
@Test
fun `apply by source sequence updates single row`() {
val current = FlightNextState(
"F1",
emptyMap(),
mapOf("GTDT" to listOf(mapOf("GTNO" to "2", "GATE" to "OLD"))),
1L,
"m1",
)
val next = FlightStateEngine.apply(
current,
FlightFieldCommands(
"F1",
collections = mapOf(
"GTDT" to CollectionCommand.Apply(mapOf("GTNO" to "2", "GATE" to "NEW"), "2"),
),
),
"m2",
bumpVersion = true,
)
assertEquals("NEW", next.collections["GTDT"]!![0]["GATE"])
}
}