Skip to content

Commit

Permalink
do not throw IncorrectDataFormat exception if value is empty and Vali…
Browse files Browse the repository at this point in the history
…dateFieldsHaveValues=N
  • Loading branch information
jfreedman committed Feb 1, 2018
1 parent 5f45a39 commit 4ea7e2a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
8 changes: 4 additions & 4 deletions quickfixj-core/src/main/java/quickfix/DataDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
import java.util.Map;
import java.util.Set;

import static quickfix.FileUtil.Location.CLASSLOADER_RESOURCE;
import static quickfix.FileUtil.Location.CONTEXT_RESOURCE;
import static quickfix.FileUtil.Location.FILESYSTEM;
import static quickfix.FileUtil.Location.URL;
import static quickfix.FileUtil.Location.*;

/**
* Provide the message metadata for various versions of FIX.
Expand Down Expand Up @@ -697,6 +694,9 @@ private void checkValidFormat(StringField field) throws IncorrectDataFormat {
if (fieldType == null) {
return;
}
if (field.getValue().length() == 0 && !checkFieldsHaveValues) {
return;
}
try {
switch (fieldType) {
case STRING:
Expand Down
55 changes: 26 additions & 29 deletions quickfixj-core/src/test/java/quickfix/DataDictionaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,7 @@
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;
import quickfix.field.CheckSum;
import quickfix.field.ClOrdID;
import quickfix.field.HandlInst;
import quickfix.field.LastMkt;
import quickfix.field.MsgSeqNum;
import quickfix.field.MsgType;
import quickfix.field.NoHops;
import quickfix.field.NoPartyIDs;
import quickfix.field.NoRelatedSym;
import quickfix.field.OrdType;
import quickfix.field.OrderQty;
import quickfix.field.Price;
import quickfix.field.QuoteReqID;
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;
import quickfix.field.TimeInForce;
import quickfix.field.TransactTime;
import quickfix.field.*;
import quickfix.fix44.NewOrderSingle;
import quickfix.test.util.ExpectedTestFailure;

Expand All @@ -57,10 +33,7 @@

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;
import static org.junit.Assert.*;

public class DataDictionaryTest {

Expand Down Expand Up @@ -781,6 +754,30 @@ public void testGroupWithReqdComponentWithReqdFieldValidation() throws Exception
dictionary.validate(quoteRequest, true);
}

/**
* Field EffectiveTime(168) is defined as UTCTIMESTAMP so an empty string value is invalid but if we allow blank values that should not fail
* validation
* @throws Exception
*/
@Test
public void testAllowingBlankValuesDisablesFieldValidation() throws Exception {
final DataDictionary dictionary = getDictionary();
dictionary.setCheckFieldsHaveValues(false);

final quickfix.fix44.NewOrderSingle newSingle = new quickfix.fix44.NewOrderSingle(
new ClOrdID("123"), new Side(Side.BUY), new TransactTime(), new OrdType(OrdType.LIMIT)
);
newSingle.setField(new OrderQty(42));
newSingle.setField(new Price(42.37));
newSingle.setField(new HandlInst());
newSingle.setField(new Symbol("QFJ"));
newSingle.setField(new HandlInst(HandlInst.MANUAL_ORDER));
newSingle.setField(new TimeInForce(TimeInForce.DAY));
newSingle.setField(new Account("testAccount"));
newSingle.setField(new StringField(EffectiveTime.FIELD));
dictionary.validate(newSingle, true);
}

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

0 comments on commit 4ea7e2a

Please sign in to comment.