Message extends FieldMap { @Override public String toString() { header.setField(new BodyLength(bodyLength())); trailer.setField(new CheckSum(checkSum())); final StringBuffer sb = new StringBuffer(); header.calculateString(sb, null, null); calculateString(sb, null, null); trailer.calculateString(sb, null, null); return sb.toString(); } Message(); protected  Message(int[] fieldOrder);  Message(String string);  Message(String string, boolean validate);  Message(String string, DataDictionary dd);  Message(String string, DataDictionary dd, boolean validate); static boolean InitializeXML(String url); @Override Object clone(); @Override String toString(); int bodyLength(); void headerAddGroup(Group group); void headerReplaceGroup(int num, Group group); Group headerGetGroup(int num, Group group); void headerRemoveGroup(Group group); boolean headerHasGroup(int field); boolean headerHasGroup(int num, int field); boolean headerHasGroup(int num, Group group); boolean headerHasGroup(Group group); void trailerAddGroup(Group group); Group trailerGetGroup(int num, Group group); void trailerReplaceGroup(int num, Group group); void trailerRemoveGroup(Group group); boolean trailerHasGroup(int field); boolean trailerHasGroup(int num, int field); boolean trailerHasGroup(int num, Group group); boolean trailerHasGroup(Group group); String toXML(); String toXML(DataDictionary dataDictionary); final Header getHeader(); final Trailer getTrailer(); boolean isAdmin(); boolean isApp(); @Override boolean isEmpty(); @Override void clear(); void reverseRoute(Header header); void fromString(String messageData, DataDictionary dd, boolean doValidation); void fromString(String messageData, DataDictionary sessionDictionary,
            DataDictionary applicationDictionary, boolean doValidation); void pushBack(StringField field); synchronized FieldException getException(); static MsgType identifyType(String message);  }
@Test public void testEmbeddedMessage() throws Exception { final NewOrderSingle order = createNewOrderSingle(); final ExecutionReport report = new ExecutionReport(new OrderID("ORDER"), new ExecID("EXEC"), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.FILLED), new Side(Side.BUY), new LeavesQty(100), new CumQty(100), new AvgPx(50)); report.set(new EncodedTextLen(order.toString().length())); report.set(new EncodedText(order.toString())); final Message msg = new Message(report.toString(), DataDictionaryTest.getDictionary()); assertEquals("embedded order", order.toString(), msg.getString(EncodedText.FIELD)); }
@Test public void testInvalidFirstFieldInGroup() throws Exception { final News news = new News(); news.set(new Headline("Test")); final News.NoRelatedSym relatedSym = new News.NoRelatedSym(); relatedSym.set(new SecurityID("SECID")); relatedSym.set(new SecurityIDSource("SECID_SOURCE")); news.addGroup(relatedSym); try { new Message(news.toString(), DataDictionaryTest.getDictionary()); } catch (final InvalidMessage e) { } catch (final NullPointerException e) { fail("Should not throw NPE when first field is missing."); } }
@Test public void testMessageFromString() { Message message = null; boolean badMessage = false; try { message = new Message("8=FIX.4.2\0019=12\00135=A\001108=30\00110=036\001"); } catch (final InvalidMessage e) { badMessage = true; } assertTrue("Message should be invalid", badMessage); try { message = new Message("8=FIX.4.2\0019=12\00135=A\001108=30\00110=026\001"); } catch (final InvalidMessage e) { assertTrue("Message should be valid (" + e.getMessage() + ")", false); } assertEquals("8=FIX.4.2\0019=12\00135=A\001108=30\00110=026\001", message.toString()); }
@Test public void testEmptyMessageToString() throws Exception { final Message msg = new quickfix.Message(); assertNotNull(msg.toString()); assertTrue("empty message contains no checksum", msg.toString().length() > 0); }