95 lines
3.2 KiB
Kotlin
95 lines
3.2 KiB
Kotlin
package com.gzzn.omms.msgexchange.codec
|
|||
|
|
|
||
|
|
import com.gzzn.omms.msgexchange.domain.MsgKind
|
||
|
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||
|
|
import org.junit.jupiter.api.Assertions.assertInstanceOf
|
||
|
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||
|
|
import org.junit.jupiter.api.Test
|
||
|
|
|
||
|
|
class JacksonXmlCodecTest {
|
||
|
|
|
||
|
|
private val codec = JacksonXmlCodec()
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `decode AODBGTDT sample extracts META and three gates`() {
|
||
|
|
val raw = """
|
||
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
|
<MSG>
|
||
|
|
<META>
|
||
|
|
<SNDR>AODB</SNDR>
|
||
|
|
<SEQN>1243</SEQN>
|
||
|
|
<DTTM>20021010090311</DTTM>
|
||
|
|
<TYPE>FLOP</TYPE>
|
||
|
|
<STYP>GTDT</STYP>
|
||
|
|
</META>
|
||
|
|
<FLOP>
|
||
|
|
<FLID>121112312</FLID>
|
||
|
|
<FFID>CA-CA101-A-12DEC031345-D</FFID>
|
||
|
|
<GTDT GTNO="1">
|
||
|
|
<GATE>G28</GATE>
|
||
|
|
<PGOT>15DEC031805</PGOT>
|
||
|
|
<PGCT>15DEC031925</PGCT>
|
||
|
|
<GOTM>15DEC031825</GOTM>
|
||
|
|
<GTYP>D</GTYP>
|
||
|
|
</GTDT>
|
||
|
|
<GTDT GTNO="2">
|
||
|
|
<GATE>G33</GATE>
|
||
|
|
<PGOT>15DEC031805</PGOT>
|
||
|
|
<PGCT>15DEC031925</PGCT>
|
||
|
|
<GTYP>I</GTYP>
|
||
|
|
</GTDT>
|
||
|
|
<GTDT GTNO="3">
|
||
|
|
<GATE>G23</GATE>
|
||
|
|
<PGOT>15DEC031805</PGOT>
|
||
|
|
<PGCT>15DEC031925</PGCT>
|
||
|
|
<GTYP>D</GTYP>
|
||
|
|
</GTDT>
|
||
|
|
</FLOP>
|
||
|
|
</MSG>
|
||
|
|
""".trimIndent()
|
||
|
|
|
||
|
|
val result = codec.decode(raw)
|
||
|
|
assertInstanceOf(DecodeResult.Ok::class.java, result)
|
||
|
|
val msg = (result as DecodeResult.Ok).message
|
||
|
|
assertEquals(MsgKind.Flop("GTDT"), msg.kind)
|
||
|
|
assertEquals("AODB", msg.meta.sndr)
|
||
|
|
assertEquals(1243L, msg.meta.seqn)
|
||
|
|
|
||
|
|
val body = msg.body as FlopPayload
|
||
|
|
assertEquals("121112312", body.flid)
|
||
|
|
assertEquals("CA-CA101-A-12DEC031345-D", body.scalars["FFID"])
|
||
|
|
assertEquals(3, body.collections["GTDT"]!!.size)
|
||
|
|
assertEquals("G28", body.collections["GTDT"]!![0]["GATE"])
|
||
|
|
assertEquals("1", body.collections["GTDT"]!![0]["GTNO"])
|
||
|
|
assertEquals("G33", body.collections["GTDT"]!![1]["GATE"])
|
||
|
|
assertEquals("3", body.collections["GTDT"]!![2]["GTNO"])
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `decode GTNO zero marks gate clear snapshot`() {
|
||
|
|
val raw = """
|
||
|
|
<MSG>
|
||
|
|
<META>
|
||
|
|
<SNDR>AODB</SNDR><SEQN>1</SEQN><DTTM>20021010090311</DTTM>
|
||
|
|
<TYPE>FLOP</TYPE><STYP>GTDT</STYP>
|
||
|
|
</META>
|
||
|
|
<FLOP>
|
||
|
|
<FLID>F_CLEAR</FLID>
|
||
|
|
<GTDT GTNO="0"></GTDT>
|
||
|
|
</FLOP>
|
||
|
|
</MSG>
|
||
|
|
""".trimIndent()
|
||
|
|
|
||
|
|
val msg = (codec.decode(raw) as DecodeResult.Ok).message
|
||
|
|
val body = msg.body as FlopPayload
|
||
|
|
assertEquals(listOf(mapOf("GTNO" to "0")), body.collections["GTDT"])
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `malformed xml returns MALFORMED not CODEC_ERROR`() {
|
||
|
|
val err = codec.decode("not-xml") as DecodeResult.Err
|
||
|
|
assertEquals(com.gzzn.omms.msgexchange.domain.ErrorClass.MALFORMED, err.failure.errorClass)
|
||
|
|
assertTrue(err.failure.detail.contains("empty-or-non-xml"))
|
||
|
|
}
|
||
|
|
}
|