Package quickfix

Examples of quickfix.Message


    private static final String CHECKSUM        = "67890";
    private static final String TX_DATE         = new Date().toString();
    private static final String SESSION_ID      = "FIX.4.1:BANZAI->SYNAPSE";

    public void testSimpleFIXMessage() throws Exception {
        Message message = new NewOrderSingle();
        message.getHeader().setField(new BeginString(BEGIN_STRING));
        message.getHeader().setField(new SenderCompID(SENDER_ID));
        message.getHeader().setField(new TargetCompID(TARGET_ID));
        message.getHeader().setField(new MsgSeqNum(SEQ_NUM));

        message.setField(new Symbol(SYMBOL));
        message.setField(new ClOrdID(CLORD_ID));
        message.setField(new TradeOriginationDate(TX_DATE));

        message.getTrailer().setField(new CheckSum(CHECKSUM));

        MessageContext msgCtx = new MessageContext();
        FIXUtils.getInstance().setSOAPEnvelope(message, SEQ_NUM, SESSION_ID, msgCtx);
        String result = msgCtx.getEnvelope().getBody().getFirstElement().toString();
        String expected =
View Full Code Here


        assertXMLEqual(expected, AXIOMUtil.stringToOM(result).toString());       
    }

    public void testAdvancedFIXMessage() throws Exception {
        Message message = new NewOrderSingle();
        message.getHeader().setField(new BeginString(BEGIN_STRING));
        message.getHeader().setField(new SenderCompID(SENDER_ID));
        message.getHeader().setField(new TargetCompID(TARGET_ID));
        message.getHeader().setField(new MsgSeqNum(SEQ_NUM));

        message.setField(new Symbol(SYMBOL));
        message.setField(new ClOrdID(CLORD_ID));
        message.setField(new TradeOriginationDate(TX_DATE));

        Group g1 = new Group(NoAllocs.FIELD, AllocAccount.FIELD);
        g1.setField(new AllocAccount("ABC"));
        g1.setField(new IndividualAllocID("PQR"));
        message.addGroup(g1);
        Group g2 = new Group(NoAllocs.FIELD, AllocAccount.FIELD);
        g2.setField(new AllocAccount("MNO"));
        g2.setField(new IndividualAllocID("XYZ"));
        message.addGroup(g2);

        message.getTrailer().setField(new CheckSum(CHECKSUM));

        MessageContext msgCtx = new MessageContext();
        FIXUtils.getInstance().setSOAPEnvelope(message, SEQ_NUM, SESSION_ID, msgCtx);
        String result = msgCtx.getEnvelope().getBody().getFirstElement().toString();
        String expected =
View Full Code Here

    }

    @Converter
    public static Message toMessage(String value, Exchange exchange) throws InvalidMessage, ConfigError {
        DataDictionary dataDictionary = getDataDictionary(exchange);
        return new Message(value, dataDictionary);
    }
View Full Code Here

            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);
    }
View Full Code Here

        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);
  
View Full Code Here

            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
View Full Code Here

        mockExchange = Mockito.mock(Exchange.class);
        org.apache.camel.Message mockCamelMessage = Mockito.mock(org.apache.camel.Message.class);
        Mockito.when(mockExchange.getIn()).thenReturn(mockCamelMessage);
       
        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(quickfix.Message.class)).thenReturn(inboundFixMessage);
