public void set (String name, String value) { if (value != null) this.fsd.set (name, value); } private static final long serialVersionUID = 1L;
public void merge (FSDMsg m) { for (Entry<String,String> entry: m.fields.entrySet()) set (entry.getKey(), entry.getValue()); } }
public Object clone(int[] fields) { FSDISOMsg m = (FSDISOMsg) super.clone(); m.fsd = new FSDMsg(fsd.getBasePath(), fsd.getBaseSchema()); for (int field : fields) { String f = Integer.toString(field); m.fsd.set(f, fsd.get(f)); } return m; } public void merge (ISOMsg m) {
public void merge (ISOMsg m) { if (m instanceof FSDISOMsg) { fsd.merge (((FSDISOMsg)m).getFSDMsg()); } else { for (int i=0; i<=m.getMaxField(); i++) { if (m.hasField(i)) fsd.set (Integer.toString(i), m.getString(i)); } } } public void setResponseMTI() {
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) {} }
@Test public void testSet() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); fSDMsg.set("testFSDMsgName", null); assertEquals("fSDMsg.fields.size()", 0, fSDMsg.fields.size()); }
public void testClone () throws Exception { FSDMsg m0 = new FSDMsg(SCHEMA_DIR_URL + "msgDS-"); m0.set ("alphavardata", "ABCDE"); FSDMsg m1 = (FSDMsg) m0.clone(); m1.set ("alphavardata", "12345"); assertEquals ("Original alphavardata", "ABCDE", m0.get ("alphavardata")); assertEquals ("Cloned alphavardata", "12345", m1.get ("alphavardata")); } public void testFSDISOMsgClone () throws Exception {
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)); }
public void testSeparator() throws Exception { String value = "1"; String field = "testafs"; imsg.set(field, value); assertEquals("Separator", "1'FS'", imsg.pack().replace(FS, "'FS'")); omsg.unpack(imsg.pack().getBytes()); assertEquals(value, omsg.get(field)); } }
@Test public void testGet7() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); fSDMsg.set(" is used, but ", "testFSDMsgValue"); String result = fSDMsg.get(" is used, but ", "A", 100, "testFSDMsgDefValue", null); assertEquals("result", "testFSDMsgValue ", result); assertEquals("fSDMsg.fields.size()", 1, fSDMsg.fields.size()); }
@Test public void testGetThrowsRuntimeException1() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); fSDMsg.set("testString", "testFSDMsgValue"); try { fSDMsg.get("testString", "B]Z", 100, "testFSDMsgDefValue", "B]Z"); fail("Expected RuntimeException to be thrown"); } catch (RuntimeException ex) { assertEquals("ex.getMessage()", "Invalid separator 'B]Z'", ex.getMessage()); assertEquals("fSDMsg.fields.size()", 1, fSDMsg.fields.size()); } }
@Test public void testGetThrowsRuntimeException2() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); fSDMsg.set("testString", "testFSDMsgValue"); try { fSDMsg.get("testString", "testFSDMsgType", 100, "testFSDMsgDefValue", "testFSDMsgType"); fail("Expected RuntimeException to be thrown"); } catch (RuntimeException ex) { assertEquals("ex.getMessage()", "Invalid separator 'testFSDMsgType'", ex.getMessage()); assertEquals("fSDMsg.fields.size()", 1, fSDMsg.fields.size()); } }
@Test public void testGet9() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); fSDMsg.set("testString", "testFSDMsgValue"); String result = fSDMsg.get("testString", "Kv", 100, null, null); assertEquals("result", "testFSDMsgValue", result); assertEquals("fSDMsg.fields.size()", 1, fSDMsg.fields.size()); }
@Test public void testPackToNoUnpadBDS() throws Throwable { Element schema = createSchema(); appendField(schema, "name", "B", "DS", 32); FSDMsg fSDMsg = new FSDMsg(SCHEMA_PREFIX); byte[] expected = "Test message ".getBytes(); fSDMsg.set("name", ISOUtil.hexString("Test message ".getBytes())); byte[] b = fSDMsg.packToBytes(); assertArrayEquals("FSDMsg.packToBytes() can't unpadding BDS fields", expected, b); }
public void testFSDISOMsgClone () throws Exception { FSDMsg m0 = new FSDMsg(SCHEMA_DIR_URL + "msgDS-"); m0.set ("alphavardata", "ABCDE"); FSDISOMsg iso0 = new FSDISOMsg (m0); FSDISOMsg iso1 = (FSDISOMsg) iso0.clone(); FSDMsg m1 = iso1.getFSDMsg(); m1.set ("alphavardata", "12345"); assertEquals ("Original alphavardata", "ABCDE", m0.get ("alphavardata")); assertEquals ("Cloned alphavardata", "12345", m1.get ("alphavardata")); } public void testFSDISOMsgPartialCloneAndMerge () throws Exception {
@Test public void testPackToUnpadADS() throws Throwable { Element schema = createSchema(); appendField(schema, "name", "A", "DS", 32); FSDMsg fSDMsg = new FSDMsg(SCHEMA_PREFIX); byte[] expected = "Test message".getBytes(); fSDMsg.set("name", "Test message "); byte[] b = fSDMsg.packToBytes(); assertArrayEquals("FSDMsg.packToBytes() don't properly handle ADS unpadding", expected, b); }
@Test public void testGetHexBytes() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); fSDMsg.set("testString", "testFSDMsgValue1"); byte[] result = fSDMsg.getHexBytes("testString"); assertEquals("result.length", 8, result.length); assertEquals("result[0]", (byte) -2, result[0]); assertEquals("fSDMsg.fields.size()", 1, fSDMsg.fields.size()); }
@Test public void testToXML1() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); fSDMsg.set("testFSDMsgName", "testFSDMsgValue"); Element result = fSDMsg.toXML(); assertEquals("result.getName()", "message", result.getName()); assertEquals("fSDMsg.fields.size()", 1, fSDMsg.fields.size()); }