From 6fcee5f57b5d410b85ca59647e5a324e9979420f Mon Sep 17 00:00:00 2001 From: Nikita Smirnov <46124551+Nikita-Smirnov-Exactpro@users.noreply.github.com> Date: Thu, 19 Dec 2024 18:22:42 +0400 Subject: [PATCH] [TH2-5265] fixed: codec can't encode fields with type `LocalDateTime`, `LocalDate`, `LocalTime` and value with timezone (#13) * Updated sailfish: `3.4.260` --- README.md | 6 +++- gradle.properties | 2 +- .../exactpro/th2/codec/fixng/FixNgCodec.kt | 7 ++-- .../th2/codec/fixng/FixNgCodecTest.kt | 35 +++++++++++++++++++ src/test/resources/dictionary.xml | 10 +++++- 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 348e836..c412836 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# th2-codec-fix-ng 0.1.1 +# th2-codec-fix-ng 0.1.2 This codec can be used in dirty mode for decoding and encoding messages via the FIX protocol. @@ -47,6 +47,10 @@ Component benchmark results available [here](docs/benchmarks/jmh-benchmark.md). ## Release notes +### 0.1.2 + + fixed: codec can't encode fields with type `LocalDateTime`, `LocalDate`, `LocalTime` and value with timezone + + Updated sailfish: `3.4.260` + ### 0.1.1 + `decodeDelimiter` setting option added. + Updated th2 gradle plugin `0.1.6` (th2-bom: `4.9.0`) diff --git a/gradle.properties b/gradle.properties index 2ca9ee4..9772d47 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ kotlin.code.style=official kotlin_version=1.8.22 -release_version=0.1.1 +release_version=0.1.2 vcs_url=https://github.com/th2-net/th2-codec-fix-ng \ No newline at end of file diff --git a/src/main/kotlin/com/exactpro/th2/codec/fixng/FixNgCodec.kt b/src/main/kotlin/com/exactpro/th2/codec/fixng/FixNgCodec.kt index e1f04cb..441b707 100644 --- a/src/main/kotlin/com/exactpro/th2/codec/fixng/FixNgCodec.kt +++ b/src/main/kotlin/com/exactpro/th2/codec/fixng/FixNgCodec.kt @@ -23,6 +23,7 @@ import com.exactpro.sf.common.messages.structures.IDictionaryStructure import com.exactpro.sf.common.messages.structures.IFieldStructure import com.exactpro.sf.common.messages.structures.IMessageStructure import com.exactpro.sf.common.messages.structures.StructureUtils +import com.exactpro.sf.comparison.conversion.MultiConverter import com.exactpro.th2.codec.api.IPipelineCodec import com.exactpro.th2.codec.api.IReportingContext import com.exactpro.th2.codec.fixng.FixNgCodecFactory.Companion.PROTOCOL @@ -356,9 +357,9 @@ class FixNgCodec(dictionary: IDictionaryStructure, settings: FixNgCodecSettings) value is String -> { try { when (field.primitiveType) { - LocalDateTime::class.java -> LocalDateTime.parse(value) - LocalDate::class.java -> LocalDate.parse(value) - LocalTime::class.java -> LocalTime.parse(value) + LocalDateTime::class.java -> MultiConverter.convert(value, LocalDateTime::class.java) + LocalDate::class.java -> MultiConverter.convert(value, LocalDate::class.java) + LocalTime::class.java -> MultiConverter.convert(value, LocalTime::class.java) java.lang.Boolean::class.java -> when { value.equals("true", true) -> true value.equals("false", true) -> false diff --git a/src/test/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecTest.kt b/src/test/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecTest.kt index 100d096..a11c355 100644 --- a/src/test/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecTest.kt +++ b/src/test/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecTest.kt @@ -534,6 +534,15 @@ class FixNgCodecTest { expectedMessage = parsedMessageWithNestedGroups ) + @ParameterizedTest + @MethodSource("configs") + fun `encode time zone`(isDirty: Boolean, delimiter: Char) = encodeTest( + MSG_TIME_ZONE, + isDirty, + delimiter, + parsedMessage = parsedMessageWithTimezone + ) + private fun createCodec(delimiter: Char = '', decodeValuesToStrings: Boolean = false): FixNgCodec { return FixNgCodec(dictionary, FixNgCodecSettings( dictionary = "", @@ -873,6 +882,31 @@ class FixNgCodecTest { ) ) + private val parsedMessageWithTimezone = ParsedMessage( + MessageId("test_alias", Direction.OUTGOING, 0L, Instant.now(), emptyList()), + EventId("test_id", "test_book", "test_scope", Instant.now()), + "TimeZoneTestMessage", + mutableMapOf("encode-mode" to "dirty"), + PROTOCOL, + mutableMapOf( + "header" to mutableMapOf( + "MsgSeqNum" to 10947, + "SenderCompID" to "SENDER", + "SendingTime" to "2023-04-19T10:36:07.415088Z", + "TargetCompID" to "RECEIVER", + "BeginString" to "FIXT.1.1", + "BodyLength" to 295, + "MsgType" to "TEST_4" + ), + "TransactTime" to "2018-02-05T10:38:08.000008Z", + "TotalVolumeTradedDate" to "2018-02-05Z", + "TotalVolumeTradedTime" to "10:38:08.000008Z", + "trailer" to mutableMapOf( + "CheckSum" to "122" + ) + ) + ) + companion object { private const val DIRTY_MODE_WARNING_PREFIX = "Dirty mode WARNING: " @@ -902,6 +936,7 @@ class FixNgCodecTest { private const val MSG_NESTED_OPT_COMPONENTS_MISSED_ALL_OUTER_FIELDS_AND_REQ_INNER_FIELD = "8=FIXT.1.19=5935=TEST_249=MZHOT056=INET34=12558=text_110=191" private const val MSG_NESTED_GROUPS = "8=FIXT.1.19=8835=TEST_349=MZHOT056=INET34=12573=2398=3399=1399=2399=3398=3399=3399=2399=110=211" + private const val MSG_TIME_ZONE = "8=FIXT.1.19=12335=TEST_449=SENDER56=RECEIVER34=1094752=20230419-10:36:07.41508860=20180205-10:38:08.000008449=20180205450=10:38:0810=206" @JvmStatic fun configs() = listOf( diff --git a/src/test/resources/dictionary.xml b/src/test/resources/dictionary.xml index f682a15..640beb6 100644 --- a/src/test/resources/dictionary.xml +++ b/src/test/resources/dictionary.xml @@ -1,5 +1,5 @@