-
Notifications
You must be signed in to change notification settings - Fork 601
/
MessageTest.java
1520 lines (1307 loc) · 73 KB
/
MessageTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) quickfixengine.org All rights reserved.
*
* This file is part of the QuickFIX FIX Engine
*
* This file may be distributed under the terms of the quickfixengine.org
* license as defined by quickfixengine.org and appearing in the file
* LICENSE included in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* See http://www.quickfixengine.org/LICENSE for licensing information.
*
* Contact ask@quickfixengine.org if any conditions of this licensing
* are not clear to you.
******************************************************************************/
package quickfix;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.quickfixj.CharsetSupport;
import quickfix.field.Account;
import quickfix.field.AllocAccount;
import quickfix.field.AllocShares;
import quickfix.field.AvgPx;
import quickfix.field.BeginString;
import quickfix.field.BidType;
import quickfix.field.BodyLength;
import quickfix.field.CheckSum;
import quickfix.field.ClOrdID;
import quickfix.field.CountryOfIssue;
import quickfix.field.CrossID;
import quickfix.field.CrossPrioritization;
import quickfix.field.CrossType;
import quickfix.field.CumQty;
import quickfix.field.EncodedText;
import quickfix.field.EncodedTextLen;
import quickfix.field.EncryptMethod;
import quickfix.field.ExecID;
import quickfix.field.ExecType;
import quickfix.field.HandlInst;
import quickfix.field.Headline;
import quickfix.field.HopCompID;
import quickfix.field.IOIID;
import quickfix.field.LastPx;
import quickfix.field.LastQty;
import quickfix.field.LeavesQty;
import quickfix.field.LegPrice;
import quickfix.field.LegQty;
import quickfix.field.LegRefID;
import quickfix.field.LegSymbol;
import quickfix.field.ListID;
import quickfix.field.ListSeqNo;
import quickfix.field.MDEntryPx;
import quickfix.field.MaturityMonthYear;
import quickfix.field.MsgDirection;
import quickfix.field.MsgSeqNum;
import quickfix.field.MsgType;
import quickfix.field.NoHops;
import quickfix.field.NoOrders;
import quickfix.field.NoSides;
import quickfix.field.OrdStatus;
import quickfix.field.OrdType;
import quickfix.field.OrderID;
import quickfix.field.OrderQty;
import quickfix.field.PartyID;
import quickfix.field.PartyIDSource;
import quickfix.field.PartyRole;
import quickfix.field.PreviouslyReported;
import quickfix.field.Price;
import quickfix.field.PutOrCall;
import quickfix.field.QuoteAckStatus;
import quickfix.field.RawData;
import quickfix.field.RawDataLength;
import quickfix.field.RefMsgType;
import quickfix.field.SecurityID;
import quickfix.field.SecurityIDSource;
import quickfix.field.SecurityReqID;
import quickfix.field.SecurityRequestResult;
import quickfix.field.SecurityResponseID;
import quickfix.field.SecurityType;
import quickfix.field.SenderCompID;
import quickfix.field.SendingTime;
import quickfix.field.SessionRejectReason;
import quickfix.field.Side;
import quickfix.field.Signature;
import quickfix.field.SignatureLength;
import quickfix.field.StrikePrice;
import quickfix.field.Symbol;
import quickfix.field.TargetCompID;
import quickfix.field.Text;
import quickfix.field.TotNoOrders;
import quickfix.field.TradeDate;
import quickfix.field.TradeReportID;
import quickfix.field.TransactTime;
import quickfix.field.UnderlyingCurrency;
import quickfix.field.UnderlyingSymbol;
import quickfix.fix42.NewOrderSingle;
import quickfix.fix43.Message.Header;
import quickfix.fix43.NewOrderList;
import quickfix.fix44.ExecutionReport;
import quickfix.fix44.IndicationOfInterest;
import quickfix.fix44.Logon;
import quickfix.fix44.Logon.NoMsgTypes;
import quickfix.fix44.NewOrderCross;
import quickfix.fix44.NewOrderSingle.NoPartyIDs;
import quickfix.fix44.News;
import quickfix.fix44.TradeCaptureReport;
import quickfix.fix44.component.Instrument;
import quickfix.fix44.component.Parties;
import quickfix.fix50.MarketDataSnapshotFullRefresh;
public class MessageTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testTrailerFieldOrdering() throws Exception {
final NewOrderSingle order = createNewOrderSingle();
order.getTrailer().setField(new Signature("FOO"));
order.getTrailer().setField(new SignatureLength(3));
assertTrue(order.toString().contains("93=3\00189=FOO\001"));
}
private NewOrderSingle createNewOrderSingle() {
return new NewOrderSingle(new ClOrdID("CLIENT"), new HandlInst(
HandlInst.AUTOMATED_EXECUTION_INTERVENTION_OK), new Symbol("ORCL"),
new Side(Side.BUY), new TransactTime(LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC)), new OrdType(OrdType.LIMIT));
}
@Test
public void testHeaderGroupParsing() throws Exception {
final Message message = new Message("8=FIX.4.2\0019=40\00135=A\001"
+ "627=2\001628=FOO\001628=BAR\001"
+ "98=0\001384=2\001372=D\001385=R\001372=8\001385=S\00110=228\001",
DataDictionaryTest.getDictionary());
final quickfix.fix44.Message.Header.NoHops hops = new quickfix.fix44.Message.Header.NoHops();
message.getHeader().getGroup(1, hops);
assertEquals("FOO", hops.getString(HopCompID.FIELD));
message.getHeader().getGroup(2, hops);
assertEquals("BAR", hops.getString(HopCompID.FIELD));
}
@Test
public void testEmbeddedMessage() throws Exception {
final ExecutionReport report = new ExecutionReport(new OrderID("ORDER"),
new ExecID("EXEC"), new ExecType(ExecType.TRADE), new OrdStatus(OrdStatus.FILLED),
new Side(Side.BUY), new LeavesQty(100), new CumQty(100), new AvgPx(50));
final NewOrderSingle order = createNewOrderSingle();
String text = order.toString();
report.set(new EncodedTextLen(text.length()));
report.set(new EncodedText(text));
final Message msg = new Message(report.toString(), DataDictionaryTest.getDictionary());
assertEquals("embedded order", text, msg.getString(EncodedText.FIELD));
}
private void doTestMessageWithEncodedField(String charset, String text) throws Exception {
CharsetSupport.setCharset(charset);
try {
NewOrderSingle order = createNewOrderSingle();
order.set(new EncodedTextLen(MessageUtils.length(CharsetSupport.getCharsetInstance(), text)));
order.set(new EncodedText(text));
final Message msg = new Message(order.toString(), DataDictionaryTest.getDictionary());
assertEquals(charset + " encoded field", text, msg.getString(EncodedText.FIELD));
} finally {
CharsetSupport.setDefaultCharset();
}
}
@Test
public void testMessageWithEncodedField() throws Exception {
String text = "\u6D4B\u9A8C\001\u6570\u636E"; // Chinese with SOH in the middle
doTestMessageWithEncodedField("UTF-8", text);
doTestMessageWithEncodedField("EUC-JP", text);
doTestMessageWithEncodedField("ISO-2022-JP", text);
doTestMessageWithEncodedField("Shift_JIS", text);
doTestMessageWithEncodedField("GBK", text);
// doTestMessageWithEncodedField("UTF-16", text); // double-byte charset not supported yet
}
@Test
public void testParsing() throws Exception {
// checksum is not verified in these tests
final Message message = new Message("8=FIX.4.2\0019=40\00135=A\001"
+ "98=0\001384=2\001372=D\001385=R\001372=8\001385=S\00110=96\001",
DataDictionaryTest.getDictionary());
assertHeaderField(message, "FIX.4.2", BeginString.FIELD);
assertHeaderField(message, "40", BodyLength.FIELD);
assertEquals("wrong field value", 40, message.getHeader().getInt(BodyLength.FIELD));
assertHeaderField(message, "A", MsgType.FIELD);
assertBodyField(message, "0", EncryptMethod.FIELD);
assertTrailerField(message, "96", CheckSum.FIELD);
final NoMsgTypes valueMessageType = new Logon.NoMsgTypes();
message.getGroup(1, valueMessageType);
assertEquals("wrong value", "D", valueMessageType.getString(RefMsgType.FIELD));
assertEquals("wrong value", "R", valueMessageType.getString(MsgDirection.FIELD));
message.getGroup(2, valueMessageType);
assertEquals("wrong value", "8", valueMessageType.getString(RefMsgType.FIELD));
assertEquals("wrong value", "S", valueMessageType.getString(MsgDirection.FIELD));
}
@Test
public void testParsing2() throws Exception {
// checksum is not verified in these tests
String data = "8=FIX.4.2\0019=76\001";
data += "35=6\001";
data += "23=IDENTIFIER\001";
data += "28=N\001";
data += "55=MSFT\001";
data += "54=1\001";
data += "711=2\001";
data += "311=DELL\001";
data += "318=USD\001";
data += "311=IBM\001";
data += "318=CAD\001";
data += "10=037\001";
final Message message = new Message(data, DataDictionaryTest.getDictionary());
assertHeaderField(message, "FIX.4.2", BeginString.FIELD);
assertHeaderField(message, "76", BodyLength.FIELD);
assertHeaderField(message, MsgType.INDICATION_OF_INTEREST, MsgType.FIELD);
assertBodyField(message, "IDENTIFIER", IOIID.FIELD);
assertTrailerField(message, "037", CheckSum.FIELD);
final IndicationOfInterest.NoUnderlyings valueMessageType = new IndicationOfInterest.NoUnderlyings();
message.getGroup(1, valueMessageType);
assertEquals("wrong value", "DELL", valueMessageType.getString(UnderlyingSymbol.FIELD));
assertEquals("wrong value", "USD", valueMessageType.getString(UnderlyingCurrency.FIELD));
message.getGroup(2, valueMessageType);
assertEquals("wrong value", "IBM", valueMessageType.getString(UnderlyingSymbol.FIELD));
assertEquals("wrong value", "CAD", valueMessageType.getString(UnderlyingCurrency.FIELD));
}
@Test
public void testValidation() throws Exception {
final String data = "8=FIX.4.4\0019=309\00135=8\00149=ASX\00156=CL1_FIX44\00134=4\001" +
"52=20060324-01:05:58\00117=X-B-WOW-1494E9A0:58BD3F9D-1109\001150=D\00139=0\001" +
"11=184271\00138=200\001198=1494E9A0:58BD3F9D\001526=4324\00137=B-WOW-1494E9A0:58BD3F9D\001" +
"55=WOW\00154=1\001151=200\00114=0\00140=2\00144=15\00159=1\0016=0\001453=3\001448=AAA35791\001" +
"447=D\001452=3\001448=8\001447=D\001452=4\001448=FIX11\001" +
"447=D\001452=36\00160=20060320-03:34:29\00110=169\001";
final ExecutionReport executionReport = new ExecutionReport();
final DataDictionary dictionary = DataDictionaryTest.getDictionary();
assertNotNull(dictionary);
executionReport.fromString(data, dictionary, true);
dictionary.validate(executionReport);
}
@Test
// QFJ-675: Message.clear() should reset position field to zero to enable Message to be reused
public void testParseTwice() throws Exception {
final String data1 = "8=FIX.4.4\0019=309\00135=8\00149=ASX\00156=CL1_FIX44\00134=4\001" +
"52=20060324-01:05:58\00117=X-B-WOW-1494E9A0:58BD3F9D-1109\001150=D\00139=0\001" +
"11=184271\00138=200\001198=1494E9A0:58BD3F9D\001526=4324\00137=B-WOW-1494E9A0:58BD3F9D\001" +
"55=WOW\00154=1\001151=200\00114=0\00140=2\00144=15\00159=1\0016=0\001453=3\001448=AAA35791\001" +
"447=D\001452=3\001448=8\001447=D\001452=4\001448=FIX11\001" +
"447=D\001452=36\00160=20060320-03:34:29\00110=169\001";
final String data2 = "8=FIX.4.4\0019=309\00135=8\00149=ASX\00156=CL1_FIX44\00134=4\001" +
"52=20060324-01:05:58\00117=X-B-WOW-1494E9A0:58BD3F9D-1109\001150=D\00139=0\00111=123456\001" +
"38=200\001198=1494E9A0:58BD3F9D\001526=4324\00137=B-WOW-1494E9A0:58BD3F9D\00155=WOW\00154=1\001" +
"151=200\00114=0\00140=2\00144=15\00159=1\0016=0\001453=3\001448=AAA35791\001447=D\001452=3\001" +
"448=8\001447=D\001452=4\001448=FIX11\001447=D\001452=36\00160=20060320-03:34:29\00110=167\001";
final DataDictionary dictionary = DataDictionaryTest.getDictionary();
final ExecutionReport executionReport = new ExecutionReport();
assertNotNull(dictionary);
executionReport.fromString(data1, dictionary, true);
dictionary.validate(executionReport);
executionReport.clear();
executionReport.fromString(data2, dictionary, true);
dictionary.validate(executionReport);
}
@Test
// QFJ-426 Message header will not validate when containing 'Hop' group
public void testValidationWithHops() throws Exception {
final String data = "8=FIX.4.4\0019=309\00135=8\00149=ASX\00156=CL1_FIX44\00134=4\001" +
"52=20060324-01:05:58\00117=X-B-WOW-1494E9A0:58BD3F9D-1109\001150=D\00139=0\00111=184271\001" +
"38=200\001198=1494E9A0:58BD3F9D\001526=4324\00137=B-WOW-1494E9A0:58BD3F9D\00155=WOW\00154=1\001" +
"151=200\00114=0\00140=2\00144=15\00159=1\0016=0\001453=3\001448=AAA35791\001447=D\001452=3\001" +
"448=8\001447=D\001452=4\001448=FIX11\001447=D\001452=36\00160=20060320-03:34:29\00110=169\001";
final ExecutionReport executionReport = new ExecutionReport();
final DataDictionary dictionary = DataDictionaryTest.getDictionary();
assertNotNull(dictionary);
executionReport.fromString(data, dictionary, true);
final Header.NoHops hops = new Header.NoHops();
hops.set(new HopCompID("FOO"));
executionReport.header.addGroup(hops);
dictionary.validate(executionReport);
}
@Test
public void testAppMessageValidation() throws Exception {
final String data = "8=FIXT.1.1\0019=234\00135=W\00134=2\00149=ABFX\00152=20080722-16:37:11.234\001" +
"56=X2RV1\00155=EUR/USD\001262=CAP0000011\001268=2\001269=0\001270=1.57844\00115=EUR\001" +
"271=500000\001272=20080724\001269=1\001270=1.57869\00115=EUR\001271=500000\001272=20080724\00110=097\001";
final MarketDataSnapshotFullRefresh mdsfr = new MarketDataSnapshotFullRefresh();
final DataDictionary sessDictionary = DataDictionaryTest.getDictionary("FIXT11.xml");
final DataDictionary appDictionary = DataDictionaryTest.getDictionary("FIX50.xml");
assertNotNull(sessDictionary);
assertNotNull(appDictionary);
mdsfr.fromString(data, sessDictionary, appDictionary, true);
DataDictionary.validate(mdsfr, sessDictionary, appDictionary);
}
@Test
public void testAppMessageValidationFixLatest() throws Exception {
final String data = "8=FIXT.1.1\0019=234\00135=W\00134=2\00149=ABFX\00152=20080722-16:37:11.234\001" +
"56=X2RV1\00155=EUR/USD\001262=CAP0000011\001779=20080722-16:37:11.234\001268=2\001269=0\001270=1.57844\00115=EUR\001" +
"271=500000\001272=20080724\001269=1\001270=1.57869\00115=EUR\001271=500000\001272=20080724\00110=118\001";
final quickfix.fixlatest.MarketDataSnapshotFullRefresh mdsfr = new quickfix.fixlatest.MarketDataSnapshotFullRefresh();
final DataDictionary sessDictionary = DataDictionaryTest.getDictionary("FIXT11.xml");
final DataDictionary appDictionary = DataDictionaryTest.getDictionary("FIXLatest.xml");
assertNotNull(sessDictionary);
assertNotNull(appDictionary);
mdsfr.fromString(data, sessDictionary, appDictionary, true);
DataDictionary.validate(mdsfr, sessDictionary, appDictionary);
}
@Test
public void testAdminMessageValidation() throws Exception {
final String data = "8=FIXT.1.1\0019=84\00135=A\00149=EXEC\00156=BANZAI\00134=1\001" +
"52=20080811-13:26:12.409\001108=1\001141=Y\00198=0\0011137=7\00110=102\001";
final Logon logon = new Logon();
final DataDictionary sessionDictionary = DataDictionaryTest.getDictionary("FIXT11.xml");
final DataDictionary appDictionary = DataDictionaryTest.getDictionary("FIX50.xml");
assertNotNull(sessionDictionary);
assertNotNull(appDictionary);
logon.fromString(data, sessionDictionary, appDictionary, true);
DataDictionary.validate(logon, sessionDictionary, sessionDictionary);
}
@Test
public void testGroupDelimOrdering() throws Exception {
// Test the generic group constructor (QFJ-95)
final quickfix.fix44.NewOrderSingle order = new quickfix.fix44.NewOrderSingle();
final Group partyGroup = new Group(quickfix.field.NoPartyIDs.FIELD, PartyID.FIELD);
partyGroup.setField(new PartyID("TraderName"));
partyGroup.setField(new PartyIDSource(
PartyIDSource.GENERAL_IDENTIFIER));
partyGroup.setField(new PartyRole(11));
order.addGroup(partyGroup);
final String data = order.toString();
assertTrue("wrong field order", data.contains("453=1\001448=TraderName"));
}
@Test
public void testComponentGroupExtraction() throws Exception {
final quickfix.fix44.NewOrderSingle order = new quickfix.fix44.NewOrderSingle();
final NoPartyIDs partyIds = new NoPartyIDs();
partyIds.set(new PartyID("PARTY_ID_1"));
order.addGroup(partyIds);
partyIds.set(new PartyID("PARTY_ID_2"));
order.addGroup(partyIds);
final Parties parties = order.getParties();
assertEquals("wrong # of party IDs", 2, parties.getNoPartyIDs().getValue());
}
@Test
public void testComponentGroupInsertion() throws Exception {
final Parties parties = new Parties();
final NoPartyIDs partyIds = new NoPartyIDs();
partyIds.set(new PartyID("PARTY_ID_1"));
parties.addGroup(partyIds);
partyIds.set(new PartyID("PARTY_ID_2"));
parties.addGroup(partyIds);
final quickfix.fix44.NewOrderSingle order = new quickfix.fix44.NewOrderSingle();
order.set(parties);
assertEquals("wrong # of party IDs", 2, order.getNoPartyIDs().getValue());
}
// QFJ-52
@Test
public void testInvalidFirstFieldInGroup() throws Exception {
final News news = new News();
news.set(new Headline("Test"));
final News.NoRelatedSym relatedSym = new News.NoRelatedSym();
relatedSym.set(new SecurityID("SECID"));
relatedSym.set(new SecurityIDSource("SECID_SOURCE"));
news.addGroup(relatedSym);
try {
new Message(news.toString(), DataDictionaryTest.getDictionary());
} catch (final InvalidMessage e) {
// expected
} catch (final NullPointerException e) {
fail("Should not throw NPE when first field is missing.");
}
}
@Test
public void testRequiredGroupValidation() throws Exception {
final News news = new News();
news.set(new Headline("Test"));
final DataDictionary dictionary = DataDictionaryTest.getDictionary();
try {
dictionary.validate(news);
fail("no field exception for missing lines group");
} catch (final FieldException e) {
// expected
}
}
/**
* Test for data fields with SOH. This test is based on report from a user on
* the QuickFIX mailing list. The problem was the user's configuration but this
* seems like a good unit test to keep in the suite.
*/
@Test
public void testDataFieldWithManualFieldInsertion() throws Exception {
final String data = "10001=Canonical.1.00\00110002=001058\00125001=01\00110003=SAPI_ADMRESP\00110004=SUBSCRIBE_RESP\001"
+ "10009=705\00110012=01\00110005=SPGW\00110006=SAPI\00110007=0\00110010=16:25:11.537\001"
+ "10045=SDQADL:01:/SDB/ENT/@/@/STKSDLL:7\00110955=Y\00110963=043\00110961=03\00111285=N\001"
+ "11339=823,980\00110919=N\00111111=86795696\00110898=043\00110920=~\00110938=N\00111340=5- 9.99\001"
+ "11343=0.20\00111344=~\00111341=~\00111342=0.15\00111345=10- 14.99\00111348=0.25\00111349=~\00111346=~\001"
+ "11347=0.15\00111350=15- 19.99\00111353=0.30\00111354=~\00111351=~\00111352=0.20\00111338=23SEP05\001"
+ "10981=0\00110485=N\00110761=0\00111220=~\00111224=N\00110808=N\00110921=~\00110960=N\00110957=N\00111329=N\001"
+ "11286=0\00111214=USA\00110917=Y\00111288=0\00110906=N\00110737=0.01\00110956=~\00110967=~\00110965=~\00110809=0\001"
+ "10762=N\00110763=N\00110712=1\00110905=09:30:00\00110918=YA0101\00110951=Y\00110469=1\00110949=1\00110487=Q\00110950=Y\001"
+ "10899=N\00110380=N\00110696=03\00111082=18.41\00110217=12\00110954=N\00110708=E\00110958=N\00111213=US \00111334=N\001"
+ "11332=N\00111331=N\00111330=N\00111335=N\00111333=N\00110767=3\00110974=~\00110980=AIRTRAN HOLDINGS \00111289=N\001"
+ "10912=4\00110915=0501\00110914=0501\00110975=N\00110913=SLK\00110698=055\00110666=AAI\00110903=S\00111328=N\001"
+ "10624=L\00111287=0\00110699=0\00110962=L\00111227=SUB1\00111229=5\00111228=1\00111236=16:24:41.521\00111277=16:25:11.630\001";
try {
final DataDictionary dictionary = DataDictionaryTest.getDictionary();
final Message m = new Message();
m.getHeader().setString(BeginString.FIELD, FixVersions.BEGINSTRING_FIX44);
final MsgType msgType = new MsgType("U678");
m.getHeader().setField(msgType);
m.setInt(RawDataLength.FIELD, data.length());
m.setString(RawData.FIELD, data);
assertEquals(1108 + msgType.getValue().length(), m.bodyLength());
final Message m2 = new Message(m.toString(), dictionary);
assertEquals(m.bodyLength(), m2.bodyLength());
} catch (final InvalidMessage e) {
fail(e.getMessage());
}
}
@Test
public void testCalculateStringWithNestedGroups() throws Exception {
final NewOrderCross noc = new NewOrderCross();
noc.getHeader().setString(BeginString.FIELD, FixVersions.BEGINSTRING_FIX44);
noc.getHeader().setInt(MsgSeqNum.FIELD, 5);
noc.getHeader().setString(SenderCompID.FIELD, "sender");
noc.getHeader().setString(TargetCompID.FIELD, "target");
noc.getHeader().setString(SendingTime.FIELD, "20060319-09:08:20.881");
noc.setString(SecurityIDSource.FIELD, SecurityIDSource.EXCHANGE_SYMBOL);
noc.setChar(OrdType.FIELD, OrdType.LIMIT);
noc.setDouble(Price.FIELD, 9.00);
noc.setString(SecurityID.FIELD, "ABC");
noc.setString(Symbol.FIELD, "ABC");
noc.setString(TransactTime.FIELD, "20060319-09:08:19");
noc.setString(CrossID.FIELD, "184214");
noc.setInt(CrossType.FIELD,
CrossType.CROSS_IOC);
noc.setInt(CrossPrioritization.FIELD, CrossPrioritization.NONE);
final NewOrderCross.NoSides side = new NewOrderCross.NoSides();
side.setChar(Side.FIELD, Side.BUY);
side.setDouble(OrderQty.FIELD, 9);
final NewOrderCross.NoSides.NoPartyIDs party = new NewOrderCross.NoSides.NoPartyIDs();
party.setString(PartyID.FIELD, "8");
party.setChar(PartyIDSource.FIELD, PartyIDSource.PROPRIETARY);
party.setInt(PartyRole.FIELD, PartyRole.CLEARING_FIRM);
side.addGroup(party);
party.setString(PartyID.FIELD, "AAA35777");
party.setChar(PartyIDSource.FIELD, PartyIDSource.PROPRIETARY);
party.setInt(PartyRole.FIELD, PartyRole.CLIENT_ID);
side.addGroup(party);
noc.addGroup(side);
side.clear();
side.setChar(Side.FIELD, Side.SELL);
side.setDouble(OrderQty.FIELD, 9);
party.clear();
party.setString(PartyID.FIELD, "8");
party.setChar(PartyIDSource.FIELD, PartyIDSource.PROPRIETARY);
party.setInt(PartyRole.FIELD, PartyRole.CLEARING_FIRM);
side.addGroup(party);
party.clear();
party.setString(PartyID.FIELD, "aaa");
party.setChar(PartyIDSource.FIELD, PartyIDSource.PROPRIETARY);
party.setInt(PartyRole.FIELD, PartyRole.CLIENT_ID);
side.addGroup(party);
noc.addGroup(side);
final String expectedMessage = "8=FIX.4.4\0019=247\00135=s\00134=5\00149=sender\00152=20060319-09:08:20.881\001"
+ "56=target\00122=8\00140=2\00144=9\00148=ABC\00155=ABC\00160=20060319-09:08:19\001548=184214\001549=2\001"
+ "550=0\001552=2\00154=1\001453=2\001448=8\001447=D\001452=4\001448=AAA35777\001447=D\001452=3\00138=9\00154=2\001"
+ "453=2\001448=8\001447=D\001452=4\001448=aaa\001447=D\001452=3\00138=9\00110=056\001";
assertEquals("wrong message", expectedMessage, noc.toString());
}
@Test
public void testFieldOrdering() throws Exception {
final String expectedMessageString = "8=FIX.4.4\0019=171\00135=D\00149=SenderCompId\00156=TargetCompId\001" +
"11=183339\00122=8\00138=1\00140=2\00144=12\00148=BHP\00154=2\00155=BHP\00159=1\00160=20060223-22:38:33\001" +
"526=3620\001453=2\001448=8\001447=D\001452=4\001448=AAA35354\001447=D\001452=3\00110=168\001";
final DataDictionary dataDictionary = new DataDictionary("FIX44.xml");
final Message message = new DefaultMessageFactory()
.create(dataDictionary.getVersion(), "D");
message.fromString(expectedMessageString, dataDictionary, false);
final String actualMessageString = message.toString();
assertTrue(
"wrong field ordering",
actualMessageString.contains("453=2\001448=8\001447=D\001452=4\001448=AAA35354\001447=D\001452=3"));
}
@Test
public void testMessageGroups() {
final Message message = new Message();
final NewOrderSingle.NoAllocs numAllocs = setUpGroups(message);
assertGroupContent(message, numAllocs);
}
@Test
public void testMessageCloneWithGroups() {
final Message message = new Message();
final NewOrderSingle.NoAllocs numAllocs = setUpGroups(message);
final Message clonedMessage = (Message) message.clone();
assertGroupContent(clonedMessage, numAllocs);
}
@Test
public void testFieldOrderAfterClone() {
final Message message = new quickfix.fix44.NewOrderSingle();
final quickfix.fix44.NewOrderSingle.NoPartyIDs partyIdGroup = new quickfix.fix44.NewOrderSingle.NoPartyIDs();
partyIdGroup.set(new PartyID("PARTY_1"));
partyIdGroup.set(new PartyIDSource(PartyIDSource.ISITCACRONYM));
partyIdGroup.set(new PartyRole(PartyRole.INTRODUCING_FIRM));
message.addGroup(partyIdGroup);
final Message clonedMessage = (Message) message.clone();
assertEquals("wrong field order",
"8=FIX.4.4\0019=35\00135=D\001453=1\001448=PARTY_1\001447=I\001452=6\00110=040\001",
clonedMessage.toString());
}
@Test
public void testMessageGroupRemovalUsingGroupObject() {
final Message message = new Message();
NewOrderSingle.NoAllocs numAllocs = setUpGroups(message);
// Remove all
assertEquals("wrong # of group members", 2, message.getGroupCount(numAllocs.getFieldTag()));
message.removeGroup(numAllocs);
assertEquals("wrong # of group members", 0, message.getGroupCount(numAllocs.getFieldTag()));
assertNoZeroLengthGroupTag(message);
assertEquals("wrong message length", 0, message.calculateLength());
// Remove one at a time
numAllocs = setUpGroups(message);
assertEquals("wrong # of group members", 2, message.getGroupCount(numAllocs.getFieldTag()));
message.removeGroup(2, numAllocs);
assertEquals("wrong # of group members", 1, message.getGroupCount(numAllocs.getFieldTag()));
message.removeGroup(1, numAllocs);
assertEquals("wrong # of group members", 0, message.getGroupCount(numAllocs.getFieldTag()));
assertNoZeroLengthGroupTag(message);
assertEquals("wrong message length", 0, message.calculateLength());
}
@Test
public void testMessageGroupRemovalUsingGroupFieldTag() {
final Message message = new Message();
NewOrderSingle.NoAllocs numAllocs = setUpGroups(message);
// Remove all
assertEquals("wrong # of group members", 2, message.getGroupCount(numAllocs.getFieldTag()));
message.removeGroup(numAllocs.getFieldTag());
assertEquals("wrong # of group members", 0, message.getGroupCount(numAllocs.getFieldTag()));
assertNoZeroLengthGroupTag(message);
assertEquals("wrong message length", 0, message.calculateLength());
assertEquals("wrong checksum", 0, message.calculateChecksum());
// Remove one at a time
numAllocs = setUpGroups(message);
assertEquals("wrong # of group members", 2, message.getGroupCount(numAllocs.getFieldTag()));
message.removeGroup(2, numAllocs.getFieldTag());
assertEquals("wrong # of group members", 1, message.getGroupCount(numAllocs.getFieldTag()));
message.removeGroup(1, numAllocs.getFieldTag());
assertEquals("wrong # of group members", 0, message.getGroupCount(numAllocs.getFieldTag()));
assertNoZeroLengthGroupTag(message);
assertEquals("wrong message length", 0, message.calculateLength());
assertEquals("wrong checksum", 0, message.calculateChecksum());
}
@Test
public void testMessageGroupRemovalFromEmptyGroup() {
final Message message = new Message();
final NewOrderSingle.NoAllocs numAllocs = setUpGroups(message);
message.removeGroup(numAllocs);
// ensure no exception when groups are empty
message.removeGroup(1, numAllocs);
assertEquals("wrong # of group members", 0, message.getGroupCount(numAllocs.getFieldTag()));
assertNoZeroLengthGroupTag(message);
assertEquals("wrong message length", 0, message.calculateLength());
}
private void assertNoZeroLengthGroupTag(final Message message) {
assertFalse("Zero-length group tag exists in message string",
message.toString().contains("\00178="));
}
@Test
public void testHasGroup() {
final Message message = new Message();
final NewOrderSingle.NoAllocs numAllocs = setUpGroups(message);
assertFalse("wrong value", message.hasGroup(654));
assertTrue("wrong value", message.hasGroup(numAllocs.getFieldTag()));
assertTrue("wrong value", message.hasGroup(numAllocs));
assertTrue("wrong value", message.hasGroup(1, numAllocs));
assertTrue("wrong value", message.hasGroup(1, numAllocs.getFieldTag()));
assertTrue("wrong value", message.hasGroup(2, numAllocs));
assertTrue("wrong value", message.hasGroup(2, numAllocs.getFieldTag()));
assertFalse("wrong value", message.hasGroup(3, numAllocs));
assertFalse("wrong value", message.hasGroup(3, numAllocs.getFieldTag()));
}
@Test
public void testComponent() throws Exception {
final Instrument instrument = new Instrument();
instrument.set(new Symbol("DELL"));
instrument.set(new CountryOfIssue("USA"));
instrument.set(new SecurityType(SecurityType.COMMON_STOCK));
final quickfix.fix44.NewOrderSingle newOrderSingle = new quickfix.fix44.NewOrderSingle();
newOrderSingle.set(instrument);
newOrderSingle.set(new OrderQty(100));
newOrderSingle.set(new Price(45));
assertEquals(new Symbol("DELL"), newOrderSingle.getSymbol());
assertEquals(new CountryOfIssue("USA"), newOrderSingle.getCountryOfIssue());
assertEquals(new SecurityType(SecurityType.COMMON_STOCK), newOrderSingle.getSecurityType());
newOrderSingle.set(new ClOrdID("CLIENT_ORDER_ID"));
final Instrument instrument2 = newOrderSingle.getInstrument();
assertEquals(new Symbol("DELL"), instrument2.getSymbol());
assertEquals(new CountryOfIssue("USA"), instrument2.getCountryOfIssue());
assertEquals(new SecurityType(SecurityType.COMMON_STOCK), instrument2.getSecurityType());
try {
instrument2.getField(new ClOrdID());
fail("should have thrown exception");
} catch (final FieldNotFound e) {
// expected
}
}
@Test
public void testReplaceGroup() throws Exception {
final Message message = new Message();
message.setField(new ListID("1"));
message.setField(new BidType(0));
message.setField(new TotNoOrders(3));
final NewOrderList.NoOrders group = new NewOrderList.NoOrders();
group.set(new ClOrdID("A"));
group.set(new ListSeqNo(1));
group.set(new Symbol("DELL"));
group.set(new Side('1'));
message.addGroup(group);
group.set(new ClOrdID("B"));
group.set(new ListSeqNo(2));
group.set(new Symbol("LNUX"));
group.set(new Side('2'));
message.addGroup(group);
group.set(new ClOrdID("C"));
group.set(new ListSeqNo(3));
group.set(new Symbol("RHAT"));
group.set(new Side('3'));
message.addGroup(group);
group.set(new ClOrdID("D"));
group.set(new ListSeqNo(4));
group.set(new Symbol("AAPL"));
group.set(new Side('4'));
message.replaceGroup(2, group);
final NoOrders noOrders = new NoOrders();
assertTrue(message.hasGroup(1, group));
assertTrue(message.hasGroup(2, group));
assertTrue(message.hasGroup(3, group));
assertEquals(3, message.getGroupCount(NoOrders.FIELD));
message.getField(noOrders);
assertEquals(3, noOrders.getValue());
final ClOrdID clOrdID = new ClOrdID();
message.getGroup(1, group);
assertEquals("A", group.getField(clOrdID).getValue());
message.getGroup(2, group);
assertEquals("D", group.getField(clOrdID).getValue());
message.getGroup(3, group);
assertEquals("C", group.getField(clOrdID).getValue());
}
@Test
public void testFieldWithEqualsCharacter() {
try {
final DataDictionary dd = DataDictionaryTest.getDictionary();
final Message m = new Message(
"8=FIXT.1.1\0019=369\00135=W\00149=I\00156=F\00134=4\00152=20111021-15:09:16.535\001" +
"262=1319209757316210\00121=2\00155=EUR/USD\001461=RCSXX=0\001268=8\001" +
"269=0\001270=1.38898\001271=2000000\001269=0\001270=1.38897\001271=8000000\001" +
"269=0\001270=1.38854\001271=2000000\001269=1\001270=1.38855\001271=6000000\001" +
"269=1\001270=1.38856\001271=7000000\001269=1\001270=1.38857\001271=3000000\001" +
"269=1\001270=1.38858\001271=9000000\001269=1\001270=1.38859\001271=100000000\00110=51\001",
dd, true);
assertEquals(m.getString(461), "RCSXX=0");
final MarketDataSnapshotFullRefresh.NoMDEntries group = new MarketDataSnapshotFullRefresh.NoMDEntries();
m.getGroup(1, group);
final MDEntryPx px = new MDEntryPx();
group.get(px);
assertEquals(px.objectAsString(), "1.38898");
} catch (final Exception e) {
final String text = e.getMessage();
assertTrue("Wrong exception message: " + text,
text != null && !text.contains("Actual body length"));
}
}
@Test
public void testMiscFeeType() {
try {
final DataDictionary dd = DataDictionaryTest.getDictionary();
final Message m = new Message(
"8=FIXT.1.1\0019=369\00135=W\00149=I\00156=F\00134=4\00152=20111021-15:09:16.535\001" +
"262=1319209757316210\00121=2\00155=EUR/USD\001461=RCSXX=0\001268=8\001" +
"269=0\001270=1.38898\001271=2000000\001269=0\001270=1.38897\001271=8000000\001" +
"269=0\001270=1.38854\001271=2000000\001269=1\001270=1.38855\001271=6000000\001" +
"269=1\001270=1.38856\001271=7000000\001269=1\001270=1.38857\001271=3000000\001" +
"269=1\001270=1.38858\001271=9000000\001269=1\001270=1.38859\001271=100000000\00110=51\001",
dd, true);
assertEquals(m.getString(461), "RCSXX=0");
final MarketDataSnapshotFullRefresh.NoMDEntries group = new MarketDataSnapshotFullRefresh.NoMDEntries();
m.getGroup(1, group);
final MDEntryPx px = new MDEntryPx();
group.get(px);
assertEquals(px.objectAsString(), "1.38898");
} catch (final Exception e) {
final String text = e.getMessage();
assertTrue("Wrong exception message: " + text,
text != null && !text.contains("Actual body length"));
}
}
@Test
public void testMessageBytesField() throws Exception {
final Logon logon = new Logon();
final String data = "rawdata";
logon.set(new RawDataLength(data.length()));
logon.setField(new BytesField(RawData.FIELD, data.getBytes()));
//logon.set(new RawData(data));
assertEquals("8=FIX.4.4\0019=21\00135=A\00195=7\00196=rawdata\00110=086\001", logon.toString());
}
@Test
// QFJ-786
public void testInvalidHeaderFields() throws Exception {
String message = "1=03100~11=140605JWI4440~15=USD~21=1~35=D~38=6~40=1~47=A~54=1~55=UNP~59=0~60=20140605-13:58:51.016~63=0~79=03100631~336=1~377=N~581=A~6020=COMPUS~86028=JWI~86029=4440~";
message = message.replace('~', (char) 1);
Message msg = new Message(message, false);
assertTrue(msg.isSetField(Account.FIELD));
}
@Test
// QFJ-791
public void testRepeatingGroupCount() throws Exception {
/*
* Prepare a very simple TradeCaptureReport message template and two
* legs.
*/
Message tcr = new TradeCaptureReport(new TradeReportID("ABC1234"), new PreviouslyReported(
false), new LastQty(1000), new LastPx(5.6789), new TradeDate("20140101"),
new TransactTime(LocalDateTime.now(ZoneOffset.UTC)));
tcr.getHeader().setField(new SenderCompID("SENDER"));
tcr.getHeader().setField(new TargetCompID("TARGET"));
tcr.getHeader().setField(new MsgSeqNum(1));
tcr.getHeader().setField(new SendingTime(LocalDateTime.now(ZoneOffset.UTC)));
TradeCaptureReport.NoLegs leg1 = new TradeCaptureReport.NoLegs();
leg1.setField(new LegSymbol("L1-XYZ"));
leg1.setField(new LegRefID("ABC1234-L1"));
leg1.setField(new LegQty(333));
leg1.setField(new LegPrice(1.2345));
TradeCaptureReport.NoLegs leg2 = new TradeCaptureReport.NoLegs();
leg2.setField(new LegSymbol("L2-XYZ"));
leg2.setField(new LegRefID("ABC1234-L2"));
leg2.setField(new LegQty(777));
leg2.setField(new LegPrice(2.3456));
/*
* Create a message from the template and add two legs. Convert the
* message to string and parse it. The parsed message should contain two
* legs.
*/
{
Message m1 = new Message();
m1.getHeader().setFields(tcr.getHeader());
m1.setFields(tcr);
m1.addGroup(leg1);
m1.addGroup(leg2);
String s1 = m1.toString();
Message parsed1 = new Message(s1, DataDictionaryTest.getDictionary());
assertEquals(s1, parsed1.toString());
assertEquals(2, parsed1.getGroupCount(555));
}
/*
* Create a message from the template and add two legs, but the first
* leg contains the additional tag 58 (Text). Convert the message to
* string and parse it. The parsed message should also contain two legs.
*/
{
Message m2 = new Message();
m2.getHeader().setFields(tcr.getHeader());
m2.setFields(tcr);
leg1.setField(new Text("TXT1")); // add unexpected tag to leg1
m2.addGroup(leg1);
m2.addGroup(leg2);
String s2 = m2.toString();
// do not use validation to parse full message
// regardless of errors in message structure
Message parsed2 = new Message(s2, DataDictionaryTest.getDictionary(), false);
assertEquals(s2, parsed2.toString());
assertEquals(2, parsed2.getGroupCount(555));
/*
* If the above test failed, it means that a simple addition of an
* unexpected tag made the parsing logic fail pretty badly, as the
* number of legs is not 2.
*/
}
}
@Test
// QFJ-791
public void testUnknownFieldsInRepeatingGroupsAndValidation() throws Exception {
Message tcr = new TradeCaptureReport(new TradeReportID("ABC1234"), new PreviouslyReported(
false), new LastQty(1000), new LastPx(5.6789), new TradeDate("20140101"),
new TransactTime(LocalDateTime.now(ZoneOffset.UTC)));
tcr.getHeader().setField(new SenderCompID("SENDER"));
tcr.getHeader().setField(new TargetCompID("TARGET"));
tcr.getHeader().setField(new MsgSeqNum(1));
tcr.getHeader().setField(new SendingTime(LocalDateTime.now(ZoneOffset.UTC)));
tcr.setField(new Symbol("ABC"));
TradeCaptureReport.NoLegs leg1 = new TradeCaptureReport.NoLegs();
leg1.setField(new LegSymbol("L1-XYZ"));
leg1.setField(new LegRefID("ABC1234-L1"));
leg1.setField(new LegQty(333));
leg1.setField(new LegPrice(1.2345));
TradeCaptureReport.NoLegs leg2 = new TradeCaptureReport.NoLegs();
leg2.setField(new LegSymbol("L2-XYZ"));
leg2.setField(new LegRefID("ABC1234-L2"));
leg2.setField(new LegQty(777));
leg2.setField(new LegPrice(2.3456));
TradeCaptureReport.NoSides sides = new TradeCaptureReport.NoSides();
sides.setField(new Side(Side.BUY));
sides.setField(new OrderID("ID"));
{
// will add a user-defined tag (i.e. greater than 5000) that is not defined in that group
Message m1 = new Message();
m1.getHeader().setFields(tcr.getHeader());
m1.setFields(tcr);
leg1.setField(new StringField(10000, "TXT1")); // add unexpected tag to leg1
m1.addGroup(leg1);
m1.addGroup(leg2);
m1.addGroup(sides);
String s1 = m1.toString();
DataDictionary dictionary = new DataDictionary(DataDictionaryTest.getDictionary());
// parsing without validation should succeed
Message parsed1 = new Message(s1, dictionary, false);
// validation should fail
int failingTag = 0;
try {
dictionary.validate(parsed1);
} catch (FieldException e) {
failingTag = e.getField();
}
assertEquals(10000, failingTag);
// but without checking user-defined fields, validation should succeed
dictionary.setCheckUserDefinedFields(false);
dictionary.validate(parsed1);
assertEquals(s1, parsed1.toString());
assertEquals(2, parsed1.getGroupCount(555));
}
{
// will add a normal tag that is not in the dictionary for that group
Message m2 = new Message();
m2.getHeader().setFields(tcr.getHeader());
m2.setFields(tcr);
leg1.removeField(10000); // remove user-defined tag from before
leg1.setField(new Text("TXT1")); // add unexpected tag to leg1
m2.addGroup(leg1);
m2.addGroup(leg2);
m2.addGroup(sides);
String s2 = m2.toString();
DataDictionary dictionary = new DataDictionary(DataDictionaryTest.getDictionary());
// parsing without validation should succeed
Message parsed2 = new Message(s2, dictionary, false);
// validation should fail
int failingTag = 0;
try {
dictionary.validate(parsed2);
} catch (FieldException e) {
failingTag = e.getField();