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

Required component in group #148

Merged
merged 2 commits into from
Nov 23, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions quickfixj-core/src/main/java/quickfix/DataDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ private int addXMLComponentFields(Document document, Node node, String msgtype,

final String required = getAttribute(componentFieldNode, "required");
if (required.equalsIgnoreCase("Y") && componentRequired) {
addRequiredField(msgtype, field);
dd.addRequiredField(msgtype, field);
}

dd.addField(field);
Expand Down Expand Up @@ -1148,7 +1148,9 @@ private void addXMLGroup(Document document, Node node, String msgtype, DataDicti
groupDD.addRequiredField(msgtype, field);
}
} else if (fieldNode.getNodeName().equals("component")) {
field = addXMLComponentFields(document, fieldNode, msgtype, groupDD, false);
final String required = getAttribute(fieldNode, "required");
final boolean isRequired = required != null && required.equalsIgnoreCase("Y");
field = addXMLComponentFields(document, fieldNode, msgtype, groupDD, isRequired);
} else if (fieldNode.getNodeName().equals("group")) {
field = lookupXMLFieldNumber(document, fieldNode);
groupDD.addField(field);
Expand Down
52 changes: 40 additions & 12 deletions quickfixj-core/src/test/java/quickfix/DataDictionaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,9 @@

package quickfix;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLClassLoader;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import quickfix.field.Account;
import quickfix.field.AvgPx;
import quickfix.field.BodyLength;
Expand All @@ -52,6 +41,7 @@
import quickfix.field.SenderCompID;
import quickfix.field.SenderSubID;
import quickfix.field.SendingTime;
import quickfix.field.SessionRejectReason;
import quickfix.field.Side;
import quickfix.field.Symbol;
import quickfix.field.TargetCompID;
Expand All @@ -60,6 +50,18 @@
import quickfix.fix44.NewOrderSingle;
import quickfix.test.util.ExpectedTestFailure;

import java.io.ByteArrayInputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLClassLoader;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.hasProperty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class DataDictionaryTest {

@Rule
Expand Down Expand Up @@ -749,10 +751,36 @@ private Message createQuoteRequest() {
Message quoteRequest = new Message();
quoteRequest.getHeader().setString(MsgType.FIELD, MsgType.QUOTE_REQUEST);
quoteRequest.setString(QuoteReqID.FIELD, "QR-12345");
quoteRequest.addGroup(new Group(NoRelatedSym.FIELD, Symbol.FIELD));
final Group noRelatedSymGroup = new Group(NoRelatedSym.FIELD, Symbol.FIELD);
noRelatedSymGroup.setString(Symbol.FIELD, "AAPL");
quoteRequest.addGroup(noRelatedSymGroup);
return quoteRequest;
}

/**
* Dictionary "FIX44.xml":<br/>
* <pre>
* message name=QuoteRequest msgtype=R msgcat=app
* group name=NoRelatedSym required=Y
* component name=Instrument required=Y
* field name=Symbol required=Y
* </pre>
* Field Symbol(55) is required, so validation must fail.
* @throws Exception
*/
@Test
public void testGroupWithReqdComponentWithReqdFieldValidation() throws Exception {
final Message quoteRequest = createQuoteRequest();
quoteRequest.getGroup(1, NoRelatedSym.FIELD).removeField(Symbol.FIELD);
final DataDictionary dictionary = getDictionary();

expectedException.expect(FieldException.class);
expectedException.expect(hasProperty("sessionRejectReason", is(SessionRejectReason.REQUIRED_TAG_MISSING)));
expectedException.expect(hasProperty("field", is(Symbol.FIELD)));

dictionary.validate(quoteRequest, true);
}

//
// Group Validation Tests in RepeatingGroupTest
//
Expand Down