Example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR

List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Prototype

String LINE_SEPARATOR

To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Click Source Link

Document

The line.separator System Property.

Usage

From source file:org.marketcetera.util.quickfix.AnalyzedMessageTest.java

@Test
public void valid() throws Exception {

    NewOrderSingle msg = new NewOrderSingle();
    // Required header fields.
    msg.getHeader().setField(new SenderCompID("me"));
    msg.getHeader().setField(new TargetCompID("you"));
    msg.getHeader().setField(new MsgSeqNum(1));
    msg.getHeader().setField(new SendingTime(new Date(2)));
    // Required body fields.
    msg.set(new ClOrdID("a"));
    msg.set(new HandlInst(HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE));
    msg.set(new TransactTime(new Date(3)));
    msg.set(new OrdType(OrdType.LIMIT));
    msg.set(new Symbol("METC"));
    // A required enumeration.
    msg.set(new Side(Side.BUY));
    // An optional non-enumeration.
    msg.set(new Account("metc"));
    msg.toString();/*www .  j a va  2s  .  c  om*/
    AnalyzedMessage msgA = new AnalyzedMessage(TEST_DICTIONARY, msg);
    assertNoEvents();
    assertEquals(7, msgA.getHeader().size());
    assertEquals(7, msgA.getBody().size());
    assertEquals(1, msgA.getTrailer().size());
    assertEquals(SystemUtils.LINE_SEPARATOR + "Header" + SystemUtils.LINE_SEPARATOR
            + " BeginString [8R] = FIX.4.2" + SystemUtils.LINE_SEPARATOR + " BodyLength [9R] = 108"
            + SystemUtils.LINE_SEPARATOR + " MsgSeqNum [34R] = 1" + SystemUtils.LINE_SEPARATOR
            + " MsgType [35R] = NewOrderSingle [D]" + SystemUtils.LINE_SEPARATOR + " SenderCompID [49R] = me"
            + SystemUtils.LINE_SEPARATOR + " SendingTime [52R] = 19700101-00:00:00.002"
            + SystemUtils.LINE_SEPARATOR + " TargetCompID [56R] = you" + SystemUtils.LINE_SEPARATOR + "Body"
            + SystemUtils.LINE_SEPARATOR + " Account [1] = metc" + SystemUtils.LINE_SEPARATOR
            + " ClOrdID [11R] = a" + SystemUtils.LINE_SEPARATOR + " HandlInst [21R] = "
            + "AUTOMATED_EXECUTION_ORDER_PRIVATE_NO_BROKER_INTERVENTION [1]" + SystemUtils.LINE_SEPARATOR
            + " OrdType [40R] = LIMIT [2]" + SystemUtils.LINE_SEPARATOR + " Side [54R] = BUY [1]"
            + SystemUtils.LINE_SEPARATOR + " Symbol [55R] = METC" + SystemUtils.LINE_SEPARATOR
            + " TransactTime [60R] = 19700101-00:00:00.003" + TEST_FOOTER + "076", msgA.toString());
}

From source file:org.marketcetera.util.quickfix.AnalyzedMessageTest.java

@Test
public void group() throws Exception {
    MarketDataSnapshotFullRefresh msg = new MarketDataSnapshotFullRefresh(new Symbol("QF"));
    MarketDataSnapshotFullRefresh.NoMDEntries group = new MarketDataSnapshotFullRefresh.NoMDEntries();
    group.set(new MDEntryType(MDEntryType.BID));
    group.set(new MDEntryPx(2));
    group.set(new MDEntrySize(16));
    group.set(new OrderID("ID1"));
    msg.addGroup(group);/*from w ww  .j  a v a  2  s  . co  m*/
    group = new MarketDataSnapshotFullRefresh.NoMDEntries();
    group.set(new MDEntryType('?'));
    group.set(new MDEntryPx(4));
    group.set(new MDEntrySize(32));
    group.set(new OrderID("ID2"));
    msg.addGroup(group);
    msg.toString();
    AnalyzedMessage msgA = new AnalyzedMessage(TEST_DICTIONARY, msg);
    assertNoEvents();
    assertEquals(3, msgA.getHeader().size());
    assertEquals(2, msgA.getBody().size());
    assertEquals(4, msgA.getBody().get(1).getGroups().get(0).getFields().size());
    assertEquals(4, msgA.getBody().get(1).getGroups().get(1).getFields().size());
    assertEquals(1, msgA.getTrailer().size());
    assertEquals(TEST_HEADER + "69" + SystemUtils.LINE_SEPARATOR
            + " MsgType [35R] = MarketDataSnapshotFullRefresh [W]" + SystemUtils.LINE_SEPARATOR + "Body"
            + SystemUtils.LINE_SEPARATOR + " Symbol [55R] = QF" + SystemUtils.LINE_SEPARATOR
            + " NoMDEntries [268R] = 2" + SystemUtils.LINE_SEPARATOR + "  Group 1" + SystemUtils.LINE_SEPARATOR
            + "   MDEntryType [269R] = BID [0]" + SystemUtils.LINE_SEPARATOR + "   OrderID [37] = ID1"
            + SystemUtils.LINE_SEPARATOR + "   MDEntryPx [270R] = 2" + SystemUtils.LINE_SEPARATOR
            + "   MDEntrySize [271] = 16" + SystemUtils.LINE_SEPARATOR + "  Group 2"
            + SystemUtils.LINE_SEPARATOR + "   MDEntryType [269R] = ? [invalid]" + SystemUtils.LINE_SEPARATOR
            + "   OrderID [37] = ID2" + SystemUtils.LINE_SEPARATOR + "   MDEntryPx [270R] = 4"
            + SystemUtils.LINE_SEPARATOR + "   MDEntrySize [271] = 32" + TEST_FOOTER + "219", msgA.toString());
}

