Search in sources :

Example 6 with Message

use of quickfix.Message in project camel by apache.

the class QuickfixjLazyProducerTest method setUp.

@Before
public void setUp() throws Exception {
    mockExchange = Mockito.mock(Exchange.class);
    mockCamelMessage = Mockito.mock(org.apache.camel.Message.class);
    Mockito.when(mockExchange.getIn()).thenReturn(mockCamelMessage);
    Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOnly);
    quickfixjEngine = TestSupport.createEngine(true);
    endpoint = Mockito.spy(new QuickfixjEndpoint(quickfixjEngine, "", new QuickfixjComponent()));
    inboundFixMessage = new Message();
    inboundFixMessage.getHeader().setString(BeginString.FIELD, FixVersions.BEGINSTRING_FIX44);
    inboundFixMessage.getHeader().setString(SenderCompID.FIELD, "SENDER");
    inboundFixMessage.getHeader().setString(TargetCompID.FIELD, "TARGET");
    sessionID = MessageUtils.getSessionID(inboundFixMessage);
    Mockito.when(mockCamelMessage.getBody(Message.class)).thenReturn(inboundFixMessage);
    Mockito.when(endpoint.getSessionID()).thenReturn(sessionID);
    producer = Mockito.spy(new QuickfixjProducer(endpoint));
}
Also used : Exchange(org.apache.camel.Exchange) Message(quickfix.Message) Before(org.junit.Before)

Example 7 with Message

use of quickfix.Message 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 8 with Message

use of quickfix.Message in project camel by apache.

the class QuickfixjProducerTest method setUp.

@Before
public void setUp() throws ConfigError, FieldConvertError, IOException, JMException {
    mockExchange = Mockito.mock(Exchange.class);
    mockEndpoint = Mockito.mock(QuickfixjEndpoint.class);
    mockCamelMessage = Mockito.mock(org.apache.camel.Message.class);
    Mockito.when(mockExchange.getIn()).thenReturn(mockCamelMessage);
    Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOnly);
    quickfixjEngine = TestSupport.createEngine();
    Mockito.when(mockEndpoint.getEngine()).thenReturn(quickfixjEngine);
    inboundFixMessage = new Message();
    inboundFixMessage.getHeader().setString(BeginString.FIELD, FixVersions.BEGINSTRING_FIX44);
    inboundFixMessage.getHeader().setString(SenderCompID.FIELD, "SENDER");
    inboundFixMessage.getHeader().setString(TargetCompID.FIELD, "TARGET");
    sessionID = MessageUtils.getSessionID(inboundFixMessage);
    Mockito.when(mockCamelMessage.getBody(Message.class)).thenReturn(inboundFixMessage);
    Mockito.when(mockEndpoint.getSessionID()).thenReturn(sessionID);
    producer = Mockito.spy(new QuickfixjProducer(mockEndpoint));
}
Also used : Exchange(org.apache.camel.Exchange) Message(quickfix.Message) Before(org.junit.Before)

Example 9 with Message

use of quickfix.Message in project camel by apache.

the class QuickfixjConverters method toMessage.

@Converter
public static Message toMessage(byte[] value, Exchange exchange) throws InvalidMessage, ConfigError, UnsupportedEncodingException {
    DataDictionary dataDictionary = getDataDictionary(exchange);
    String charsetName = IOHelper.getCharsetName(exchange);
    String message;
    if (charsetName != null) {
        message = new String(value, charsetName);
    } else {
        message = new String(value);
    }
    // if message ends with any sort of newline trim it so QuickfixJ's doesn't fail while parsing the string
    if (message.endsWith("\r\n")) {
        message = message.substring(0, message.length() - 2);
    } else if (message.endsWith("\r") || message.endsWith("\n")) {
        message = message.substring(0, message.length() - 1);
    }
    return new Message(message, dataDictionary, false);
}
Also used : InvalidMessage(quickfix.InvalidMessage) Message(quickfix.Message) DataDictionary(quickfix.DataDictionary) Converter(org.apache.camel.Converter)

Example 10 with Message

use of quickfix.Message 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

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