binary message parsing has improved drastically. BINARY, LLBIN and LLLBIN types are correctly encoded and parsed in both ASCII and binary formats.

git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@65 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
chochos
2010-12-07 19:24:52 +00:00
parent ad4f51d3cd
commit 3b36a1dfe9
9 changed files with 251 additions and 39 deletions
+44 -4
View File
@@ -1,6 +1,9 @@
package j8583;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Arrays;
import junit.framework.Assert;
@@ -26,20 +29,57 @@ public class TestBinaries {
mfactBin.setUseBinaryMessages(true);
}
void testParsed(IsoMessage m) {
Assert.assertEquals(m.getType(), 0x600);
Assert.assertEquals(new BigDecimal("1234.00"), m.getObjectValue(4));
Assert.assertTrue("No field 7!", m.hasField(7));
Assert.assertEquals("Wrong trace", "000123", m.getField(11).toString());
byte[] buf = (byte[])m.getObjectValue(41);
byte[] exp = new byte[]{ (byte)0xab, (byte)0xcd, (byte)0xef, 0, 0, 0, 0, 0};
Assert.assertEquals("Field 41 wrong length", 8, buf.length);
Assert.assertTrue("Field 41 wrong value", Arrays.equals(exp, buf));
buf = (byte[])m.getObjectValue(42);
exp = new byte[]{ (byte)0x0a, (byte)0xbc, (byte)0xde, 0 };
Assert.assertEquals("field 42 wrong length", 4, buf.length);
Assert.assertTrue("Field 42 wrong value", Arrays.equals(exp, buf));
Assert.assertTrue(((String)m.getObjectValue(43)).startsWith("Field of length 40"));
buf = (byte[])m.getObjectValue(62);
exp = new byte[]{ 1, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xab, (byte)0xcd, (byte)0xef,
1, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xab, (byte)0xcd, (byte)0xef };
Assert.assertEquals(16, buf.length);
Assert.assertTrue(Arrays.equals(exp, buf));
buf = (byte[])m.getObjectValue(64);
Assert.assertEquals(16, buf.length);
Assert.assertTrue(Arrays.equals(exp, buf));
buf = (byte[])m.getObjectValue(63);
exp = new byte[]{ 0, (byte)0x12, (byte)0x34, (byte)0x56, (byte)0x78, (byte)0x9a };
Assert.assertEquals(6, buf.length);
Assert.assertTrue(Arrays.equals(exp, buf));
buf = (byte[])m.getObjectValue(65);
Assert.assertEquals(6, buf.length);
Assert.assertTrue(Arrays.equals(exp, buf));
}
@Test
public void testMessages() {
public void testMessages() throws ParseException {
//Create a message with both factories
IsoMessage ascii = mfactAscii.newMessage(0x600);
IsoMessage bin = mfactBin.newMessage(0x600);
//HEXencode the binary message, headers should be similar to the ASCII version
String hexBin = HexCodec.hexEncode(bin.writeData());
String hexAscii = new String(ascii.writeData());
String hexAscii = new String(ascii.writeData()).toUpperCase();
System.out.printf("bin: %s%nascii: %s%n", hexBin, hexAscii);
Assert.assertEquals("0600", hexBin.substring(0, 4));
//Should be the same up to the trace (first 64 chars)
Assert.assertEquals(hexAscii.substring(0, 64), hexBin.substring(0, 64));
//Should be the same up to the field 42 (first 80 chars)
Assert.assertEquals(hexAscii.substring(0, 88), hexBin.substring(0, 88));
//Parse both messages
IsoMessage ascii2 = mfactAscii.parseMessage(ascii.writeData(), 0);
testParsed(ascii2);
Assert.assertEquals(ascii.getObjectValue(7).toString(), ascii2.getObjectValue(7).toString());
IsoMessage bin2 = mfactBin.parseMessage(bin.writeData(), 0);
//Compare values, should be the same
testParsed(bin2);
Assert.assertEquals(bin.getObjectValue(7).toString(), bin2.getObjectValue(7).toString());
}
}
+4
View File
@@ -35,6 +35,10 @@ public class TestHexCodec {
Assert.assertEquals(0xab, (buf[5] & 0xff));
Assert.assertEquals(0xcd, (buf[6] & 0xff));
Assert.assertEquals(0xef, (buf[7] & 0xff));
buf = HexCodec.hexDecode("ABC");
Assert.assertEquals(0x0a, (buf[0] & 0xff));
Assert.assertEquals(0xbc, (buf[1] & 0xff));
encodeDecode("ABC");
}
}