From source file:org.marketcetera.util.quickfix.AnalyzedMessageTest.java

@Test
public void nestedGroup() throws Exception {
    MassQuote msg = new MassQuote();
    MassQuote.NoQuoteSets topGroup = new MassQuote.NoQuoteSets();
    topGroup.set(new QuoteSetID("TID1"));
    topGroup.set(new UnderlyingIssuer("UI1"));
    MassQuote.NoQuoteSets.NoQuoteEntries nestedGroup = new MassQuote.NoQuoteSets.NoQuoteEntries();
    nestedGroup.set(new QuoteEntryID("NID1.1"));
    nestedGroup.set(new Issuer("I1.1"));
    topGroup.addGroup(nestedGroup);/*from www .  ja  v  a  2s . c  om*/
    nestedGroup = new MassQuote.NoQuoteSets.NoQuoteEntries();
    nestedGroup.set(new QuoteEntryID("NID1.2"));
    nestedGroup.set(new Issuer("I1.2"));
    topGroup.addGroup(nestedGroup);
    msg.addGroup(topGroup);
    topGroup = new MassQuote.NoQuoteSets();
    topGroup.set(new QuoteSetID("TID2"));
    topGroup.set(new UnderlyingIssuer("UI2"));
    nestedGroup = new MassQuote.NoQuoteSets.NoQuoteEntries();
    nestedGroup.set(new QuoteEntryID("NID2.1"));
    nestedGroup.set(new Issuer("I2.1"));
    topGroup.addGroup(nestedGroup);
    nestedGroup = new MassQuote.NoQuoteSets.NoQuoteEntries();
    nestedGroup.set(new QuoteEntryID("NID2.2"));
    nestedGroup.set(new Issuer("I2.2"));
    topGroup.addGroup(nestedGroup);
    msg.addGroup(topGroup);
    msg.toString();
    AnalyzedMessage msgA = new AnalyzedMessage(TEST_DICTIONARY, msg);
    assertNoEvents();
    assertEquals(3, msgA.getHeader().size());
    assertEquals(1, msgA.getBody().size());
    assertEquals(3, msgA.getBody().get(0).getGroups().get(0).getFields().size());
    assertEquals(2,
            msgA.getBody().get(0).getGroups().get(0).getFields().get(1).getGroups().get(0).getFields().size());
    assertEquals(2,
            msgA.getBody().get(0).getGroups().get(0).getFields().get(1).getGroups().get(1).getFields().size());
    assertEquals(3, msgA.getBody().get(0).getGroups().get(1).getFields().size());
    assertEquals(2,
            msgA.getBody().get(0).getGroups().get(1).getFields().get(1).getGroups().get(0).getFields().size());
    assertEquals(2,
            msgA.getBody().get(0).getGroups().get(1).getFields().get(1).getGroups().get(1).getFields().size());
    assertEquals(1, msgA.getTrailer().size());
    assertEquals(TEST_HEADER + "137" + SystemUtils.LINE_SEPARATOR + " MsgType [35R] = MassQuote [i]"
            + SystemUtils.LINE_SEPARATOR + "Body" + SystemUtils.LINE_SEPARATOR + " NoQuoteSets [296R] = 2"
            + SystemUtils.LINE_SEPARATOR + "  Group 1" + SystemUtils.LINE_SEPARATOR
            + "   QuoteSetID [302R] = TID1" + SystemUtils.LINE_SEPARATOR + "   NoQuoteEntries [295R] = 2"
            + SystemUtils.LINE_SEPARATOR + "    Group 1" + SystemUtils.LINE_SEPARATOR
            + "     QuoteEntryID [299R] = NID1.1" + SystemUtils.LINE_SEPARATOR + "     Issuer [106] = I1.1"
            + SystemUtils.LINE_SEPARATOR + "    Group 2" + SystemUtils.LINE_SEPARATOR
            + "     QuoteEntryID [299R] = NID1.2" + SystemUtils.LINE_SEPARATOR + "     Issuer [106] = I1.2"
            + SystemUtils.LINE_SEPARATOR + "   UnderlyingIssuer [306] = UI1" + SystemUtils.LINE_SEPARATOR
            + "  Group 2" + SystemUtils.LINE_SEPARATOR + "   QuoteSetID [302R] = TID2"
            + SystemUtils.LINE_SEPARATOR + "   NoQuoteEntries [295R] = 2" + SystemUtils.LINE_SEPARATOR
            + "    Group 1" + SystemUtils.LINE_SEPARATOR + "     QuoteEntryID [299R] = NID2.1"
            + SystemUtils.LINE_SEPARATOR + "     Issuer [106] = I2.1" + SystemUtils.LINE_SEPARATOR
            + "    Group 2" + SystemUtils.LINE_SEPARATOR + "     QuoteEntryID [299R] = NID2.2"
            + SystemUtils.LINE_SEPARATOR + "     Issuer [106] = I2.2" + SystemUtils.LINE_SEPARATOR
            + "   UnderlyingIssuer [306] = UI2" + TEST_FOOTER + "125", msgA.toString());
}

