@Override public void dump (PrintStream p, String indent) { String inner = indent + " "; p.println (indent + "<fsdmsg schema='" + basePath + baseSchema + "'>"); if (header != null) { append (p, "header", getHexHeader(), inner); } for (String f :fields.keySet()) append (p, f, fields.get (f), inner); p.println (indent + "</fsdmsg>"); } private void append (PrintStream p, String f, String v, String indent) {
public Element toXML () { Element e = new Element ("message"); if (header != null) { e.addContent ( new Element ("header") .setText (getHexHeader ()) ); } for (String fieldName :fields.keySet()) { Element inner = new Element (fieldName); inner.addContent (ISOUtil.normalize (fields.get (fieldName))); e.addContent (inner); } return e; } protected Element getSchema ()
@Test public void testGetHexHeader1() throws Throwable { String result = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema").getHexHeader(); assertEquals("result", "", result); }
@Test public void testGetHexHeader() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); byte[] h = new byte[1]; fSDMsg.setHeader(h); String result = fSDMsg.getHexHeader(); assertEquals("result", "", result); }
@Test public void testGetHexHeaderThrowsStringIndexOutOfBoundsException() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); byte[] h = new byte[0]; fSDMsg.setHeader(h); try { fSDMsg.getHexHeader(); fail("Expected StringIndexOutOfBoundsException to be thrown"); } catch (StringIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "String index out of range: -2", ex.getMessage()); } }