-
Notifications
You must be signed in to change notification settings - Fork 662
Expand file tree
/
Copy pathRepeatingGroupTest.java
More file actions
600 lines (490 loc) · 27.4 KB
/
RepeatingGroupTest.java
File metadata and controls
600 lines (490 loc) · 27.4 KB
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
/*******************************************************************************
* 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 org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import quickfix.field.BeginString;
import quickfix.field.LegSymbol;
import quickfix.field.OrderID;
import quickfix.field.SessionRejectReason;
import quickfix.field.SettlDate2;
import quickfix.field.Symbol;
import quickfix.fix44.Quote;
import quickfix.fix50sp2.QuoteRequest;
public class RepeatingGroupTest {
// In this testcase we use only FIX4.4 message, but we could use the others
// FIX version. Indeed the group
// management is independent from the version
// NON NESTED Groups
private Quote.NoLegs buildGroupWithStandardFields(String settingValue) {
final Quote.NoLegs grp = new Quote.NoLegs();
grp.set(new LegSymbol(settingValue));
return grp;
}
@Test
public void testSettingGettingGroupWithStandardFields() throws FieldNotFound {
final String settingValue = "SETTING_VALUE";
final Quote.NoLegs grp = buildGroupWithStandardFields(settingValue);
final LegSymbol accessorField = new LegSymbol();
final LegSymbol gotField = (LegSymbol) grp.getField(accessorField);
// We assume that checksum equality s enough - DV
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotField
.getValue());
}
private Quote.NoLegs buildGroupWithCustomFields(String settingValue) {
final Quote.NoLegs grp = new Quote.NoLegs();
grp.setField(new StringField(9001, settingValue)); // Custom tag is
// 9001
return grp;
}
@Test
public void testSettingGettingGroupWithCustomFields() throws FieldNotFound {
final String settingValue = "SETTING_VALUE";
final Quote.NoLegs grp = buildGroupWithCustomFields(settingValue);
final StringField accessorField = new StringField(9001); // Custom tag is
// 9001
final StringField gotField = grp.getField(accessorField);
// We assume that checksum equality s enough - DV
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotField
.getValue());
}
private Quote.NoLegs buildGroupWithCustomAndStandardFields(String settingValue) {
final Quote.NoLegs grp = new Quote.NoLegs();
grp.setField(new StringField(9001, settingValue)); // Custom tag is
// 9001
grp.set(new LegSymbol(settingValue));
return grp;
}
@Test
public void testSettingGettingGroupWithCustomAndStandardFields() throws FieldNotFound {
final String settingValue = "SETTING_VALUE";
final Quote.NoLegs grp = buildGroupWithCustomAndStandardFields(settingValue);
final StringField accessorField = new StringField(9001); // Custom tag is
// 9001
final StringField gotField = grp.getField(accessorField);
final LegSymbol accessorFieldStd = new LegSymbol(); // Standard Field
final LegSymbol gotFieldStd = (LegSymbol) grp.getField(accessorFieldStd);
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotField
.getValue());
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotFieldStd
.getValue());
}
// NESTED Groups outside messages
private quickfix.fix44.QuoteRequest.NoRelatedSym buildNestedGroupWithStandardFields(
String settingValue) {
// The root group
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fix44.QuoteRequest.NoRelatedSym();
// The nested group
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
nestedgroup.setField(new LegSymbol(settingValue));
gNoRelatedSym.addGroup(nestedgroup);
// Adding a second fake nested group to avoid being the case of having
// one element which is not relevant :-)
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs oneMoreNestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
oneMoreNestedgroup.setField(new LegSymbol("Donald"));
gNoRelatedSym.addGroup(oneMoreNestedgroup);
return gNoRelatedSym;
}
private quickfix.fix50sp2.QuoteRequest.NoRelatedSym buildNestedGroupWithStandardFieldsFIX50SP2(
String settingValue) {
// The root group
final quickfix.fix50sp2.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fix50sp2.QuoteRequest.NoRelatedSym();
// The nested group
final quickfix.fix50sp2.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fix50sp2.QuoteRequest.NoRelatedSym.NoLegs();
nestedgroup.setField(new LegSymbol(settingValue));
gNoRelatedSym.addGroup(nestedgroup);
// Adding a second fake nested group to avoid being the case of having
// one element which is not relevant :-)
final quickfix.fix50sp2.QuoteRequest.NoRelatedSym.NoLegs oneMoreNestedgroup = new quickfix.fix50sp2.QuoteRequest.NoRelatedSym.NoLegs();
oneMoreNestedgroup.setField(new LegSymbol("Donald"));
gNoRelatedSym.addGroup(oneMoreNestedgroup);
return gNoRelatedSym;
}
private quickfix.fixlatest.QuoteRequest.NoRelatedSym buildNestedGroupWithStandardFieldsFIXLatest(
String settingValue) {
// The root group
final quickfix.fixlatest.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fixlatest.QuoteRequest.NoRelatedSym();
// The nested group
final quickfix.fixlatest.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fixlatest.QuoteRequest.NoRelatedSym.NoLegs();
nestedgroup.setField(new LegSymbol(settingValue));
gNoRelatedSym.addGroup(nestedgroup);
// Adding a second fake nested group to avoid being the case of having
// one element which is not relevant :-)
final quickfix.fixlatest.QuoteRequest.NoRelatedSym.NoLegs oneMoreNestedgroup = new quickfix.fixlatest.QuoteRequest.NoRelatedSym.NoLegs();
oneMoreNestedgroup.setField(new LegSymbol("Donald"));
gNoRelatedSym.addGroup(oneMoreNestedgroup);
return gNoRelatedSym;
}
@Test
public void testSettingGettingNestedGroupWithStandardFields() throws FieldNotFound {
final String settingValue = "SETTING_VALUE";
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithStandardFields(settingValue);
// Getting part
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs getgrp = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
gNoRelatedSym.getGroup(1, getgrp);
final LegSymbol accessorFieldStd = new LegSymbol(); // Standard Field
final LegSymbol gotFieldStd = (LegSymbol) getgrp.getField(accessorFieldStd);
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotFieldStd
.getValue());
}
private quickfix.fix44.QuoteRequest.NoRelatedSym buildNestedGroupWithCustomFields(
String settingValue) {
// The root group
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fix44.QuoteRequest.NoRelatedSym();
// The nested group
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
nestedgroup.setField(new StringField(9001, settingValue));
gNoRelatedSym.addGroup(nestedgroup);
// Adding a second fake nested group to avoid being the case of having
// one element which is not relevant :-)
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs oneMoreNestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
oneMoreNestedgroup.setField(new StringField(9001, "Donald"));
gNoRelatedSym.addGroup(oneMoreNestedgroup);
return gNoRelatedSym;
}
@Test
public void testSettingGettingNestedGroupWithCustomFields() throws FieldNotFound {
final String settingValue = "SETTING_VALUE";
// The root group
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithCustomFields(settingValue);
// Getting part
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs getgrp = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
gNoRelatedSym.getGroup(1, getgrp);
final StringField accessorField = new StringField(9001); // Custom Field
final StringField gotFieldStd = getgrp.getField(accessorField);
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotFieldStd
.getValue());
}
private quickfix.fix44.QuoteRequest.NoRelatedSym buildNestedGroupWithCustomAndStandardFields(
String settingValue) {
// The root group
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fix44.QuoteRequest.NoRelatedSym();
// The nested group
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
nestedgroup.setField(new LegSymbol(settingValue));
nestedgroup.setField(new StringField(9001, settingValue));
gNoRelatedSym.addGroup(nestedgroup);
// Adding a second fake nested group to avoid being the case of having
// one element which is not relevant :-)
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs oneMoreNestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
oneMoreNestedgroup.setField(new LegSymbol("Donald"));
oneMoreNestedgroup.setField(new StringField(9001, "Donald"));
gNoRelatedSym.addGroup(oneMoreNestedgroup);
return gNoRelatedSym;
}
@Test
public void testSettingGettingNestedGroupWithCustomAndStandardFields() throws FieldNotFound {
final String settingValue = "SETTING_VALUE";
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithCustomAndStandardFields(settingValue);
// Getting part
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs getgrp = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
gNoRelatedSym.getGroup(1, getgrp);
final StringField accessorField = new StringField(9001); // Custom Field
final StringField gotField = getgrp.getField(accessorField);
final LegSymbol accessorFieldStd = new LegSymbol(); // Standard Field
final LegSymbol gotFieldStd = (LegSymbol) getgrp.getField(accessorFieldStd);
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotField
.getValue());
assertEquals("GettingValue is not the same the SettingValue", settingValue, gotFieldStd
.getValue());
}
@Test
// Testing group re-usability when setting values
public void testSettingGettingGroupByReusingGroup() throws FieldNotFound {
// The root group
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fix44.QuoteRequest.NoRelatedSym();
// Create the initial group
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
final String notOverridenFieldValue = "Value1.1";
nestedgroup.setField(new LegSymbol(notOverridenFieldValue));
nestedgroup.setField(new StringField(9001, "Value1.2"));
gNoRelatedSym.addGroup(nestedgroup);
// Create the second group by re-using the same group and changing one value of only one field
final String overridenFieldValue = "Value2.2";
nestedgroup.setField(new StringField(9001, overridenFieldValue));
gNoRelatedSym.addGroup(nestedgroup);
// Getting part
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs getgrp = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
gNoRelatedSym.getGroup(2, getgrp);
final StringField accessorField = new StringField(9001); // Custom Field
final StringField gotField = getgrp.getField(accessorField);
final LegSymbol accessorFieldStd = new LegSymbol(); // Standard Field
final LegSymbol gotFieldStd = (LegSymbol) getgrp.getField(accessorFieldStd);
// Ensures that the field overriden has been set correctly
assertEquals("GettingValue is not the same the SettingValue", overridenFieldValue, gotField
.getValue());
// Ensures that the field not overriden has been set correctly
assertEquals("GettingValue is not the same the SettingValue", notOverridenFieldValue,
gotFieldStd.getValue());
}
// Testing Message validation
private static DataDictionary defaultDataDictionary = null;
private static ValidationSettings defaultDDSettings = null;
private static ValidationSettings ignoreOutOfOrderSettings = null;
private static DataDictionary customDataDictionary = null;
private final DefaultMessageFactory messageFactory = new DefaultMessageFactory();
static {
try {
defaultDataDictionary = new DataDictionary("FIX44.xml");
defaultDDSettings = new ValidationSettings();
ignoreOutOfOrderSettings = new ValidationSettings();
ignoreOutOfOrderSettings.setCheckUnorderedGroupFields(false);
customDataDictionary = new DataDictionary("FIX44_Custom_Test.xml");
} catch (final ConfigError e) {
e.printStackTrace();
}
}
private Message buildValidatedMessage(String sourceFIXString, DataDictionary dd, ValidationSettings validationSettings)
throws InvalidMessage {
final Message message = messageFactory.create(MessageUtils.getStringField(sourceFIXString,
BeginString.FIELD), MessageUtils.getMessageType(sourceFIXString));
message.fromString(sourceFIXString, dd, validationSettings, true);
return message;
}
@Test
public void testValidationWithNestedGroupAndStandardFields() throws InvalidMessage {
final quickfix.fix44.QuoteRequest quoteRequest = new quickfix.fix44.QuoteRequest();
final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
gQuoteReqID.setValue("12342");
quoteRequest.setField(gQuoteReqID);
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithStandardFields("DEFAULT_VALUE");
gNoRelatedSym.setField(new Symbol("SYM00"));
quoteRequest.addGroup(gNoRelatedSym);
quoteRequest.addGroup(gNoRelatedSym);
final String sourceFIXString = quoteRequest.toString();
final quickfix.fix44.QuoteRequest validatedMessage = (quickfix.fix44.QuoteRequest) buildValidatedMessage(
sourceFIXString, defaultDataDictionary, defaultDDSettings);
String validateFIXString = null;
if (validatedMessage != null) {
validateFIXString = validatedMessage.toString();
}
assertEquals("Message validation failed", sourceFIXString, validateFIXString);
}
@Test
public void testValidationWithNestedGroupAndStandardFieldsFIX50SP2() throws InvalidMessage, ConfigError {
final quickfix.fix50sp2.QuoteRequest quoteRequest = new quickfix.fix50sp2.QuoteRequest();
final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
gQuoteReqID.setValue("12342");
quoteRequest.setField(gQuoteReqID);
final quickfix.fix50sp2.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithStandardFieldsFIX50SP2("DEFAULT_VALUE");
gNoRelatedSym.setField(new Symbol("SYM00"));
gNoRelatedSym.setField(new SettlDate2("20120801"));
quoteRequest.addGroup(gNoRelatedSym);
quoteRequest.addGroup(gNoRelatedSym);
final String sourceFIXString = quoteRequest.toString();
final DataDictionary fix50sp2DataDictionary = new DataDictionary("FIX50SP2.xml");
final quickfix.fix50sp2.QuoteRequest validatedMessage = (quickfix.fix50sp2.QuoteRequest) messageFactory.create(FixVersions.FIX50SP2, QuoteRequest.MSGTYPE);
validatedMessage.fromString(sourceFIXString, fix50sp2DataDictionary, new ValidationSettings(), true);
String validateFIXString = validatedMessage.toString();
assertEquals("Message validation failed", sourceFIXString, validateFIXString);
assertEquals(2, validatedMessage.getGroupCount(gNoRelatedSym.getFieldTag()));
}
@Test
public void testValidationWithNestedGroupAndStandardFieldsFIXLatest() throws InvalidMessage, ConfigError {
final quickfix.fixlatest.QuoteRequest quoteRequest = new quickfix.fixlatest.QuoteRequest();
final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
gQuoteReqID.setValue("12342");
quoteRequest.setField(gQuoteReqID);
final quickfix.fixlatest.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithStandardFieldsFIXLatest("DEFAULT_VALUE");
gNoRelatedSym.setField(new Symbol("SYM00"));
gNoRelatedSym.setField(new SettlDate2("20120801"));
quoteRequest.addGroup(gNoRelatedSym);
quoteRequest.addGroup(gNoRelatedSym);
final String sourceFIXString = quoteRequest.toString();
final DataDictionary fixDataDictionary = new DataDictionary("FIXLatest.xml");
final quickfix.fixlatest.QuoteRequest validatedMessage = (quickfix.fixlatest.QuoteRequest) messageFactory.create(FixVersions.FIXLATEST, QuoteRequest.MSGTYPE);
validatedMessage.fromString(sourceFIXString, fixDataDictionary, new ValidationSettings(), true);
String validateFIXString = validatedMessage.toString();
assertEquals("Message validation failed", sourceFIXString, validateFIXString);
assertEquals(2, validatedMessage.getGroupCount(gNoRelatedSym.getFieldTag()));
}
@Test
public void testValidationWithNestedGroupAndStandardFieldsWithoutDelimiter() throws InvalidMessage {
final quickfix.fix44.QuoteRequest quoteRequest = new quickfix.fix44.QuoteRequest();
final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
gQuoteReqID.setValue("12342");
quoteRequest.setField(gQuoteReqID);
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithStandardFields("DEFAULT_VALUE");
quoteRequest.addGroup(gNoRelatedSym);
quoteRequest.addGroup(gNoRelatedSym);
final String sourceFIXString = quoteRequest.toString();
Message buildValidatedMessage = buildValidatedMessage(sourceFIXString, defaultDataDictionary, defaultDDSettings);
assertEquals("The group 146 must set the delimiter field 55", buildValidatedMessage.getException().getMessage());
}
@Test
public void testGroupFieldsOrderWithCustomDataDictionary() throws InvalidMessage {
final quickfix.fix44.QuoteRequest quoteRequest = new quickfix.fix44.QuoteRequest();
final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
gQuoteReqID.setValue("12342");
quoteRequest.setField(gQuoteReqID);
// The root group
final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fix44.QuoteRequest.NoRelatedSym();
gNoRelatedSym.setField(new Symbol("SYM00"));
// The nested group
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
nestedgroup.setField(new LegSymbol("DEFAULT_VALUE"));
nestedgroup.setField(new OrderID("111")); // The non ordered field
nestedgroup.setField(new StringField(9001, "1.9001")); // The custom non ordered field
gNoRelatedSym.addGroup(nestedgroup);
// Adding a second fake nested group to avoid being the case of having
// one element which is not relevant :-)
final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs oneMoreNestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
oneMoreNestedgroup.setField(new LegSymbol("Donald"));
oneMoreNestedgroup.setField(new OrderID("112")); // The non ordered field
oneMoreNestedgroup.setField(new StringField(9001, "2.9001")); // The custom non ordered field
gNoRelatedSym.addGroup(oneMoreNestedgroup);
quoteRequest.addGroup(gNoRelatedSym);
final String sourceFIXString = quoteRequest.toString();
final quickfix.fix44.QuoteRequest validatedMessage = (quickfix.fix44.QuoteRequest) buildValidatedMessage(
sourceFIXString, customDataDictionary, new ValidationSettings());
assertNull("Invalid message", validatedMessage.getException());
String validatedFIXString = validatedMessage.toString();
assertEquals("Message validation failed",
MessageUtils.checksum(sourceFIXString), MessageUtils.checksum(validatedFIXString));
}
@Test
public void testOutOfOrderGroupMembersDelimiterField() throws Exception {
final Message m = new Message(
"8=FIX.4.4\0019=0\00135=D\00134=2\00149=TW\00152=<TIME>\00156=ISLD\00111=ID\001" +
"21=1\00140=1\00154=1\00138=200.00\00155=INTC\00178=2\00180=50\00179=acct1\001" +
"80=150\00179=acct2\00160=<TIME>\00110=000\001",
defaultDataDictionary, defaultDDSettings, false);
try {
defaultDataDictionary.validate(m, defaultDDSettings);
Assert.fail("No exception");
} catch (final FieldException e) {
// expected
assertEquals(SessionRejectReason.REPEATING_GROUP_FIELDS_OUT_OF_ORDER, e
.getSessionRejectReason());
assertEquals(80, e.getField());
}
}
@Test
public void testIgnoreOutOfOrderGroupMembersDelimiterField() throws Exception {
final Message m = new Message(
"8=FIX.4.4\0019=0\00135=D\00134=2\00149=TW\00152=<TIME>\00156=ISLD\00111=ID\001" +
"21=1\00140=1\00154=1\00138=200.00\00155=INTC\00178=2\00180=50\00179=acct1\001" +
"80=150\00179=acct2\00160=<TIME>\00110=000\001",
defaultDataDictionary, ignoreOutOfOrderSettings,false);
try {
defaultDataDictionary.validate(m, ignoreOutOfOrderSettings);
Assert.fail("No exception");
} catch (final FieldException e) {
// expected
assertEquals(SessionRejectReason.REPEATING_GROUP_FIELDS_OUT_OF_ORDER, e
.getSessionRejectReason());
assertEquals(80, e.getField());
}
}
@Test
public void testOutOfOrderGroupMembers() throws Exception {
final Message m = new Message(
"8=FIX.4.4\0019=0\00135=D\00134=2\00149=TW\00152=20080203-00:29:51.453\00156=ISLD\001" +
"11=ID\00121=1\00140=1\00154=1\00138=200.00\00155=INTC\00178=2\00179=acct1\00180=50\001" +
"661=X\00179=acct2\00180=150\001661=X\00160=20080203-00:29:51.453\00110=000\001",
defaultDataDictionary, defaultDDSettings, false);
try {
defaultDataDictionary.validate(m, defaultDDSettings);
Assert.fail("No exception");
} catch (final FieldException e) {
// expected
assertEquals(e.getMessage(), SessionRejectReason.REPEATING_GROUP_FIELDS_OUT_OF_ORDER, e
.getSessionRejectReason());
assertEquals(661, e.getField());
}
}
@Test
public void testIgnoreOutOfOrderGroupMembers() throws Exception {
final Message m = new Message(
"8=FIX.4.4\0019=0\00135=D\00134=2\00149=TW\00152=20080203-00:29:51.453\00156=ISLD\001" +
"11=ID\00121=1\00140=1\00154=1\00138=200.00\00155=INTC\00178=2\00179=acct1\00180=50\001" +
"661=1\00179=acct2\00180=150\001661=2\00160=20080203-00:29:51.453\00110=000\001",
defaultDataDictionary, ignoreOutOfOrderSettings,false);
try {
defaultDataDictionary.validate(m, ignoreOutOfOrderSettings);
} catch (final FieldException e) {
Assert.fail("Exception");
}
}
@Test
public void testRequiredGroupMembers() throws Exception {
// Missing group tag 304
final Message m = new Message("8=FIX.4.4\0019=0\00135=i\00134=2\00149=TW\001" +
"52=20080203-00:29:51.453\00156=ISLD\001117=ID\001296=1\001302=X\00110=000\001",
defaultDataDictionary, defaultDDSettings,false);
try {
defaultDataDictionary.validate(m, defaultDDSettings);
Assert.fail("No exception");
} catch (final FieldException e) {
// expected
assertEquals(e.getMessage(), SessionRejectReason.REQUIRED_TAG_MISSING, e
.getSessionRejectReason());
assertEquals(304, e.getField());
}
}
@Test
public void testWrongGroupCount() throws Exception {
// Excessive group counts in nested group
final Message m = new Message("8=FIX.4.4\0019=0\00135=i\00134=2\00149=TW\001" +
"52=20080203-00:29:51.453\00156=ISLD\001117=ID\001296=1\001302=X\001" +
"304=5\001295=50\001299=QID\00110=085\001",
defaultDataDictionary, defaultDDSettings,true);
try {
defaultDataDictionary.validate(m, defaultDDSettings);
Assert.fail("No exception");
} catch (final FieldException e) {
// expected
assertEquals("Wrong reject reason: [" + e.getMessage() + "]",
SessionRejectReason.INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP, e
.getSessionRejectReason());
assertEquals(295, e.getField());
}
}
@Test
public void testInvalidEnumFieldInGroup() throws Exception {
// Excessive group counts
final Message m = new Message(
"8=FIX.4.4\0019=0\00135=A\00134=2\00152=20080203-00:29:51.453\00156=ISLD\001" +
"49=TW\001108=10\001384=1\001372=D\001385=X\00198=0\00110=129\001",
defaultDataDictionary, defaultDDSettings, false);
try {
defaultDataDictionary.validate(m, defaultDDSettings);
Assert.fail("No exception");
} catch (final IncorrectTagValue e) {
// expected
assertEquals(385, e.getField());
}
}
@Test
public void testSettingGettingGroupWithStandardFieldsInHeader() throws Exception {
final Message m = new Message(
"8=FIX.4.4\0019=87\00135=0\00134=2\00152=20080203-00:29:51.453\00156=ISLD\001" +
"49=TW\001627=2\001628=_TED02A\001629=20090717-13:25:31.896\001628=_GWSURV\001" +
"629=20090717-13:25:31.928\00110=012\001",
defaultDataDictionary, defaultDDSettings, false);
try {
defaultDataDictionary.validate(m, defaultDDSettings);
} catch (final IncorrectTagValue e) {
// not expected
Assert.fail("Exception occured");
}
}
}