From source file:org.marketcetera.util.quickfix.AnalyzedMessageTest.java

@Test
public void badEnum() throws Exception {
    NewOrderSingle msg = new NewOrderSingle();
    msg.set(new Side('?'));
    msg.toString();//  ww  w.  ja  v a  2  s  . c o  m
    AnalyzedMessage msgA = new AnalyzedMessage(TEST_DICTIONARY, msg);
    assertNoEvents();
    assertEquals(3, msgA.getHeader().size());
    assertEquals(1, msgA.getBody().size());
    assertEquals(1, msgA.getTrailer().size());
    assertEquals(TEST_HEADER + "10" + SystemUtils.LINE_SEPARATOR + " MsgType [35R] = NewOrderSingle [D]"
            + SystemUtils.LINE_SEPARATOR + "Body" + SystemUtils.LINE_SEPARATOR + " Side [54R] = ? [invalid]"
            + TEST_FOOTER + "199", msgA.toString());
}

From source file:org.marketcetera.util.quickfix.AnalyzedMessageTest.java

@Test
public void missingGroup() throws Exception {
    MarketDataSnapshotFullRefresh msg = new MarketDataSnapshotFullRefresh(new Symbol("QF"));
    msg.set(new NoMDEntries(1));
    msg.toString();/*  w  ww. ja va 2  s. c o m*/
    AnalyzedMessage msgA = new AnalyzedMessage(TEST_DICTIONARY, msg);
    assertSingleEvent(Level.ERROR, TEST_FIELD_CATEGORY, "Group 1 is missing from message scope '8=FIX.4.2" + SOH
            + "9=11" + SOH + "35=W" + SOH + "55=QF" + SOH + "10=052" + SOH + "'", TEST_FIELD_CATEGORY);
    assertEquals(3, msgA.getHeader().size());
    assertEquals(2, msgA.getBody().size());
    assertEquals(1, msgA.getTrailer().size());
    assertEquals(TEST_HEADER + "17" + SystemUtils.LINE_SEPARATOR
            + " MsgType [35R] = MarketDataSnapshotFullRefresh [W]" + SystemUtils.LINE_SEPARATOR + "Body"
            + SystemUtils.LINE_SEPARATOR + " Symbol [55R] = QF" + SystemUtils.LINE_SEPARATOR
            + " NoMDEntries [268R] = 1" + TEST_FOOTER + "052", msgA.toString());
}

From source file:org.marketcetera.util.test.LogTestAssist.java

/**
 * Returns a string with all the events of the receiver's
 * collector./*from   ww  w.j  av  a  2 s .  c  o  m*/
 *
 * @return The string.
 */