View Full Code Here

    public void setExceptionOnInOutExchange() throws Exception {           
        org.apache.camel.Message mockCamelOutMessage = Mockito.mock(org.apache.camel.Message.class);
        Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
        Mockito.when(mockExchange.hasOut()).thenReturn(true);
        Mockito.when(mockExchange.getOut()).thenReturn(mockCamelOutMessage);
        Mockito.when(mockCamelOutMessage.getBody(Message.class)).thenReturn(new Message());
       
        QuickfixjConsumer consumer = new QuickfixjConsumer(mockEndpoint, mockProcessor);
        consumer.start();
       
        // Simulate a message from the FIX engine
View Full Code Here

    @Test
    public void processInOutExchange() throws Exception {
        org.apache.camel.Message mockCamelOutMessage = Mockito.mock(org.apache.camel.Message.class);
        Mockito.when(mockExchange.hasOut()).thenReturn(true);
        Mockito.when(mockExchange.getOut()).thenReturn(mockCamelOutMessage);
        Message outboundFixMessage = new Message();
        Mockito.when(mockCamelOutMessage.getBody(Message.class)).thenReturn(outboundFixMessage);
       
        QuickfixjConsumer consumer = Mockito.spy(new QuickfixjConsumer(mockEndpoint, mockProcessor));
        Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
        Mockito.doReturn(mockSession).when(consumer).getSession(MessageUtils.getReverseSessionID(inboundFixMessage));
View Full Code Here

                Symbol.FIELD, SecurityID.FIELD, SecurityIDSource.FIELD, Product.FIELD,
                QuoteType.FIELD, OrderQty.FIELD, SettlDate.FIELD, QuotePriceType.FIELD,
                ValidUntilTime.FIELD, ExpireTime.FIELD
        };

        Message message = new QuoteRequest(new QuoteReqID("20101110-2"));
        Group group = new Group(NoRelatedSym.FIELD, Symbol.FIELD, order);
        group.setField(new Symbol("TestSymbol"));
        group.setField(new SecurityID("SecurityID"));
        group.setField(new SecurityIDSource("SecurityIDSource"));
        group.setField(new Product(11));
        group.setField(new QuoteType(1));
        group.setField(new OrderQty(500));
        group.setField(new SettlDate("20151116"));
        group.setField(new QuotePriceType(1));
        group.setField(new ValidUntilTime(new Date()));
        group.setField(new ExpireTime(new Date()));
        message.addGroup(group);
        System.out.println("Original Message: " + message);

        MessageContext msgCtx = new MessageContext();
        FIXUtils.getInstance().setSOAPEnvelope(message, 1, "TestSession", msgCtx);
        OMElement msgElt = msgCtx.getEnvelope().getBody().getFirstElement();
        OMElement groupsElt = msgElt.getFirstChildWithName(new QName(FIXConstants.FIX_BODY)).
                getFirstChildWithName(new QName(FIXConstants.FIX_GROUPS));

        int groupId = Integer.parseInt(groupsElt.getAttributeValue(
                new QName(FIXConstants.FIX_FIELD_ID)));
        assertEquals(groupId, group.getFieldTag());

        // Test whether the fileds in the SOAP infoset are in the correct order
        Iterator fields = groupsElt.getFirstElement().getChildrenWithName(
                new QName(FIXConstants.FIX_FIELD));
        List<Integer> fieldList = new ArrayList<Integer>();
        while (fields.hasNext()) {
            OMElement fieldElt = (OMElement) fields.next();
            fieldList.add(Integer.parseInt(fieldElt.getAttributeValue(
                    new QName(FIXConstants.FIX_FIELD_ID))));
        }
        assertEquals(order.length, fieldList.size());
        for (int i = 0; i < order.length; i++) {
            assertEquals(order[i], (int) fieldList.get(i));
        }

        // Test whether the reconstructed message preserves the group field order
        Message copy = FIXUtils.getInstance().createFIXMessage(msgCtx);
        System.out.println("Reconstructed Message: " + copy);
        List<Group> groups = copy.getGroups(NoRelatedSym.FIELD);
        assertEquals(1, groups.size());
        int[] copyOrder = groups.get(0).getFieldOrder();
        assertEquals(order.length, copyOrder.length);
        for (int i = 0; i < order.length; i++) {
            assertEquals(order[i], copyOrder[i]);
        }

        assertEquals(message.toString(), copy.toString());       
    }
View Full Code Here

TOP

Related Classes of quickfix.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.