Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataDictionary: removed check for empty message body #735

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions quickfixj-base/src/main/java/quickfix/DataDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ private void load(InputStream inputStream, DocumentBuilderFactory factory) throw
private int getIntegerAttributeIfDefined(final Element documentElement, final String attribute) throws ConfigError {
try {
return documentElement.hasAttribute(attribute)
? Integer.valueOf(documentElement.getAttribute(attribute)) : 0;
? Integer.parseInt(documentElement.getAttribute(attribute)) : 0;
} catch (NumberFormatException e) {
throw new ConfigError("Attribute " + attribute + " could not be parsed as Integer.", e);
}
Expand All @@ -1168,8 +1168,9 @@ public int getNumMessageCategories() {
private void load(Document document, String msgtype, Node node) throws ConfigError {
String name;
final NodeList fieldNodes = node.getChildNodes();
if (countElementNodes(fieldNodes) == 0) {
throw new ConfigError("No fields found: msgType=" + msgtype);

if (countElementNodes(fieldNodes) == 0 && (msgtype == HEADER_ID || msgtype == TRAILER_ID)) {
throw new ConfigError("No fields found in " + msgtype);
}

for (int j = 0; j < fieldNodes.getLength(); j++) {
Expand Down
114 changes: 4 additions & 110 deletions quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,59 +205,6 @@ public void testHeaderTrailerRequired() throws Exception {
assertFalse("Unknown trailer field shows up as required", dd.isRequiredTrailerField(666));
}

@Test
public void testMessageWithNoChildren40() throws Exception {
String data = "";
data += "<fix major=\"4\" minor=\"0\">";
data += " <header>";
data += " <field name=\"BeginString\" required=\"Y\"/>";
data += " </header>";
data += " <trailer>";
data += " <field name=\"CheckSum\" required=\"Y\"/>";
data += " </trailer>";
data += " <fields>";
data += " <field number=\"1\" name=\"Account\" type=\"STRING\"/>";
data += " <field number=\"8\" name=\"BeginString\" type=\"STRING\"/>";
data += " <field number=\"10\" name=\"CheckSum\" type=\"STRING\"/>";
data += " </fields>";
data += " <messages>";
data += " <message name=\"MessageWithNoChildren\" msgtype=\"msg\" msgcat=\"custom\"/>";
data += " </messages>";
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=msg");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}

@Test
public void testMessageWithTextElement40() throws Exception {
String data = "";
data += "<fix major=\"4\" minor=\"0\">";
data += " <header>";
data += " <field name=\"BeginString\" required=\"Y\"/>";
data += " </header>";
data += " <trailer>";
data += " <field name=\"CheckSum\" required=\"Y\"/>";
data += " </trailer>";
data += " <fields>";
data += " <field number=\"1\" name=\"Account\" type=\"STRING\"/>";
data += " <field number=\"8\" name=\"BeginString\" type=\"STRING\"/>";
data += " <field number=\"10\" name=\"CheckSum\" type=\"STRING\"/>";
data += " </fields>";
data += " <messages>";
data += " <message name=\"MessageWithNoChildren\" msgtype=\"msg\" msgcat=\"custom\">";
data += " </message>";
data += " </messages>";
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=msg");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}

@Test
public void testMessagesWithNoChildren40() throws Exception {
String data = "";
Expand Down Expand Up @@ -328,7 +275,7 @@ public void testHeaderWithNoChildren40() throws Exception {
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=HEADER");
expectedException.expectMessage("No fields found in HEADER");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}
Expand All @@ -355,7 +302,7 @@ public void testHeaderWithTextElement40() throws Exception {
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=HEADER");
expectedException.expectMessage("No fields found in HEADER");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}
Expand All @@ -381,7 +328,7 @@ public void testTrailerWithNoChildren40() throws Exception {
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=TRAILER");
expectedException.expectMessage("No fields found in TRAILER");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}
Expand All @@ -408,7 +355,7 @@ public void testTrailerWithTextElement40() throws Exception {
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=TRAILER");
expectedException.expectMessage("No fields found in TRAILER");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}
Expand Down Expand Up @@ -462,59 +409,6 @@ public void testFieldsWithTextElement40() throws Exception {
new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}

@Test
public void testMessageWithNoChildren50() throws Exception {
String data = "";
data += "<fix major=\"5\" minor=\"0\">";
data += " <header>";
data += " <field name=\"BeginString\" required=\"Y\"/>";
data += " </header>";
data += " <trailer>";
data += " <field name=\"CheckSum\" required=\"Y\"/>";
data += " </trailer>";
data += " <fields>";
data += " <field number=\"1\" name=\"Account\" type=\"STRING\"/>";
data += " <field number=\"8\" name=\"BeginString\" type=\"STRING\"/>";
data += " <field number=\"10\" name=\"CheckSum\" type=\"STRING\"/>";
data += " </fields>";
data += " <messages>";
data += " <message name=\"MessageWithNoChildren\" msgtype=\"msg\" msgcat=\"custom\"/>";
data += " </messages>";
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=msg");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}

@Test
public void testMessageWithTextElement50() throws Exception {
String data = "";
data += "<fix major=\"5\" minor=\"0\">";
data += " <header>";
data += " <field name=\"BeginString\" required=\"Y\"/>";
data += " </header>";
data += " <trailer>";
data += " <field name=\"CheckSum\" required=\"Y\"/>";
data += " </trailer>";
data += " <fields>";
data += " <field number=\"1\" name=\"Account\" type=\"STRING\"/>";
data += " <field number=\"8\" name=\"BeginString\" type=\"STRING\"/>";
data += " <field number=\"10\" name=\"CheckSum\" type=\"STRING\"/>";
data += " </fields>";
data += " <messages>";
data += " <message name=\"MessageWithNoChildren\" msgtype=\"msg\" msgcat=\"custom\">";
data += " </message>";
data += " </messages>";
data += "</fix>";

expectedException.expect(ConfigError.class);
expectedException.expectMessage("No fields found: msgType=msg");

new DataDictionary(new ByteArrayInputStream(data.getBytes()));
}

@Test
public void testMessagesWithNoChildren50() throws Exception {
String data = "";
Expand Down