|
23 | 23 | import org.junit.Test; |
24 | 24 | import quickfix.FixVersions; |
25 | 25 | import quickfix.Message; |
| 26 | +import quickfix.MessageUtils; |
26 | 27 | import quickfix.Responder; |
27 | 28 | import quickfix.Session; |
28 | 29 | import quickfix.SessionFactoryTestSupport; |
|
33 | 34 | import quickfix.field.ApplVerID; |
34 | 35 | import quickfix.field.DefaultApplVerID; |
35 | 36 | import quickfix.field.EncryptMethod; |
| 37 | +import quickfix.field.Headline; |
36 | 38 | import quickfix.field.HeartBtInt; |
37 | 39 | import quickfix.field.MsgSeqNum; |
38 | 40 | import quickfix.field.MsgType; |
|
42 | 44 | import quickfix.field.Text; |
43 | 45 | import quickfix.fix44.Logout; |
44 | 46 | import quickfix.fixt11.Logon; |
| 47 | +import quickfix.fix50.News; |
45 | 48 | import quickfix.mina.EventHandlingStrategy; |
46 | 49 | import quickfix.mina.NetworkingOptions; |
47 | 50 | import quickfix.mina.SessionConnector; |
|
56 | 59 |
|
57 | 60 | import static org.junit.Assert.assertEquals; |
58 | 61 | import static org.junit.Assert.assertNull; |
| 62 | +import static org.junit.Assert.assertTrue; |
59 | 63 | import static org.mockito.Mockito.mock; |
60 | 64 | import static org.mockito.Mockito.verify; |
61 | 65 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
@@ -101,6 +105,42 @@ public void testFIXTLogonAndApplVerID() throws Exception { |
101 | 105 | } |
102 | 106 | } |
103 | 107 |
|
| 108 | + @Test |
| 109 | + public void testFIXTLogonAndUnknownApplVerID() throws Exception { |
| 110 | + EventHandlingStrategy mockEventHandlingStrategy = mock(EventHandlingStrategy.class); |
| 111 | + IoSession mockIoSession = mock(IoSession.class); |
| 112 | + SessionSettings settings = mock(SessionSettings.class); |
| 113 | + |
| 114 | + final SessionID sessionID = new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", |
| 115 | + "TARGET"); |
| 116 | + final UnitTestApplication unitTestApplication = new UnitTestApplication(); |
| 117 | + try (Session session = SessionFactoryTestSupport.createSession(sessionID, unitTestApplication, false, false, true, true, new DefaultApplVerID(DefaultApplVerID.FIX50SP2))) { |
| 118 | + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); // to create a new Session |
| 119 | + |
| 120 | + final HashMap<SessionID, Session> acceptorSessions = new HashMap<>(); |
| 121 | + acceptorSessions.put(sessionID, session); |
| 122 | + final StaticAcceptorSessionProvider sessionProvider = createSessionProvider(acceptorSessions); |
| 123 | + |
| 124 | + final AcceptorIoHandler handler = new AcceptorIoHandler(sessionProvider, |
| 125 | + settings, new NetworkingOptions(new Properties()), mockEventHandlingStrategy); |
| 126 | + |
| 127 | + final DefaultApplVerID defaultApplVerID = new DefaultApplVerID("33"); |
| 128 | + final Logon message = new Logon(new EncryptMethod(EncryptMethod.NONE_OTHER), |
| 129 | + new HeartBtInt(30), defaultApplVerID); |
| 130 | + message.getHeader().setString(TargetCompID.FIELD, sessionID.getSenderCompID()); |
| 131 | + message.getHeader().setString(SenderCompID.FIELD, sessionID.getTargetCompID()); |
| 132 | + message.getHeader().setField(new SendingTime(LocalDateTime.now())); |
| 133 | + message.getHeader().setInt(MsgSeqNum.FIELD, 1); |
| 134 | + |
| 135 | + handler.messageReceived(mockIoSession, message.toString()); |
| 136 | + session.next(message); |
| 137 | + |
| 138 | + Message lastToAdminMessage = unitTestApplication.lastToAdminMessage(); |
| 139 | + assertEquals(MsgType.LOGOUT, MessageUtils.getMessageType(lastToAdminMessage.toString())); |
| 140 | + assertTrue(lastToAdminMessage.getString(Text.FIELD).contains("Invalid DefaultApplVerID=33")); |
| 141 | + } |
| 142 | + } |
| 143 | + |
104 | 144 | @Test |
105 | 145 | public void testMessageBeforeLogon() throws Exception { |
106 | 146 | IoSession mockIoSession = mock(IoSession.class); |
|
0 commit comments