Search in sources :

Example 6 with Session

use of quickfix.Session in project camel by apache.

the class QuickfixjProducerTest method processInOutExchangeSuccess.

@Test
public void processInOutExchangeSuccess() throws Exception {
    Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
    SessionID responseSessionID = new SessionID(sessionID.getBeginString(), sessionID.getTargetCompID(), sessionID.getSenderCompID());
    Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_CRITERIA_KEY)).thenReturn(new MessagePredicate(responseSessionID, MsgType.EMAIL));
    Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_TIMEOUT_KEY, 1000L, Long.class)).thenReturn(5000L);
    org.apache.camel.Message mockOutboundCamelMessage = Mockito.mock(org.apache.camel.Message.class);
    Mockito.when(mockExchange.getOut()).thenReturn(mockOutboundCamelMessage);
    final Message outboundFixMessage = new Email();
    outboundFixMessage.getHeader().setString(SenderCompID.FIELD, "TARGET");
    outboundFixMessage.getHeader().setString(TargetCompID.FIELD, "SENDER");
    Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
    Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
    Mockito.doAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    try {
                        quickfixjEngine.getMessageCorrelator().onEvent(QuickfixjEventCategory.AppMessageReceived, sessionID, outboundFixMessage);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }, 10);
            return true;
        }
    }).when(mockSession).send(Matchers.isA(Message.class));
    producer.process(mockExchange);
    Mockito.verify(mockExchange, Mockito.never()).setException(Matchers.isA(IllegalStateException.class));
    Mockito.verify(mockSession).send(inboundFixMessage);
    Mockito.verify(mockOutboundCamelMessage).getHeaders();
    Mockito.verify(mockOutboundCamelMessage).setBody(outboundFixMessage);
}
Also used : Email(quickfix.fix42.Email) Message(quickfix.Message) IOException(java.io.IOException) JMException(javax.management.JMException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SessionID(quickfix.SessionID) Session(quickfix.Session) Test(org.junit.Test)

Example 7 with Session

use of quickfix.Session in project camel by apache.

the class QuickfixjProducerTest method processInOnlyExchangeSuccess.

@Test
public void processInOnlyExchangeSuccess() throws Exception {
    Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
    Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
    Mockito.doReturn(true).when(mockSession).send(Matchers.isA(Message.class));
    producer.process(mockExchange);
    Mockito.verify(mockExchange, Mockito.never()).setException(Matchers.isA(IllegalStateException.class));
    Mockito.verify(mockSession).send(inboundFixMessage);
}
Also used : Message(quickfix.Message) Session(quickfix.Session) Test(org.junit.Test)

Example 8 with Session

use of quickfix.Session in project camel by apache.

the class QuickfixjProducerTest method processInOnlyExchangeSendUnsuccessful.

@Test
public void processInOnlyExchangeSendUnsuccessful() throws Exception {
    Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
    Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
    Mockito.doReturn(false).when(mockSession).send(Matchers.isA(Message.class));
    producer.process(mockExchange);
    Mockito.verify(mockSession).send(inboundFixMessage);
    Mockito.verify(mockExchange).setException(Matchers.isA(CannotSendException.class));
}
Also used : Message(quickfix.Message) Session(quickfix.Session) Test(org.junit.Test)

Example 9 with Session

use of quickfix.Session in project camel by apache.

the class QuickfixjConverters method getDataDictionary.

private static DataDictionary getDataDictionary(Exchange exchange) throws ConfigError {
    Object dictionaryValue = exchange.getProperties().get(QuickfixjEndpoint.DATA_DICTIONARY_KEY);
    DataDictionary dataDictionary = null;
    if (dictionaryValue instanceof DataDictionary) {
        dataDictionary = (DataDictionary) dictionaryValue;
    } else if (dictionaryValue instanceof String) {
        dataDictionary = new DataDictionary((String) dictionaryValue);
    } else {
        SessionID sessionID = exchange.getIn().getHeader(QuickfixjEndpoint.SESSION_ID_KEY, SessionID.class);
        if (sessionID != null) {
            Session session = Session.lookupSession(sessionID);
            dataDictionary = session != null ? session.getDataDictionary() : null;
        }
    }
    return dataDictionary;
}
Also used : DataDictionary(quickfix.DataDictionary) SessionID(quickfix.SessionID) Session(quickfix.Session)

Example 10 with Session

use of quickfix.Session in project camel by apache.

the class QuickfixjConsumerTest method processInOutExchange.

@Test
public void processInOutExchange() throws Exception {
    org.apache.camel.Message mockCamelOutMessage = Mockito.mock(org.apache.camel.Message.class);
    org.apache.camel.Message mockCamelInMessage = Mockito.mock(org.apache.camel.Message.class);
    SessionID mockSessionId = Mockito.mock(SessionID.class);
    Session mockSession = Mockito.mock(Session.class);
    QuickfixjConsumer consumer = Mockito.spy(new QuickfixjConsumer(mockEndpoint, mockProcessor));
    Mockito.doReturn(mockSession).when(consumer).getSession(mockSessionId);
    Mockito.doReturn(true).when(mockSession).send(Matchers.isA(Message.class));
    Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
    Mockito.when(mockExchange.hasOut()).thenReturn(true);
    Mockito.when(mockExchange.getOut()).thenReturn(mockCamelOutMessage);
    Message outboundFixMessage = new Message();
    Mockito.when(mockCamelOutMessage.getBody(Message.class)).thenReturn(outboundFixMessage);
    Mockito.when(mockExchange.getIn()).thenReturn(mockCamelInMessage);
    Mockito.when(mockCamelInMessage.getHeader("SessionID", SessionID.class)).thenReturn(mockSessionId);
    consumer.start();
    consumer.onExchange(mockExchange);
    Mockito.verify(mockExchange, Mockito.never()).setException(Matchers.isA(Exception.class));
    Mockito.verify(mockSession).send(outboundFixMessage);
}
Also used : Message(quickfix.Message) SessionID(quickfix.SessionID) Session(quickfix.Session) Test(org.junit.Test)

Aggregations

Session (quickfix.Session)12 Message (quickfix.Message)8 SessionID (quickfix.SessionID)7 Test (org.junit.Test)6 DataDictionary (quickfix.DataDictionary)4 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 Email (quickfix.fix42.Email)2 Message (org.apache.camel.Message)1 DataDictionaryProvider (quickfix.DataDictionaryProvider)1 SessionNotFound (quickfix.SessionNotFound)1 ApplVerID (quickfix.field.ApplVerID)1