Search in sources :

Example 11 with SessionID

use of quickfix.SessionID 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 12 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjSpringTest method configureInSpring.

@Test
public void configureInSpring() throws Exception {
    if (isJava16()) {
        // cannot test on java 1.6
        return;
    }
    SessionID sessionID = new SessionID("FIX.4.2:INITIATOR->ACCEPTOR");
    QuickfixjConfiguration configuration = context.getRegistry().lookupByNameAndType("quickfixjConfiguration", QuickfixjConfiguration.class);
    SessionSettings springSessionSettings = configuration.createSessionSettings();
    Properties sessionProperties = springSessionSettings.getSessionProperties(sessionID, true);
    assertThat(sessionProperties.get("ConnectionType").toString(), CoreMatchers.is("initiator"));
    assertThat(sessionProperties.get("SocketConnectProtocol").toString(), CoreMatchers.is("VM_PIPE"));
    QuickfixjComponent component = context.getComponent("quickfix", QuickfixjComponent.class);
    assertThat(component.isLazyCreateEngines(), is(false));
    QuickfixjEngine engine = component.getEngines().values().iterator().next();
    assertThat(engine.isInitialized(), is(true));
    QuickfixjComponent lazyComponent = context.getComponent("lazyQuickfix", QuickfixjComponent.class);
    assertThat(lazyComponent.isLazyCreateEngines(), is(true));
    QuickfixjEngine lazyEngine = lazyComponent.getEngines().values().iterator().next();
    assertThat(lazyEngine.isInitialized(), is(false));
    assertThat(engine.getMessageFactory(), is(instanceOf(CustomMessageFactory.class)));
}
Also used : Properties(java.util.Properties) SessionID(quickfix.SessionID) SessionSettings(quickfix.SessionSettings) Test(org.junit.Test)

Example 13 with SessionID

use of quickfix.SessionID 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 14 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjComponentTest method setUp.

@Before
public void setUp() throws Exception {
    settingsFile = File.createTempFile("quickfixj_test_", ".cfg");
    settingsFile2 = File.createTempFile("quickfixj_test2_", ".cfg");
    tempdir = settingsFile.getParentFile();
    tempdir2 = settingsFile.getParentFile();
    URL[] urls = new URL[] { tempdir.toURI().toURL(), tempdir2.toURI().toURL() };
    sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "FOO", "BAR");
    settings = new SessionSettings();
    settings.setString(Acceptor.SETTING_SOCKET_ACCEPT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setString(Initiator.SETTING_SOCKET_CONNECT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setBool(Session.SETTING_USE_DATA_DICTIONARY, false);
    setSessionID(settings, sessionID);
    contextClassLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader testClassLoader = new URLClassLoader(urls, contextClassLoader);
    Thread.currentThread().setContextClassLoader(testClassLoader);
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) SessionID(quickfix.SessionID) URL(java.net.URL) SessionSettings(quickfix.SessionSettings) Before(org.junit.Before)

Example 15 with SessionID

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

SessionID (quickfix.SessionID)27 Test (org.junit.Test)13 Message (quickfix.Message)13 Session (quickfix.Session)7 Exchange (org.apache.camel.Exchange)6 SessionSettings (quickfix.SessionSettings)6 DefaultExchange (org.apache.camel.impl.DefaultExchange)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 DataDictionary (quickfix.DataDictionary)4 ArrayList (java.util.ArrayList)3 NoHops (quickfix.fix44.Message.Header.NoHops)3 IOException (java.io.IOException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 Properties (java.util.Properties)2 Before (org.junit.Before)2 BeginString (quickfix.field.BeginString)2 Email (quickfix.fix42.Email)2 MalformedURLException (java.net.MalformedURLException)1 Date (java.util.Date)1