use of quickfix.SessionID in project camel by apache.
the class QuickfixjEngineTest method sessionEvents.
@Test
public void sessionEvents() throws Exception {
SessionID acceptorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "MARKET", "TRADER");
SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "TRADER", "MARKET");
quickfixjEngine = new QuickfixjEngine("quickfix:test", "examples/inprocess.cfg");
doLogonEventsTest(acceptorSessionID, initiatorSessionID, quickfixjEngine);
doApplicationMessageEventsTest(acceptorSessionID, initiatorSessionID, quickfixjEngine);
doLogoffEventsTest(acceptorSessionID, initiatorSessionID, quickfixjEngine);
}
use of quickfix.SessionID in project camel by apache.
the class QuickfixjEngineTest method doApplicationMessageEventsTest.
private void doApplicationMessageEventsTest(SessionID acceptorSessionID, SessionID initiatorSessionID, QuickfixjEngine quickfixjEngine) throws SessionNotFound, InterruptedException, FieldNotFound {
final List<EventRecord> events = new ArrayList<EventRecord>();
final CountDownLatch messageLatch = new CountDownLatch(1);
QuickfixjEventListener messageListener = new QuickfixjEventListener() {
@Override
public synchronized void onEvent(QuickfixjEventCategory eventCategory, SessionID sessionID, Message message) {
EventRecord event = new EventRecord(eventCategory, sessionID, message);
events.add(event);
if (eventCategory == QuickfixjEventCategory.AppMessageReceived) {
messageLatch.countDown();
}
}
};
quickfixjEngine.addEventListener(messageListener);
Email email = TestSupport.createEmailMessage("Test");
Session.sendToTarget(email, initiatorSessionID);
assertTrue("Application message not received", messageLatch.await(5000, TimeUnit.MILLISECONDS));
quickfixjEngine.removeEventListener(messageListener);
assertThat(events.size(), is(2));
EventRecord sendEvent = new EventRecord(QuickfixjEventCategory.AppMessageSent, initiatorSessionID, new Message());
assertTrue(events.contains(sendEvent));
int sendEventIndex = events.indexOf(sendEvent);
assertThat(events.get(sendEventIndex).message.getHeader().getString(MsgType.FIELD), is(MsgType.EMAIL));
EventRecord receiveEvent = new EventRecord(QuickfixjEventCategory.AppMessageReceived, acceptorSessionID, new Message());
assertTrue(events.contains(receiveEvent));
int receiveEventIndex = events.indexOf(receiveEvent);
assertThat(events.get(receiveEventIndex).message.getHeader().getString(MsgType.FIELD), is(MsgType.EMAIL));
}
use of quickfix.SessionID in project camel by apache.
the class QuickfixjEngineTest method doLogoffEventsTest.
private void doLogoffEventsTest(SessionID acceptorSessionID, SessionID initiatorSessionID, QuickfixjEngine quickfixjEngine) throws Exception {
final List<EventRecord> events = new ArrayList<EventRecord>();
final CountDownLatch logoffLatch = new CountDownLatch(2);
QuickfixjEventListener logoffListener = new QuickfixjEventListener() {
@Override
public synchronized void onEvent(QuickfixjEventCategory eventCategory, SessionID sessionID, Message message) {
EventRecord event = new EventRecord(eventCategory, sessionID, message);
events.add(event);
if (eventCategory == QuickfixjEventCategory.SessionLogoff) {
logoffLatch.countDown();
}
}
};
quickfixjEngine.addEventListener(logoffListener);
quickfixjEngine.stop();
assertTrue("Logoffs not received", logoffLatch.await(5000, TimeUnit.MILLISECONDS));
quickfixjEngine.removeEventListener(logoffListener);
assertThat(events.size(), is(2));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogoff, acceptorSessionID, null)));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogoff, initiatorSessionID, null)));
}
use of quickfix.SessionID in project camel by apache.
the class QuickfixjEngineTest method minimalInitiatorAndAcceptor.
@Test
public void minimalInitiatorAndAcceptor() throws Exception {
settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
settings.setLong(sessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 1234);
SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "FARGLE", "BARGLE");
settings.setString(initiatorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
TestSupport.setSessionID(settings, initiatorSessionID);
writeSettings();
quickfixjEngine = new QuickfixjEngine("quickfix:test", settingsFile.getName());
assertThat(quickfixjEngine.getInitiator(), notNullValue());
assertThat(quickfixjEngine.getAcceptor(), notNullValue());
assertDefaultConfiguration(quickfixjEngine);
}
use of quickfix.SessionID in project camel by apache.
the class QuickfixjEventJsonTransformer method transform.
public String transform(Exchange exchange) {
SessionID sessionID = exchange.getIn().getHeader(QuickfixjEndpoint.SESSION_ID_KEY, SessionID.class);
Session session = Session.lookupSession(sessionID);
DataDictionary dataDictionary = session.getDataDictionary();
if (dataDictionary == null) {
throw new IllegalStateException("No Data Dictionary. Exchange must reference an existing session");
}
StringBuilder sb = new StringBuilder();
sb.append("\"event\": {\n");
org.apache.camel.Message in = exchange.getIn();
for (String key : in.getHeaders().keySet()) {
sb.append(" \"").append(key).append("\": ").append(in.getHeader(key)).append(",\n");
}
sb.append(renderer.transform(in.getBody(Message.class), " ", dataDictionary)).append("\n");
sb.append("}\n");
return sb.toString();
}
Aggregations