diff --git a/src/test/java/j8583/TestBinaries.java b/src/test/java/j8583/TestBinaries.java index f24e40e..76a40b7 100644 --- a/src/test/java/j8583/TestBinaries.java +++ b/src/test/java/j8583/TestBinaries.java @@ -4,10 +4,8 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.text.ParseException; -import java.util.Arrays; - -import junit.framework.Assert; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -40,27 +38,25 @@ public class TestBinaries { 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)); + Assert.assertArrayEquals("Field 41 wrong value", 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.assertArrayEquals("Field 42 wrong value", 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)); + 0x62, 1, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xab, (byte)0xcd }; + Assert.assertArrayEquals(exp, buf); buf = (byte[])m.getObjectValue(64); - Assert.assertEquals(16, buf.length); - Assert.assertTrue(Arrays.equals(exp, buf)); + exp[8] = 0x64; + Assert.assertArrayEquals(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)); + exp = new byte[]{ 0, (byte)0x12, (byte)0x34, (byte)0x56, (byte)0x78, (byte)0x63 }; + Assert.assertArrayEquals(exp, buf); buf = (byte[])m.getObjectValue(65); - Assert.assertEquals(6, buf.length); - Assert.assertTrue(Arrays.equals(exp, buf)); + exp[5] = 0x65; + Assert.assertArrayEquals(exp, buf); } @Test @@ -68,12 +64,16 @@ public class TestBinaries { //Create a message with both factories IsoMessage ascii = mfactAscii.newMessage(0x600); IsoMessage bin = mfactBin.newMessage(0x600); + Assert.assertFalse(ascii.isBinary() || ascii.isBinaryBitmap()); + Assert.assertTrue(bin.isBinary()); //HEXencode the binary message, headers should be similar to the ASCII version - String hexBin = HexCodec.hexEncode(bin.writeData()); + final byte[] _v = bin.writeData(); + String hexBin = HexCodec.hexEncode(_v, 0, _v.length); String hexAscii = new String(ascii.writeData()).toUpperCase(); Assert.assertEquals("0600", hexBin.substring(0, 4)); //Should be the same up to the field 42 (first 80 chars) Assert.assertEquals(hexAscii.substring(0, 88), hexBin.substring(0, 88)); + Assert.assertEquals(ascii.getObjectValue(43), new String(_v, 44, 40).trim()); //Parse both messages byte[] asciiBuf = ascii.writeData(); IsoMessage ascii2 = mfactAscii.parseMessage(asciiBuf, 0); @@ -98,7 +98,7 @@ public class TestBinaries { byte[] sub1 = new byte[8]; System.arraycopy(data1, 16, sub1, 0, 8); String sub2 = new String(data2, 16, 16, iso2.getCharacterEncoding()); - Assert.assertEquals(sub2, HexCodec.hexEncode(sub1)); + Assert.assertEquals(sub2, HexCodec.hexEncode(sub1, 0, sub1.length)); } } diff --git a/src/test/java/j8583/TestDates.java b/src/test/java/j8583/TestDates.java index 7d52c18..1660942 100644 --- a/src/test/java/j8583/TestDates.java +++ b/src/test/java/j8583/TestDates.java @@ -6,6 +6,7 @@ import java.text.ParseException; import java.util.Date; import java.util.GregorianCalendar; +import com.solab.iso8583.IsoMessage; import org.junit.*; import com.solab.iso8583.IsoType; @@ -20,11 +21,11 @@ import com.solab.iso8583.parse.Date4ParseInfo; */ public class TestDates { - private MessageFactory mf; + private MessageFactory mf; @Before public void init() throws IOException { - mf = new MessageFactory(); + mf = new MessageFactory(); mf.setCharacterEncoding("UTF-8"); mf.setCustomField(48, new CustomField48()); mf.setConfigPath("config.xml"); @@ -39,12 +40,12 @@ public class TestDates { today.set(GregorianCalendar.SECOND,0); today.set(GregorianCalendar.MILLISECOND,0); byte[] buf = IsoType.DATE4.format(soon).getBytes(); - IsoValue comp = new Date4ParseInfo().parse(buf, 0, null); + IsoValue comp = new Date4ParseInfo().parse(0, buf, 0, null); Assert.assertEquals(comp.getValue(), today.getTime()); //Now with the binary ByteArrayOutputStream bout = new ByteArrayOutputStream(); comp.write(bout, true); - IsoValue bin = new Date4ParseInfo().parseBinary(bout.toByteArray(), 0, null); + IsoValue bin = new Date4ParseInfo().parseBinary(0, bout.toByteArray(), 0, null); Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime()); } @@ -52,12 +53,12 @@ public class TestDates { public void testDate10FutureTolerance() throws ParseException, IOException { Date soon = new Date(System.currentTimeMillis() + 50000); byte[] buf = IsoType.DATE10.format(soon).getBytes(); - IsoValue comp = new Date10ParseInfo().parse(buf, 0, null); + IsoValue comp = new Date10ParseInfo().parse(0, buf, 0, null); assert comp.getValue().after(new Date()); //Now with the binary ByteArrayOutputStream bout = new ByteArrayOutputStream(); comp.write(bout, true); - IsoValue bin = new Date10ParseInfo().parseBinary(bout.toByteArray(), 0, null); + IsoValue bin = new Date10ParseInfo().parseBinary(0, bout.toByteArray(), 0, null); Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime()); } diff --git a/src/test/java/j8583/TestHexCodec.java b/src/test/java/j8583/TestHexCodec.java index 987c28f..33c7b17 100644 --- a/src/test/java/j8583/TestHexCodec.java +++ b/src/test/java/j8583/TestHexCodec.java @@ -12,7 +12,7 @@ public class TestHexCodec { public void encodeDecode(String hex) { byte[] buf = HexCodec.hexDecode(hex); Assert.assertEquals((hex.length() / 2) + (hex.length() % 2), buf.length); - String reenc = HexCodec.hexEncode(buf); + String reenc = HexCodec.hexEncode(buf, 0, buf.length); if (reenc.startsWith("0") && !hex.startsWith("0")) { Assert.assertEquals(reenc.substring(1), hex); } else { @@ -41,4 +41,10 @@ public class TestHexCodec { encodeDecode("ABC"); } + @Test + public void testPartial() { + Assert.assertEquals("FF01", HexCodec.hexEncode(new byte[]{0, (byte)0xff, 1, 2, 3, 4}, + 1, 2)); + } + } diff --git a/src/test/java/j8583/TestIsoMessage.java b/src/test/java/j8583/TestIsoMessage.java index 70c3016..a07ceaa 100644 --- a/src/test/java/j8583/TestIsoMessage.java +++ b/src/test/java/j8583/TestIsoMessage.java @@ -18,11 +18,11 @@ import com.solab.iso8583.MessageFactory; */ public class TestIsoMessage { - private MessageFactory mf; + private MessageFactory mf; @Before public void init() throws IOException { - mf = new MessageFactory(); + mf = new MessageFactory(); mf.setCharacterEncoding("UTF-8"); mf.setCustomField(48, new CustomField48()); mf.setConfigPath("config.xml"); diff --git a/src/test/java/j8583/TestParsing.java b/src/test/java/j8583/TestParsing.java index a3e1574..7251b7a 100644 --- a/src/test/java/j8583/TestParsing.java +++ b/src/test/java/j8583/TestParsing.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.text.ParseException; +import com.solab.iso8583.IsoMessage; import com.solab.iso8583.IsoValue; import com.solab.iso8583.parse.NumericParseInfo; import junit.framework.Assert; @@ -18,11 +19,11 @@ import com.solab.iso8583.MessageFactory; */ public class TestParsing { - private MessageFactory mf; + private MessageFactory mf; @Before public void init() throws IOException { - mf = new MessageFactory(); + mf = new MessageFactory(); mf.setCharacterEncoding("UTF-8"); mf.setCustomField(48, new CustomField48()); mf.setConfigPath("config.xml"); @@ -102,7 +103,7 @@ public class TestParsing { @Test public void testBinaryNumberParsing() throws ParseException { NumericParseInfo npi = new NumericParseInfo(6); - IsoValue val = npi.parseBinary(new byte[]{0x12, 0x34, 0x56}, 0, null); + IsoValue val = npi.parseBinary(0, new byte[]{0x12, 0x34, 0x56}, 0, null); Assert.assertEquals(123456, val.getValue().intValue()); }