From 24214eefad191020b102bd172760d03ba733459a Mon Sep 17 00:00:00 2001 From: Christoph John Date: Wed, 13 Dec 2023 17:16:59 +0100 Subject: [PATCH 1/4] removed check for empty message --- quickfixj-base/src/main/java/quickfix/DataDictionary.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/quickfixj-base/src/main/java/quickfix/DataDictionary.java b/quickfixj-base/src/main/java/quickfix/DataDictionary.java index d4113242c4..c0a4cb5647 100644 --- a/quickfixj-base/src/main/java/quickfix/DataDictionary.java +++ b/quickfixj-base/src/main/java/quickfix/DataDictionary.java @@ -1168,10 +1168,6 @@ 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); - } - for (int j = 0; j < fieldNodes.getLength(); j++) { final Node fieldNode = fieldNodes.item(j); From 25565ef3a4c0895392b61b660c071661274b3255 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Mon, 18 Dec 2023 12:21:00 +0100 Subject: [PATCH 2/4] check for header and trailer --- quickfixj-base/src/main/java/quickfix/DataDictionary.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/quickfixj-base/src/main/java/quickfix/DataDictionary.java b/quickfixj-base/src/main/java/quickfix/DataDictionary.java index c0a4cb5647..ec3e908889 100644 --- a/quickfixj-base/src/main/java/quickfix/DataDictionary.java +++ b/quickfixj-base/src/main/java/quickfix/DataDictionary.java @@ -1155,6 +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) + // TODO ? Integer.valueOf(documentElement.getAttribute(attribute)) : 0; } catch (NumberFormatException e) { throw new ConfigError("Attribute " + attribute + " could not be parsed as Integer.", e); @@ -1168,6 +1169,11 @@ 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 && (msgtype == HEADER_ID || msgtype == TRAILER_ID)) { + throw new ConfigError("No fields found: msgType=" + msgtype); + } + for (int j = 0; j < fieldNodes.getLength(); j++) { final Node fieldNode = fieldNodes.item(j); From fefd7a99e619c266be3eae4890e4869e0ae4da48 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Mon, 18 Dec 2023 16:58:34 +0100 Subject: [PATCH 3/4] removed no longer needed tests --- .../java/quickfix/DataDictionaryTest.java | 106 ------------------ 1 file changed, 106 deletions(-) diff --git a/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java b/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java index edf5f5adc8..7ed261607c 100644 --- a/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java +++ b/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java @@ -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 += ""; - data += "
"; - data += " "; - data += "
"; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += "
"; - - 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 += ""; - data += "
"; - data += " "; - data += "
"; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += "
"; - - 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 = ""; @@ -462,59 +409,6 @@ public void testFieldsWithTextElement40() throws Exception { new DataDictionary(new ByteArrayInputStream(data.getBytes())); } - @Test - public void testMessageWithNoChildren50() throws Exception { - String data = ""; - data += ""; - data += "
"; - data += " "; - data += "
"; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += "
"; - - 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 += ""; - data += "
"; - data += " "; - data += "
"; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += " "; - data += "
"; - - 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 = ""; From 61ead2183af43f9bcac73d618a95035ce9e46016 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Tue, 19 Dec 2023 12:55:54 +0100 Subject: [PATCH 4/4] improved exception message --- quickfixj-base/src/main/java/quickfix/DataDictionary.java | 5 ++--- .../src/test/java/quickfix/DataDictionaryTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/quickfixj-base/src/main/java/quickfix/DataDictionary.java b/quickfixj-base/src/main/java/quickfix/DataDictionary.java index ec3e908889..05e62fe9c1 100644 --- a/quickfixj-base/src/main/java/quickfix/DataDictionary.java +++ b/quickfixj-base/src/main/java/quickfix/DataDictionary.java @@ -1155,8 +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) - // TODO - ? 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); } @@ -1171,7 +1170,7 @@ private void load(Document document, String msgtype, Node node) throws ConfigErr final NodeList fieldNodes = node.getChildNodes(); if (countElementNodes(fieldNodes) == 0 && (msgtype == HEADER_ID || msgtype == TRAILER_ID)) { - throw new ConfigError("No fields found: msgType=" + msgtype); + throw new ConfigError("No fields found in " + msgtype); } for (int j = 0; j < fieldNodes.getLength(); j++) { diff --git a/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java b/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java index 7ed261607c..97c87c1359 100644 --- a/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java +++ b/quickfixj-base/src/test/java/quickfix/DataDictionaryTest.java @@ -275,7 +275,7 @@ public void testHeaderWithNoChildren40() throws Exception { data += ""; expectedException.expect(ConfigError.class); - expectedException.expectMessage("No fields found: msgType=HEADER"); + expectedException.expectMessage("No fields found in HEADER"); new DataDictionary(new ByteArrayInputStream(data.getBytes())); } @@ -302,7 +302,7 @@ public void testHeaderWithTextElement40() throws Exception { data += ""; expectedException.expect(ConfigError.class); - expectedException.expectMessage("No fields found: msgType=HEADER"); + expectedException.expectMessage("No fields found in HEADER"); new DataDictionary(new ByteArrayInputStream(data.getBytes())); } @@ -328,7 +328,7 @@ public void testTrailerWithNoChildren40() throws Exception { data += ""; expectedException.expect(ConfigError.class); - expectedException.expectMessage("No fields found: msgType=TRAILER"); + expectedException.expectMessage("No fields found in TRAILER"); new DataDictionary(new ByteArrayInputStream(data.getBytes())); } @@ -355,7 +355,7 @@ public void testTrailerWithTextElement40() throws Exception { data += ""; expectedException.expect(ConfigError.class); - expectedException.expectMessage("No fields found: msgType=TRAILER"); + expectedException.expectMessage("No fields found in TRAILER"); new DataDictionary(new ByteArrayInputStream(data.getBytes())); }