Search in sources :

Example 11 with Message

use of quickfix.Message in project camel by apache.

the class QuickfixjConvertersTest method convertMessageWithRepeatingGroupsUsingExchangeDictionaryResource.

@Test
public void convertMessageWithRepeatingGroupsUsingExchangeDictionaryResource() throws Exception {
    SessionID sessionID = new SessionID("FIX.4.4", "FOO", "BAR");
    createSession(sessionID);
    try {
        String data = "8=FIX.4.4\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=230\001";
        Exchange exchange = new DefaultExchange(context);
        exchange.setProperty(QuickfixjEndpoint.DATA_DICTIONARY_KEY, "FIX44.xml");
        exchange.getIn().setBody(data);
        Message message = exchange.getIn().getBody(Message.class);
        NoHops hop = new NoHops();
        message.getHeader().getGroup(1, hop);
        assertEquals("FOO", hop.getString(HopCompID.FIELD));
        message.getHeader().getGroup(2, hop);
        assertEquals("BAR", hop.getString(HopCompID.FIELD));
    } finally {
        quickfixjEngine.stop();
    }
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) NoHops(quickfix.fix44.Message.Header.NoHops) Message(quickfix.Message) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 12 with Message

use of quickfix.Message in project camel by apache.

the class QuickfixjConvertersTest method convertToExchange.

@Test
public void convertToExchange() {
    SessionID sessionID = new SessionID("FIX.4.0", "FOO", "BAR");
    QuickfixjEndpoint endpoint = new QuickfixjEndpoint(null, "", new QuickfixjComponent());
    Message message = new Message();
    message.getHeader().setString(MsgType.FIELD, MsgType.ORDER_SINGLE);
    Exchange exchange = QuickfixjConverters.toExchange(endpoint, sessionID, message, QuickfixjEventCategory.AppMessageSent);
    assertThat((SessionID) exchange.getIn().getHeader(QuickfixjEndpoint.SESSION_ID_KEY), is(sessionID));
    assertThat((QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY), is(QuickfixjEventCategory.AppMessageSent));
    assertThat((String) exchange.getIn().getHeader(QuickfixjEndpoint.MESSAGE_TYPE_KEY), is(MsgType.ORDER_SINGLE));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(quickfix.Message) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 13 with Message

use of quickfix.Message in project camel by apache.

the class QuickfixjConvertersTest method convertMessageWithRepeatingGroupsUsingExchangeDictionary.

@Test
public void convertMessageWithRepeatingGroupsUsingExchangeDictionary() throws Exception {
    SessionID sessionID = new SessionID("FIX.4.4", "FOO", "BAR");
    createSession(sessionID);
    try {
        String data = "8=FIX.4.4\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=230\001";
        Exchange exchange = new DefaultExchange(context);
        exchange.setProperty(QuickfixjEndpoint.DATA_DICTIONARY_KEY, new DataDictionary("FIX44.xml"));
        exchange.getIn().setBody(data);
        Message message = exchange.getIn().getBody(Message.class);
        NoHops hop = new NoHops();
        message.getHeader().getGroup(1, hop);
        assertEquals("FOO", hop.getString(HopCompID.FIELD));
        message.getHeader().getGroup(2, hop);
        assertEquals("BAR", hop.getString(HopCompID.FIELD));
    } finally {
        quickfixjEngine.stop();
    }
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) NoHops(quickfix.fix44.Message.Header.NoHops) Message(quickfix.Message) DataDictionary(quickfix.DataDictionary) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 14 with Message

use of quickfix.Message in project camel by apache.

the class QuickfixjConvertersTest method convertMessageWithRepeatingGroupsUsingSessionID.

@Test
public void convertMessageWithRepeatingGroupsUsingSessionID() throws Exception {
    SessionID sessionID = new SessionID("FIX.4.4", "FOO", "BAR");
    createSession(sessionID);
    try {
        String data = "8=FIX.4.4\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=230\001";
        Exchange exchange = new DefaultExchange(context);
        exchange.getIn().setHeader(QuickfixjEndpoint.SESSION_ID_KEY, sessionID);
        exchange.getIn().setBody(data);
        Message message = exchange.getIn().getBody(Message.class);
        NoHops hop = new NoHops();
        message.getHeader().getGroup(1, hop);
        assertEquals("FOO", hop.getString(HopCompID.FIELD));
        message.getHeader().getGroup(2, hop);
        assertEquals("BAR", hop.getString(HopCompID.FIELD));
    } finally {
        quickfixjEngine.stop();
    }
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) NoHops(quickfix.fix44.Message.Header.NoHops) Message(quickfix.Message) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 15 with Message

use of quickfix.Message 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));
}
Also used : Email(quickfix.fix42.Email) Message(quickfix.Message) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) SessionID(quickfix.SessionID)

Aggregations

Message (quickfix.Message)17 SessionID (quickfix.SessionID)12 Test (org.junit.Test)8 Exchange (org.apache.camel.Exchange)7 DefaultExchange (org.apache.camel.impl.DefaultExchange)4 Session (quickfix.Session)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Before (org.junit.Before)3 Email (quickfix.fix42.Email)3 NoHops (quickfix.fix44.Message.Header.NoHops)3 IOException (java.io.IOException)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 JMException (javax.management.JMException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 DataDictionary (quickfix.DataDictionary)2 Converter (org.apache.camel.Converter)1 Processor (org.apache.camel.Processor)1 InvalidMessage (quickfix.InvalidMessage)1