public byte[] packToBytes () throws JDOMException, IOException, ISOException { return pack().getBytes(charset); }
public void testFSDMsgDefaultKey () throws Exception { FSDMsg m0 = new FSDMsg(SCHEMA_DIR_URL + "fsd-"); FSDMsg m1 = new FSDMsg(SCHEMA_DIR_URL + "fsd-"); FSDMsg u0 = new FSDMsg(SCHEMA_DIR_URL + "fsd-"); FSDMsg u1 = new FSDMsg(SCHEMA_DIR_URL + "fsd-"); m0.set("message-id","03"); m0.set("x","X"); m0.set("y","WHYWHY03"); assertEquals ("Default defined - not used - pack", "000X0300WHYWHY03", m0.pack() ); m1.set("message-id","99"); m1.set("x","X"); m1.set("z","DEFAULT"); assertEquals ("Default defined - used - pack", "000X99DEFAULT ", m1.pack() ); u0.unpack(m0.packToBytes()); assertEquals ("Default defined - not used - unpack", "00WHYWHY03", u0.get("y") ); u1.unpack(m1.packToBytes()); assertEquals ("Default defined - used - unpack", "DEFAULT ", u1.get("z") ); }
/** * @return message string * @throws org.jdom2.JDOMException * @throws java.io.IOException * @throws ISOException */ public String pack () throws JDOMException, IOException, ISOException { StringBuilder sb = new StringBuilder (); pack (getSchema (baseSchema), sb); return sb.toString (); } public byte[] packToBytes ()
public void testMixedBlanksLeadingArePreserved() throws Exception { String value = " 123 "; String field = "testafs"; imsg.set(field, value); assertEquals("Mixed blanks", ISOUtil.hex2byte("20203132331C"), imsg .pack().getBytes()); omsg.unpack(imsg.pack().getBytes()); assertEquals(" 123", omsg.get(field)); }
pack (getSchema (getId (schema), keyOff, defaultKey), sb);
public void testPack() throws Exception { imsg.set("length", "11"); imsg.set("rest", "ABCDEFGHIJKLMNOPQRST"); assertEquals("11ABCDEFGHIJKLMNOPQRST", imsg.pack()); }
@Test public void testPackThrowsNullPointerException1() throws Throwable { StringBuilder sb = new StringBuilder(); FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); try { fSDMsg.pack(null, sb); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertEquals("fSDMsg.fields.size()", 0, fSDMsg.fields.size()); assertEquals("sb.toString()", "", sb.toString()); } }
public void testFinalField() throws Exception { String value1 = " 123 "; String field1 = "testafs"; String value2 = "ABC"; String field2 = "finalfield"; imsg.set(field1, value1); imsg.set(field2, value2); assertEquals("20203132331C414243",ISOUtil.hexString(imsg.pack().getBytes())); omsg.unpack(imsg.pack().getBytes()); assertEquals(" 123", omsg.get(field1)); assertEquals(value2, omsg.get(field2)); }
@Test public void testPack() throws Throwable { Element schema = new FSDMsg("testFSDMsgBasePath").toXML(); FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); StringBuilder sb = new StringBuilder(); fSDMsg.pack(schema, sb); assertEquals("fSDMsg.fields.size()", 0, fSDMsg.fields.size()); assertEquals("schema.getName()", "message", schema.getName()); assertEquals("sb.toString()", "", sb.toString()); }
@Test public void testPackThrowsMalformedURLException() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); try { fSDMsg.pack(); fail("Expected MalformedURLException to be thrown"); } catch (MalformedURLException ex) { assertEquals("ex.getClass()", MalformedURLException.class, ex.getClass()); assertEquals("fSDMsg.fields.size()", 0, fSDMsg.fields.size()); assertEquals("fSDMsg.baseSchema", "testFSDMsgBaseSchema", fSDMsg.baseSchema); } }
@Test public void testPackThrowsNullPointerException() throws Throwable { FSDMsg fSDMsg = new FSDMsg(null, "testFSDMsgBaseSchema"); try { fSDMsg.pack(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertEquals("fSDMsg.fields.size()", 0, fSDMsg.fields.size()); assertEquals("fSDMsg.baseSchema", "testFSDMsgBaseSchema", fSDMsg.baseSchema); } }
public void testPackJarSchema() throws Exception { FSDMsg fsdm = new FSDMsg(SCHEMA_JAR_URL + "DSmsg-"); String mac = "12345678123456781234567812345678"; String packedMAC = new String(ISOUtil.hex2byte(mac), ISOUtil.CHARSET); String id = "01"; String packedID = new String(ISOUtil.hex2byte(id),ISOUtil.CHARSET); fsdm.set("id", id); fsdm.set("content", mac); String s = fsdm.pack(); assertEquals(packedID + packedMAC, s); }
public void testLoadMissingJarSchema() throws Exception { FSDMsg fsdm = new FSDMsg(SCHEMA_JAR_URL + "DSmsgX-"); String mac = "12345678123456781234567812345678"; String id = "01"; fsdm.set("id", id); fsdm.set("content", mac); try { fsdm.pack(); fail("FileNotFoundException expected"); } catch (FileNotFoundException ex) {} }
public void testLoadMissingDirSchema() throws Exception { FSDMsg fsdm = new FSDMsg(SCHEMA_DIR_URL + "DSmsgX-"); String mac = "12345678123456781234567812345678"; String id = "01"; fsdm.set("id", id); fsdm.set("content", mac); try { fsdm.pack(); fail("FileNotFoundException expected"); } catch (FileNotFoundException ex) {} }
public void testDummySeparatorNumeric() throws Exception { FSDMsg m = new FSDMsg(SCHEMA_DIR_URL + "msgDS-"); String macData = "12345678"; m.set("length", "8"); m.set("alphavardata", macData); assertEquals("000812345678", m.pack()); macData = "12345678123456781234567812345678"; m.set("length", "32"); m.set("alphavardata", macData); assertEquals("Dummy separator long data", "003212345678123456781234567812345678", m.pack()); m.set("length", ""); m.set("alphavardata", ""); assertEquals("Dummy separator no data", "0000", m.pack()); m.set("length", "40"); // Too long data data will be silently truncated, // not sure I like this behaviour! m.set("alphavardata", "12345678123456781234567812345678XXXXXXXX"); assertEquals("Dummy separator truncated data", "004012345678123456781234567812345678", m.pack()); } public void testClone () throws Exception {
imsg.set("length", "8"); imsg.set("alphavardata", macData); assertEquals("0008AbCdEfGh",imsg.pack()); omsg.unpack(imsg.pack().getBytes()); imsg.set("alphavardata", macData); assertEquals("Dummy separator long data", "0032AbCdEfGhAbCdEfGhAbCdEfGhAbCdEfGh", imsg.pack()); omsg.unpack(imsg.pack().getBytes()); assertEquals("Dummy separator no data", "0000", imsg.pack()); "0040AbCdEfGhAbCdEfGhAbCdEfGhAbCdEfGh", imsg.pack()); omsg.unpack(imsg.pack().getBytes());