1919
2020package quickfix ;
2121
22- import org .junit .Test ;
23-
24- import quickfix .field .ApplVerID ;
2522import quickfix .field .BeginString ;
26- import quickfix .field .DefaultApplVerID ;
27- import quickfix .field .EmailThreadID ;
28- import quickfix .field .EmailType ;
29- import quickfix .field .EncryptMethod ;
30- import quickfix .field .HeartBtInt ;
3123import quickfix .field .MsgType ;
3224import quickfix .field .SenderCompID ;
33- import quickfix .field .Subject ;
34- import quickfix .field .TargetCompID ;
35- import quickfix .fix40 .Logon ;
36- import quickfix .fix50 .Email ;
3725
38- import static org .hamcrest .Matchers .instanceOf ;
39- import static org .hamcrest .Matchers .is ;
40- import static org .hamcrest .Matchers .notNullValue ;
41- import static org .hamcrest .MatcherAssert .assertThat ;
4226import static org .junit .Assert .assertEquals ;
4327import static org .junit .Assert .assertNull ;
4428import static org .junit .Assert .fail ;
4529import org .junit .Test ;
46- import static org .mockito .ArgumentMatchers .any ;
47- import static org .mockito .Mockito .mock ;
48- import static org .mockito .Mockito .when ;
4930
31+ /**
32+ * NOTE: There are two MessageUtilsTests.
33+ * One in quickfixj-base, one in quickfixj-core, which each test
34+ * some functionality. This test excludes some test cases that cannot
35+ * be tested in this module due to classes that are generated in a
36+ * later step, e.g. MessageFactories.
37+ */
5038public class MessageUtilsTest {
5139
5240 @ Test
@@ -58,37 +46,6 @@ public void testGetStringField() throws Exception {
5846 assertNull (messageString , MessageUtils .getStringField (messageString , SenderCompID .FIELD ));
5947 }
6048
61- @ Test
62- public void testSessionIdFromMessage () throws Exception {
63- Message message = new Logon ();
64- message .getHeader ().setString (SenderCompID .FIELD , "TW" );
65- message .getHeader ().setString (TargetCompID .FIELD , "ISLD" );
66- SessionID sessionID = MessageUtils .getSessionID (message );
67- assertEquals (sessionID .getBeginString (), "FIX.4.0" );
68- assertEquals ("TW" , sessionID .getSenderCompID ());
69- assertEquals ("ISLD" , sessionID .getTargetCompID ());
70- }
71-
72- @ Test
73- public void testReverseSessionIdFromMessage () throws Exception {
74- Message message = new Logon ();
75- message .getHeader ().setString (SenderCompID .FIELD , "TW" );
76- message .getHeader ().setString (TargetCompID .FIELD , "ISLD" );
77- SessionID sessionID = MessageUtils .getReverseSessionID (message );
78- assertEquals (sessionID .getBeginString (), "FIX.4.0" );
79- assertEquals ("ISLD" , sessionID .getSenderCompID ());
80- assertEquals ("TW" , sessionID .getTargetCompID ());
81- }
82-
83- @ Test
84- public void testReverseSessionIdFromMessageWithMissingFields () throws Exception {
85- Message message = new Logon ();
86- SessionID sessionID = MessageUtils .getReverseSessionID (message );
87- assertEquals (sessionID .getBeginString (), "FIX.4.0" );
88- assertEquals (sessionID .getSenderCompID (), SessionID .NOT_SET );
89- assertEquals (sessionID .getTargetCompID (), SessionID .NOT_SET );
90- }
91-
9249 @ Test
9350 public void testSessionIdFromRawMessage () throws Exception {
9451 String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 " +
@@ -155,118 +112,4 @@ public void testGetStringFieldWithBadValue() throws Exception {
155112 assertNull (MessageUtils .getStringField (messageString , 10 ));
156113 }
157114
158- @ Test
159- public void testParse () throws Exception {
160- Session mockSession = mock (Session .class );
161- DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
162- when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
163- when (mockSession .getMessageFactory ()).thenReturn (new quickfix .fix40 .MessageFactory ());
164- String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 " +
165- "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223\001 " ;
166-
167- Message message = MessageSessionUtils .parse (mockSession , messageString );
168-
169- assertThat (message , notNullValue ());
170- }
171-
172- @ Test
173- public void testLegacyParse () throws Exception {
174- String data = "8=FIX.4.4\001 9=309\001 35=8\001 49=ASX\001 56=CL1_FIX44\001 34=4\001 " +
175- "52=20060324-01:05:58\001 17=X-B-WOW-1494E9A0:58BD3F9D-1109\001 150=D\001 " +
176- "39=0\001 11=184271\001 38=200\001 198=1494E9A0:58BD3F9D\001 526=4324\001 " +
177- "37=B-WOW-1494E9A0:58BD3F9D\001 55=WOW\001 54=1\001 151=200\001 14=0\001 40=2\001 " +
178- "44=15\001 59=1\001 6=0\001 453=3\001 448=AAA35791\001 447=D\001 452=3\001 448=8\001 " +
179- "447=D\001 452=4\001 448=FIX11\001 447=D\001 452=36\001 60=20060320-03:34:29\001 10=169\001 " ;
180-
181- Message message = MessageUtils .parse (new quickfix .fix40 .MessageFactory (), DataDictionaryTest .getDictionary (), data );
182- assertThat (message , notNullValue ());
183- }
184-
185- @ Test
186- public void testParseFixt () throws Exception {
187- Session mockSession = mock (Session .class );
188- DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
189- when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
190- when (mockSession .getMessageFactory ()).thenReturn (new quickfix .fix40 .MessageFactory ());
191-
192- Email email = new Email (new EmailThreadID ("THREAD_ID" ), new EmailType (EmailType .NEW ), new Subject ("SUBJECT" ));
193- email .getHeader ().setField (new ApplVerID (ApplVerID .FIX42 ));
194- email .getHeader ().setField (new SenderCompID ("SENDER" ));
195- email .getHeader ().setField (new TargetCompID ("TARGET" ));
196-
197- Message message = MessageSessionUtils .parse (mockSession , email .toString ());
198-
199- assertThat (message , is (notNullValue ()));
200- assertThat (message , instanceOf (quickfix .fix40 .Email .class ));
201- }
202-
203- @ Test
204- public void testParseFixtLogon () throws Exception {
205- Session mockSession = mock (Session .class );
206- DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
207- when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
208- when (mockSession .getMessageFactory ()).thenReturn (new DefaultMessageFactory ());
209-
210- quickfix .fixt11 .Logon logon = new quickfix .fixt11 .Logon (new EncryptMethod (EncryptMethod .NONE_OTHER ), new HeartBtInt (30 ),
211- new DefaultApplVerID (ApplVerID .FIX42 ));
212-
213- Message message = MessageSessionUtils .parse (mockSession , logon .toString ());
214-
215- assertThat (message , is (notNullValue ()));
216- assertThat (message , instanceOf (quickfix .fixt11 .Logon .class ));
217- }
218-
219- @ Test
220- public void testParseFixtLogout () throws Exception {
221- Session mockSession = mock (Session .class );
222- DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
223- when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
224- when (mockSession .getMessageFactory ()).thenReturn (new DefaultMessageFactory ());
225-
226- quickfix .fixt11 .Logout logout = new quickfix .fixt11 .Logout ();
227-
228- Message message = MessageSessionUtils .parse (mockSession , logout .toString ());
229-
230- assertThat (message , is (notNullValue ()));
231- assertThat (message , instanceOf (quickfix .fixt11 .Logout .class ));
232- }
233-
234- @ Test
235- public void testParseFix50 () throws Exception {
236- Session mockSession = mock (Session .class );
237- DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
238- when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
239- when (mockSession .getMessageFactory ()).thenReturn (new DefaultMessageFactory ());
240-
241- Email email = new Email (new EmailThreadID ("THREAD_ID" ), new EmailType (EmailType .NEW ), new Subject ("SUBJECT" ));
242- email .getHeader ().setField (new ApplVerID (ApplVerID .FIX50 ));
243- email .getHeader ().setField (new SenderCompID ("SENDER" ));
244- email .getHeader ().setField (new TargetCompID ("TARGET" ));
245-
246- Message message = MessageSessionUtils .parse (mockSession , email .toString ());
247-
248- assertThat (message , is (notNullValue ()));
249- assertThat (message , instanceOf (quickfix .fix50 .Email .class ));
250- }
251-
252- // QFJ-973
253- @ Test
254- public void testParseMessageWithoutChecksumValidation () throws InvalidMessage {
255- Session mockSession = mock (Session .class );
256- when (mockSession .isValidateChecksum ()).thenReturn (Boolean .FALSE );
257-
258- DataDictionary dataDictionary = mock (DataDictionary .class );
259- DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
260- when (mockDataDictionaryProvider .getSessionDataDictionary (any (String .class ))).thenReturn (dataDictionary );
261- when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
262- when (mockSession .getMessageFactory ()).thenReturn (new quickfix .fix40 .MessageFactory ());
263-
264- String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 " +
265- "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=283\001 " ;
266-
267- Message message = MessageSessionUtils .parse (mockSession , messageString );
268-
269- assertThat (message , notNullValue ());
270- }
271-
272115}
0 commit comments