public String getEventsAsString() {
    StringBuilder builder = new StringBuilder();
    builder.append("Event count: "); //$NON-NLS-1$
    builder.append(getAppender().getEvents().size());
    int i = 0;
    for (LoggingEvent event : getAppender().getEvents()) {
        builder.append(SystemUtils.LINE_SEPARATOR);
        builder.append("Event "); //$NON-NLS-1$
        builder.append(i++);
        builder.append(": level: "); //$NON-NLS-1$
        builder.append(event.getLevel());
        builder.append("; logger: "); //$NON-NLS-1$
        builder.append(event.getLoggerName());
        builder.append("; message: "); //$NON-NLS-1$
        builder.append(event.getMessage());
        builder.append("; location: "); //$NON-NLS-1$
        builder.append(event.getLocationInformation().getClassName());
    }
    return builder.toString();
}

From source file:org.marketcetera.util.test.LogTestAssist.java

/**
 * Asserts that the receiver's collector contains the given number
 * of events./* w  w  w .  j av a 2 s .  com*/
 *
 * @param count The number of events.
 */

public void assertEventCount(int count) {
    if (getAppender().getEvents().size() == count) {
        return;
    }
    StringBuilder builder = new StringBuilder();
    builder.append("Incorrect event count; expected "); //$NON-NLS-1$
    builder.append(count);
    builder.append(" actual "); //$NON-NLS-1$
    builder.append(SystemUtils.LINE_SEPARATOR);
    builder.append(getEventsAsString());
    fail(builder.toString());
}

From source file:org.marketcetera.util.test.LogTestAssist.java

/**
 * Asserts that at least one of the receiver's collector's events
 * matches the given expected level, logger name, message, and
 * location. If the collector has no events, the assertion fails.
 *
 * @param level The expected level. Use null to indicate "don't
 * care".//from   ww  w. j ava 2  s .co m
 * @param logger The expected logger name. Use null to indicate
 * "don't care".
 * @param message The expected message. Use null to indicate
 * "don't care".
 * @param location The expected location. Use null to indicate
 * "don't care".
 */

public void assertSomeEvent(Level level, String logger, String message, String location) {
    for (LoggingEvent event : getAppender().getEvents()) {
        if (((level == null) || level.equals(event.getLevel()))
                && ((logger == null) || logger.equals(event.getLoggerName()))
                && ((message == null) || message.equals(event.getMessage()))
                && ((location == null) || location.equals(event.getLocationInformation().getClassName()))) {
            return;
        }
    }
    fail("No matches against given event. Events are:" + //$NON-NLS-1$
            SystemUtils.LINE_SEPARATOR + getEventsAsString());
}

From source file:org.marketcetera.util.test.LogTestAssistTest.java

@Test
public void twoEventsAsString() {
    String c = getNextTestCategory();
    setLevel(c, Level.INFO);/*w  ww  .  j a v a  2s  .c om*/
    Logger.getLogger(c).info(TEST_MESSAGE);
    Logger.getLogger(c).warn(TEST_MESSAGE);
    assertEquals("Event count: 2" + SystemUtils.LINE_SEPARATOR + "Event 0: level: INFO" + "; logger: " + c
            + "; message: " + TEST_MESSAGE + "; location: " + TEST_LOCATION + SystemUtils.LINE_SEPARATOR
            + "Event 1: level: WARN" + "; logger: " + c + "; message: " + TEST_MESSAGE + "; location: "
            + TEST_LOCATION, getEventsAsString());
}

From source file:org.mule.transport.stdio.StdioMessageReceiver.java

@Override
public void poll() {
    String encoding = endpoint.getEncoding();
    try {// w w  w.ja v  a 2s  .  c o  m
        if (sendStream) {
            PushbackInputStream in = new PushbackInputStream(inputStream);

            //Block until we have some data
            int i = in.read();
            //Roll back our read
            in.unread(i);
            MuleMessage message = createMuleMessage(in, encoding);
            routeMessage(message);
        } else {
            byte[] inputBuffer = new byte[bufferSize];
            int len = inputStream.read(inputBuffer);

            if (len == -1) {
                return;
            }

            StringBuffer fullBuffer = new StringBuffer(bufferSize);
            while (len > 0) {
                fullBuffer.append(new String(inputBuffer, 0, len));
                len = 0; // mark as read
                if (inputStream.available() > 0) {
                    len = inputStream.read(inputBuffer);
                }
            }

            // Each line is a separate message
            String[] lines = fullBuffer.toString().split(SystemUtils.LINE_SEPARATOR);
            for (int i = 0; i < lines.length; ++i) {
                MuleMessage message = createMuleMessage(lines[i], encoding);
                routeMessage(message);
            }
        }

        doConnect();
    } catch (Exception e) {
        getConnector().getMuleContext().getExceptionListener().handleException(e);
    }
}