Skip to content

Commit

Permalink
tests for nested groups added
Browse files Browse the repository at this point in the history
  • Loading branch information
lumber1000 committed Sep 16, 2024
1 parent b3f3b32 commit d8604e5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
66 changes: 63 additions & 3 deletions src/test/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -372,24 +372,36 @@ class FixNgCodecTest {
)
}

@ParameterizedTest
@ValueSource(booleans = [true, false])
fun `encode nested groups`(isDirty: Boolean) = encodeTest(MSG_NESTED_GROUPS, dirtyMode = isDirty, parsedMessage = parsedMessageWithNestedGroups)

@ParameterizedTest
@ValueSource(booleans = [true, false])
fun `decode nested groups`(isDirty: Boolean) = decodeTest(MSG_NESTED_GROUPS, expectedMessage = parsedMessageWithNestedGroups, dirtyMode = isDirty)

private fun encodeTest(
expectedRawMessage: String,
expectedError: String? = null,
dirtyMode: Boolean,
encodeFromStringValues: Boolean = false
encodeFromStringValues: Boolean = false,
parsedMessage: ParsedMessage = this.parsedMessage
) {
if (dirtyMode) {
encodeTestDirty(expectedRawMessage, expectedError, encodeFromStringValues)
encodeTestDirty(expectedRawMessage, expectedError, parsedMessage, encodeFromStringValues)
} else {
encodeTestNonDirty(expectedRawMessage, expectedError, encodeFromStringValues)
encodeTestNonDirty(expectedRawMessage, expectedError, parsedMessage, encodeFromStringValues)
}
}

private fun encodeTestDirty(
expectedRawMessage: String,
expectedWarning: String? = null,
parsedMessage: ParsedMessage,
encodeFromStringValues: Boolean = false
) {
val parsedBody = parsedMessage.body as MutableMap<String, Any?>

if (encodeFromStringValues) {
@Suppress("UNCHECKED_CAST")
val stringBody = convertValuesToString(parsedBody) as Map<String, Any>
Expand All @@ -410,8 +422,11 @@ class FixNgCodecTest {
private fun encodeTestNonDirty(
expectedRawMessage: String,
expectedError: String? = null,
parsedMessage: ParsedMessage,
encodeFromStringValues: Boolean = false
) {
val parsedBody = parsedMessage.body as MutableMap<String, Any?>

if (encodeFromStringValues) {
@Suppress("UNCHECKED_CAST")
val stringBody = convertValuesToString(parsedBody) as Map<String, Any>
Expand Down Expand Up @@ -645,6 +660,49 @@ class FixNgCodecTest {
)
private val parsedBodyWithNestedComponents: MutableMap<String, Any?> = parsedMessageWithNestedComponents.body as MutableMap

private val parsedMessageWithNestedGroups = ParsedMessage(
MessageId("test_alias", Direction.OUTGOING, 0L, Instant.now(), emptyList()),
EventId("test_id", "test_book", "test_scope", Instant.now()),
"NestedGroupsTestMessage",
mutableMapOf("encode-mode" to "dirty"),
PROTOCOL,
mutableMapOf(
"header" to mutableMapOf(
"BeginString" to "FIXT.1.1",
"BodyLength" to 88,
"MsgType" to "TEST_3",
"MsgSeqNum" to 125,
"TargetCompID" to "INET",
"SenderCompID" to "MZHOT0"
),
"OuterGroup" to mutableMapOf(
"NoOrders" to mutableListOf(
mutableMapOf(
"NestedGroups" to mutableMapOf(
"NoBidDescriptors" to mutableListOf(
mutableMapOf("BidDescriptorType" to 1),
mutableMapOf("BidDescriptorType" to 2),
mutableMapOf("BidDescriptorType" to 3)
)
)
),
mutableMapOf(
"NestedGroups" to mutableMapOf(
"NoBidDescriptors" to mutableListOf(
mutableMapOf("BidDescriptorType" to 3),
mutableMapOf("BidDescriptorType" to 2),
mutableMapOf("BidDescriptorType" to 1)
)
)
)
)
),
"trailer" to mapOf(
"CheckSum" to "211"
)
)
)

companion object {
private const val DIRTY_MODE_WARNING_PREFIX = "Dirty mode WARNING: "

Expand Down Expand Up @@ -672,5 +730,7 @@ class FixNgCodecTest {
private const val MSG_NESTED_OPT_COMPONENTS_MISSED_ALL_FIELDS = "8=FIXT.1.19=5935=TEST_249=MZHOT056=INET34=125151=123410=191"
private const val MSG_NESTED_OPT_COMPONENTS_MISSED_ALL_FIELDS_INNER_AND_OUTER = "8=FIXT.1.19=5935=TEST_249=MZHOT056=INET34=12510=191"
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"
}
}
18 changes: 17 additions & 1 deletion src/test/resources/dictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7272,6 +7272,12 @@
<attribute name="fixtype" type="java.lang.String">NUMINGROUP</attribute>
<field name="BidDescriptorType" reference="field-BidDescriptorType"/>
</message>
<message name="OuterGroup_NoOrders" id="group-OuterGroup-NoOrders">
<attribute name="entity_type" type="java.lang.String">Group</attribute>
<attribute name="tag" type="java.lang.Integer">73</attribute>
<attribute name="fixtype" type="java.lang.String">NUMINGROUP</attribute>
<field name="NestedGroups" reference="component-BidDescReqGrp" isCollection="true"/>
</message>
<message name="NewOrderSingle">
<attribute name="entity_type" type="java.lang.String">Message</attribute>
<attribute name="IsAdmin" type="java.lang.Boolean">false</attribute>
Expand Down Expand Up @@ -7373,6 +7379,12 @@
<attribute name="MessageType" type="java.lang.String">TEST_2</attribute>
<field name="OuterComponent" reference="component-OuterComponent"/>
</message>
<message name="NestedGroupsTestMessage">
<attribute name="entity_type" type="java.lang.String">Message</attribute>
<attribute name="IsAdmin" type="java.lang.Boolean">false</attribute>
<attribute name="MessageType" type="java.lang.String">TEST_3</attribute>
<field name="OuterGroup" reference="component-OuterGroup"/>
</message>
<message id="component-OuterComponent" name="OuterComponent">
<attribute name="entity_type" type="java.lang.String">Component</attribute>
<field name="InnerComponent" reference="component-InnerComponent" required="true"/>
Expand Down Expand Up @@ -7400,6 +7412,10 @@
<attribute name="entity_type" type="java.lang.String">Component</attribute>
<field name="NoBidDescriptors" reference="group-BidDescReqGrp_NoBidDescriptors" isCollection="true"/>
</message>
<message id="component-OuterGroup" name="OuterGroup">
<attribute name="entity_type" type="java.lang.String">Component</attribute>
<field name="NoOrders" reference="group-OuterGroup-NoOrders" isCollection="true" required="true"/>
</message>
<message id="header" name="header">
<attribute name="entity_type" type="java.lang.String">Header</attribute>
<field name="BeginString" reference="field-BeginString" required="true"/>
Expand Down Expand Up @@ -7491,4 +7507,4 @@
<field name="trailer" reference="trailer" required="true"/>
</message>
</messages>
</dictionary>
</dictionary>

0 comments on commit d8604e5

Please sign in to comment.