moved tests to proper packages

This commit is contained in:
Enrique Zamudio
2014-03-05 16:54:32 -06:00
parent 9c16e3c063
commit bb1b23b282
13 changed files with 13 additions and 51 deletions
@@ -0,0 +1,77 @@
package com.solab.iso8583;
/** This is an example of a custom field codec, which converts between strings and instances of this same class.
* It's used to test the encoding and decoding of custom fields by the message factory.
*
* @author Enrique Zamudio
*/
public class CustomField48 implements CustomField<CustomField48> {
private String v1;
private int v2;
public void setValue1(String value) {
v1 = value;
}
public String getValue1() {
return v1;
}
public void setValue2(int value) {
v2 = value;
}
public int getValue2() {
return v2;
}
@Override
public CustomField48 decodeField(String value) {
CustomField48 cf = null;
if (value != null) {
if (value.length() == 1 && value.charAt(0) == '|') {
cf = new CustomField48();
} else {
int idx = value.lastIndexOf('|');
if (idx < 0 || idx == value.length() - 1) {
throw new IllegalArgumentException(String.format("Invalid data '%s' for field 48", value));
}
cf = new CustomField48();
cf.setValue1(value.substring(0, idx));
cf.setValue2(Integer.parseInt(value.substring(idx + 1)));
}
}
return cf;
}
@Override
public String encodeField(CustomField48 value) {
StringBuilder sb = new StringBuilder();
if (value.getValue1() != null) {
sb.append(value.getValue1());
}
sb.append('|');
sb.append(value.getValue2());
return sb.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof CustomField48)) {
return false;
}
CustomField48 other = (CustomField48)obj;
if (other.getValue2() == v2) {
if (other.getValue1() == null) {
return v1 == null;
} else {
return other.getValue1().equals(v1);
}
}
return false;
}
@Override
public int hashCode() {
return (v1 == null ? 0 : v1.hashCode()) | v2;
}
}
@@ -0,0 +1,107 @@
package com.solab.iso8583;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.ParseException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.solab.iso8583.util.HexCodec;
/** Test binary message encoding and binary fields. */
public class TestBinaries {
private MessageFactory<IsoMessage> mfactAscii = new MessageFactory<IsoMessage>();
private MessageFactory<IsoMessage> mfactBin = new MessageFactory<IsoMessage>();
@Before
public void setup() throws IOException {
mfactAscii.setCharacterEncoding("UTF-8");
mfactAscii.setConfigPath("config.xml");
mfactAscii.setAssignDate(true);
mfactBin.setCharacterEncoding("UTF-8");
mfactBin.setConfigPath("config.xml");
mfactBin.setAssignDate(true);
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 = 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.assertArrayEquals("Field 41 wrong value", exp, buf);
buf = m.getObjectValue(42);
exp = new byte[]{ (byte)0x0a, (byte)0xbc, (byte)0xde, 0 };
Assert.assertEquals("field 42 wrong length", 4, buf.length);
Assert.assertArrayEquals("Field 42 wrong value", exp, buf);
Assert.assertTrue(((String)m.getObjectValue(43)).startsWith("Field of length 40"));
buf = m.getObjectValue(62);
exp = new byte[]{ 1, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xab, (byte)0xcd, (byte)0xef,
0x62, 1, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xab, (byte)0xcd };
Assert.assertArrayEquals(exp, buf);
buf = m.getObjectValue(64);
exp[8] = 0x64;
Assert.assertArrayEquals(exp, buf);
buf = m.getObjectValue(63);
exp = new byte[]{ 0, (byte)0x12, (byte)0x34, (byte)0x56, (byte)0x78, (byte)0x63 };
Assert.assertArrayEquals(exp, buf);
buf = m.getObjectValue(65);
exp[5] = 0x65;
Assert.assertArrayEquals(exp, buf);
}
@Test
public void testMessages() throws ParseException, UnsupportedEncodingException {
//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
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);
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());
//Test the debug string
ascii.setValue(60, "XXX", IsoType.LLVAR, 0);
bin.setValue(60, "XXX", IsoType.LLVAR, 0);
Assert.assertEquals("Debug strings differ", ascii.debugString(), bin.debugString());
Assert.assertTrue("LLVAR fields wrong", ascii.debugString().contains("03XXX"));
}
@Test
public void testBinaryBitmap() throws UnsupportedEncodingException {
IsoMessage iso1 = mfactAscii.newMessage(0x200);
IsoMessage iso2 = mfactAscii.newMessage(0x200);
iso1.setBinaryBitmap(true);
byte[] data1 = iso1.writeData();
byte[] data2 = iso2.writeData();
//First message should be shorter by exactly 16 bytes
Assert.assertEquals(data2.length-16, data1.length);
//compare hex-encoded bitmap from one against the other
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, 0, sub1.length));
}
}
@@ -0,0 +1,61 @@
package com.solab.iso8583;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.text.ParseException;
/**
* Test certain ConfigParser features.
*
* @author Enrique Zamudio
* Date: 25/11/13 18:41
*/
public class TestConfigParser {
@Test
public void testParser() throws IOException, ParseException {
MessageFactory<IsoMessage> mfact = new MessageFactory<IsoMessage>();
mfact.setConfigPath("config.xml");
//Headers
Assert.assertNotNull(mfact.getIsoHeader(0x800));
Assert.assertNotNull(mfact.getIsoHeader(0x810));
Assert.assertEquals(mfact.getIsoHeader(0x800), mfact.getIsoHeader(0x810));
//Templates
final IsoMessage m200 = mfact.getMessageTemplate(0x200);
Assert.assertNotNull(m200);
final IsoMessage m400 = mfact.getMessageTemplate(0x400);
Assert.assertNotNull(m400);
for (int i=2; i <89; i++) {
IsoValue<?> v = m200.getField(i);
if (v == null) {
Assert.assertFalse(m400.hasField(i));
} else {
Assert.assertTrue(m400.hasField(i));
Assert.assertEquals(v, m400.getField(i));
}
}
Assert.assertFalse(m200.hasField(90));
Assert.assertTrue(m400.hasField(90));
Assert.assertTrue(m200.hasField(102));
Assert.assertFalse(m400.hasField(102));
//Parsing guides
final String s800 = "0800201080000000000012345611251125";
final String s810 = "08102010000002000000123456112500";
IsoMessage m = mfact.parseMessage(s800.getBytes(), 0);
Assert.assertNotNull(m);
Assert.assertTrue(m.hasField(3));
Assert.assertTrue(m.hasField(12));
Assert.assertTrue(m.hasField(17));
Assert.assertFalse(m.hasField(39));
m = mfact.parseMessage(s810.getBytes(), 0);
Assert.assertNotNull(m);
Assert.assertTrue(m.hasField(3));
Assert.assertTrue(m.hasField(12));
Assert.assertFalse(m.hasField(17));
Assert.assertTrue(m.hasField(39));
}
}
@@ -0,0 +1,179 @@
package com.solab.iso8583;
import com.solab.iso8583.parse.*;
import com.solab.iso8583.util.HexCodec;
import org.junit.Assert;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
/**
* Test for EBCDIC support.
*
* @author Enrique Zamudio
* Date: 13/05/13 18:12
*/
public class TestEbcdic {
private IsoValue<String> llvar = new IsoValue<String>(IsoType.LLVAR, "Testing, testing, 123");
@Test
public void testAscii() throws IOException, ParseException {
llvar.setCharacterEncoding("UTF-8");
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
llvar.write(bout, false, false);
byte[] buf = bout.toByteArray();
Assert.assertEquals(50, buf[0]);
Assert.assertEquals(49, buf[1]);
final LlvarParseInfo parser = new LlvarParseInfo();
parser.setCharacterEncoding("UTF-8");
IsoValue<?> field = parser.parse(1, buf, 0, null);
Assert.assertEquals(llvar.getValue(), field.getValue());
}
@Test
public void testEbcdic() throws IOException, ParseException {
llvar.setCharacterEncoding("Cp1047");
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
llvar.write(bout, false, true);
byte[] buf = bout.toByteArray();
Assert.assertEquals((byte)242, buf[0]);
Assert.assertEquals((byte) 241, buf[1]);
final LlvarParseInfo parser = new LlvarParseInfo();
parser.setCharacterEncoding("Cp1047");
parser.setForceStringDecoding(true);
IsoValue<?> field = parser.parse(1, buf, 0, null);
Assert.assertEquals(llvar.getValue(), field.getValue());
}
@Test
public void testParsers() throws UnsupportedEncodingException, ParseException {
final byte[] stringA = "A".getBytes("Cp1047");
final LllvarParseInfo lllvar = new LllvarParseInfo();
lllvar.setCharacterEncoding("Cp1047");
lllvar.setForceStringDecoding(true);
IsoValue<?> field = lllvar.parse(1, new byte[]{(byte)240, (byte)240, (byte)241, (byte)193}, 0, null);
Assert.assertEquals(new String(stringA, "Cp1047"), field.getValue());
final LllbinParseInfo lllbin = new LllbinParseInfo();
lllbin.setCharacterEncoding("Cp1047");
lllbin.setForceStringDecoding(true);
field = lllbin.parse(1, new byte[]{(byte)240, (byte)240, (byte)242, 67, 49}, 0, null);
Assert.assertArrayEquals(stringA, (byte[]) field.getValue());
final LlbinParseInfo llbin = new LlbinParseInfo();
llbin.setCharacterEncoding("Cp1047");
llbin.setForceStringDecoding(true);
field = llbin.parse(1, new byte[]{(byte)240, (byte)242, 67, 49}, 0, null);
Assert.assertArrayEquals(stringA, (byte[]) field.getValue());
}
@Test
public void testMessageType() throws UnsupportedEncodingException, ParseException {
final IsoMessage msg = new IsoMessage();
msg.setType(0x1100);
msg.setBinaryBitmap(true);
msg.setCharacterEncoding("Cp1047");
final byte[] enc = msg.writeData();
Assert.assertEquals(12, enc.length);
Assert.assertEquals((byte) 241, enc[0]);
Assert.assertEquals((byte) 241, enc[1]);
Assert.assertEquals((byte)240, enc[2]);
Assert.assertEquals((byte) 240, enc[3]);
MessageFactory<IsoMessage> mf = new MessageFactory<IsoMessage>();
HashMap<Integer, FieldParseInfo> pmap = new HashMap<Integer, FieldParseInfo>();
mf.setForceStringEncoding(true);
mf.setUseBinaryBitmap(true);
mf.setCharacterEncoding("Cp1047");
mf.setParseMap(0x1100, pmap);
IsoMessage m2 = mf.parseMessage(enc, 0);
Assert.assertEquals(msg.getType(), m2.getType());
//Now with text bitmap
msg.setBinaryBitmap(false);
msg.setForceStringEncoding(true);
final byte[] enc2 = msg.writeData();
Assert.assertEquals(20, enc2.length);
mf.setUseBinaryBitmap(false);
m2 = mf.parseMessage(enc2, 0);
Assert.assertEquals(msg.getType(), m2.getType());
}
@Test
public void testDate4() throws UnsupportedEncodingException, ParseException {
final Date4ParseInfo parser = new Date4ParseInfo();
parser.setCharacterEncoding("Cp1047");
parser.setForceStringDecoding(true);
final IsoValue<Date> v = parser.parse(1, new byte[]{(byte)240, (byte)241, (byte)242, (byte)245}, 0, null);
Assert.assertEquals("01", String.format("%Tm", v.getValue()));
Assert.assertEquals("25", String.format("%Td", v.getValue()));
}
@Test
public void testDate10() throws UnsupportedEncodingException, ParseException {
final Date10ParseInfo parser = new Date10ParseInfo();
parser.setCharacterEncoding("Cp1047");
parser.setForceStringDecoding(true);
final IsoValue<Date> v = parser.parse(1, new byte[]{(byte)240, (byte)241, (byte)242, (byte)245, (byte)242, (byte)243, (byte)245, (byte)249, (byte)245, (byte)249}, 0, null);
Assert.assertEquals("01", String.format("%Tm", v.getValue()));
Assert.assertEquals("25", String.format("%Td", v.getValue()));
Assert.assertEquals("23:59:59", String.format("%TT", v.getValue()));
}
@Test
public void testDateExp() throws UnsupportedEncodingException, ParseException {
final DateExpParseInfo parser = new DateExpParseInfo();
parser.setCharacterEncoding("Cp1047");
parser.setForceStringDecoding(true);
final IsoValue<Date> v = parser.parse(1, new byte[]{(byte)241, (byte)247, (byte)241, (byte)242}, 0, null);
Assert.assertEquals("12", String.format("%Tm", v.getValue()));
Assert.assertEquals("2017", String.format("%TY", v.getValue()));
}
@Test
public void testTime() throws UnsupportedEncodingException, ParseException {
final TimeParseInfo parser = new TimeParseInfo();
parser.setCharacterEncoding("Cp1047");
parser.setForceStringDecoding(true);
final IsoValue<Date> v = parser.parse(1, new byte[]{(byte)242, (byte)241, (byte)243, (byte)244, (byte)245, (byte)246}, 0, null);
Assert.assertEquals("21:34:56", String.format("%TT", v.getValue()));
}
@Test
public void testAmount() throws UnsupportedEncodingException, ParseException {
final AmountParseInfo parser = new AmountParseInfo();
parser.setCharacterEncoding("Cp1047");
parser.setForceStringDecoding(true);
IsoValue<BigDecimal> v = parser.parse(4, new byte[]{(byte)240, (byte)240, (byte)240, (byte)241, (byte)242, (byte)243, (byte)244, (byte)245, (byte)246, (byte)247, (byte)248, (byte)249}, 0, null);
Assert.assertEquals(new BigDecimal("1234567.89"), v.getValue());
}
@Test
public void testMessage() throws ParseException, UnsupportedEncodingException {
final byte[] trama = HexCodec.hexDecode("f1f8f1f42030010002000000f0f0f0f0f0f0f0f1f5f9f5f5f1f3f0f6f1f2f1f1f2f9f0f8f8f3f1f8f0f0");
MessageFactory<IsoMessage> mfact = new MessageFactory<IsoMessage>();
mfact.setUseBinaryBitmap(true);
HashMap<Integer, FieldParseInfo> pinfo = new HashMap<Integer, FieldParseInfo>();
pinfo.put(3, new AlphaParseInfo(6));
pinfo.put(11, new AlphaParseInfo(6));
pinfo.put(12, new AlphaParseInfo(12));
pinfo.put(24, new AlphaParseInfo(3));
pinfo.put(39, new AlphaParseInfo(3));
mfact.setParseMap(0x1814, pinfo);
mfact.setCharacterEncoding("Cp1047");
mfact.setForceStringEncoding(true);
IsoMessage iso = mfact.parseMessage(trama, 0);
Assert.assertNotNull(iso);
Assert.assertEquals("000000", iso.getObjectValue(3));
Assert.assertEquals("015955", iso.getObjectValue(11));
Assert.assertEquals("130612112908", iso.getObjectValue(12));
Assert.assertEquals("831", iso.getObjectValue(24));
Assert.assertEquals("800", iso.getObjectValue(39));
}
}
@@ -0,0 +1,56 @@
package com.solab.iso8583;
import java.math.BigDecimal;
import java.util.Date;
import java.util.TimeZone;
import org.junit.Assert;
import org.junit.Test;
/** Tests formatting of certain IsoTypes.
*
* @author Enrique Zamudio
*/
public class TestFormats {
private final Date date = new Date(96867296000l);
@Test
public void testDateFormats() {
assert IsoType.DATE10.format(date, null).equals("0125213456");
assert IsoType.DATE4.format(date, null).equals("0125");
assert IsoType.DATE_EXP.format(date, null).equals("7301");
assert IsoType.TIME.format(date, null).equals("213456");
//Now with GMT
TimeZone gmt = TimeZone.getTimeZone("GMT");
Assert.assertEquals("0126033456", IsoType.DATE10.format(date, gmt));
Assert.assertEquals("0126", IsoType.DATE4.format(date, gmt));
Assert.assertEquals("7301", IsoType.DATE_EXP.format(date, gmt));
Assert.assertEquals("033456", IsoType.TIME.format(date, gmt));
//And now with GMT+1
gmt = TimeZone.getTimeZone("GMT+0100");
Assert.assertEquals("0126043456", IsoType.DATE10.format(date, gmt));
Assert.assertEquals("0126", IsoType.DATE4.format(date, gmt));
Assert.assertEquals("7301", IsoType.DATE_EXP.format(date, gmt));
Assert.assertEquals("043456", IsoType.TIME.format(date, gmt));
}
@Test
public void testNumericFormats() {
assert IsoType.NUMERIC.format(123, 6).equals("000123");
assert IsoType.NUMERIC.format("hola", 6).equals("00hola");
assert IsoType.AMOUNT.format(12345, 0).equals("000001234500");
assert IsoType.AMOUNT.format(new BigDecimal("12345.67"), 0).equals("000001234567");
assert IsoType.AMOUNT.format("1234.56", 0).equals("000000123456");
}
@Test
public void testStringFormats() {
assert IsoType.ALPHA.format("hola", 3).equals("hol");
assert IsoType.ALPHA.format("hola", 4).equals("hola");
assert IsoType.ALPHA.format("hola", 6).equals("hola ");
assert IsoType.LLVAR.format("hola", 0).equals("hola");
assert IsoType.LLLVAR.format("hola", 0).equals("hola");
}
}
@@ -0,0 +1,127 @@
package com.solab.iso8583;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/** These are very simple tests for creating and manipulating messages.
*
* @author Enrique Zamudio
*/
public class TestIsoMessage {
private MessageFactory<IsoMessage> mf;
@Before
public void init() throws IOException {
mf = new MessageFactory<IsoMessage>();
mf.setCharacterEncoding("UTF-8");
mf.setCustomField(48, new CustomField48());
mf.setConfigPath("config.xml");
}
/** Creates a new message and checks that it has all the fields included in the config. */
@Test
public void testCreation() {
IsoMessage iso = mf.newMessage(0x200);
assert iso.getType() == 0x200;
assert iso.getField(3).getType() == IsoType.NUMERIC && "650000".equals(iso.getObjectValue(3));
assert iso.getField(32).getType() == IsoType.LLVAR;
assert iso.getField(35).getType() == IsoType.LLVAR;
assert iso.getField(43).getType() == IsoType.ALPHA && ((String)iso.getObjectValue(43)).length() == 40;
assert iso.getField(48).getType() == IsoType.LLLVAR && iso.getObjectValue(48) instanceof CustomField48;
assert iso.getField(49).getType() == IsoType.ALPHA;
assert iso.getField(60).getType() == IsoType.LLLVAR;
assert iso.getField(61).getType() == IsoType.LLLVAR;
assert iso.getField(100).getType() == IsoType.LLVAR;
assert iso.getField(102).getType() == IsoType.LLVAR;
for (int i = 4; i < 32; i++) {
assert !iso.hasField(i);
}
for (int i = 36; i < 43; i++) {
assert !iso.hasField(i);
}
for (int i = 50; i < 60; i++) {
assert !iso.hasField(i);
}
for (int i = 62; i < 100; i++) {
assert !iso.hasField(i);
}
for (int i = 103; i < 128; i++) {
assert !iso.hasField(i);
}
}
@Test
public void testEncoding() throws Exception {
IsoMessage m1 = mf.newMessage(0x200);
byte[] buf = m1.writeData();
IsoMessage m2 = mf.parseMessage(buf, mf.getIsoHeader(0x200).length());
assert m2.getType() == m1.getType();
for (int i = 2; i < 128; i++) {
//Either both have the field or neither have it
if (m1.hasField(i) && m2.hasField(i)) {
Assert.assertEquals(m1.getField(i).getType(), m2.getField(i).getType());
Assert.assertEquals(m1.getObjectValue(i), m2.getObjectValue(i));
} else {
assert !m1.hasField(i) && !m2.hasField(i);
}
}
}
/** Parses a message from a file and checks the fields. */
@Test
public void testParsing() throws IOException, ParseException {
InputStream ins = getClass().getResourceAsStream("/parse1.txt");
byte[] buf = new byte[400];
int pos = 0;
while (ins.available() > 0) {
buf[pos++] = (byte)ins.read();
}
ins.close();
IsoMessage iso = mf.parseMessage(buf, mf.getIsoHeader(0x210).length());
Assert.assertEquals(0x210, iso.getType());
byte[] b2 = iso.writeData();
//Remove leftover newline and stuff from the original buffer
byte[] b3 = new byte[b2.length];
System.arraycopy(buf, 0, b3, 0, b3.length);
Assert.assertArrayEquals(b3, b2);
}
@Test
public void testTemplating() {
IsoMessage iso1 = mf.newMessage(0x200);
IsoMessage iso2 = mf.newMessage(0x200);
assert iso1 != iso2;
assert iso1.getObjectValue(3).equals(iso2.getObjectValue(3));
assert iso1.getField(3) != iso2.getField(3);
assert iso1.getField(48) != iso2.getField(48);
CustomField48 cf48_1 = iso1.getObjectValue(48);
int origv = cf48_1.getValue2();
cf48_1.setValue2(origv + 1000);
CustomField48 cf48_2 = iso2.getObjectValue(48);
assert cf48_1 == cf48_2;
assert cf48_2.getValue2() == origv + 1000;
}
@Test(expected = IllegalArgumentException.class)
public void testSimpleFieldSetter() {
IsoMessage iso = mf.newMessage(0x200);
IsoValue<String> f3 = iso.getField(3);
iso.updateValue(3, "999999");
assert iso.getObjectValue(3).equals("999999");
IsoValue<String> nf3 = iso.getField(3);
assert f3 != nf3;
assert f3.getType() == nf3.getType();
assert f3.getLength() == nf3.getLength();
assert f3.getEncoder() == nf3.getEncoder();
iso.updateValue(4, "INVALID!");
throw new RuntimeException("Update failed!");
}
}
@@ -0,0 +1,63 @@
package com.solab.iso8583;
import com.solab.iso8583.parse.ConfigParser;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.ParseException;
/**
* Tests for chochos/j8583#4.
*
* @author Enrique Zamudio
* Date: 18/01/13 10:13
*/
public class TestIssue4 {
@Test
public void testTextBitmap() throws IOException, ParseException {
MessageFactory<IsoMessage> tmf = new MessageFactory<IsoMessage>();
ConfigParser.configureFromClasspathConfig(tmf, "issue4.xml");
IsoMessage tm = tmf.newMessage(0x800);
final ByteBuffer bb = tm.writeToBuffer(2);
Assert.assertEquals("Wrong message length for new TXT",
70, bb.array().length);
Assert.assertEquals(68, bb.getShort());
MessageFactory<IsoMessage> tmfp = new MessageFactory<IsoMessage>();
ConfigParser.configureFromClasspathConfig(tmfp, "issue4.xml");
byte[] buf2 = new byte[bb.remaining()];
bb.get(buf2);
tm = tmfp.parseMessage(buf2, 0);
final ByteBuffer bbp = tm.writeToBuffer(2);
Assert.assertArrayEquals("Parsed-reencoded TXT differs from original",
bb.array(), bbp.array());
}
@Test
public void testBinaryBitmap() throws IOException, ParseException {
MessageFactory<IsoMessage> mf = new MessageFactory<IsoMessage>();
ConfigParser.configureFromClasspathConfig(mf, "issue4.xml");
IsoMessage bm = mf.getMessageTemplate(0x800);
bm.setBinaryBitmap(true);
final ByteBuffer bb = bm.writeToBuffer(2);
Assert.assertEquals("Wrong message length for new BIN", 62, bb.array().length);
Assert.assertEquals(60, bb.getShort());
MessageFactory<IsoMessage> mfp = new MessageFactory<IsoMessage>();
mfp.setUseBinaryBitmap(true);
ConfigParser.configureFromClasspathConfig(mfp, "issue4.xml");
byte[] buf2 = new byte[bb.remaining()];
bb.get(buf2);
bm = mfp.parseMessage(buf2, 0);
Assert.assertTrue("Parsed message should have binary bitmap flag set",
bm.isBinaryBitmap());
Assert.assertFalse(bm.isBinary());
final ByteBuffer bbp = bm.writeToBuffer(2);
Assert.assertArrayEquals("Parsed-reencoded BIN differs from original",
bb.array(), bbp.array());
}
}
@@ -0,0 +1,151 @@
package com.solab.iso8583;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import com.solab.iso8583.codecs.CompositeField;
import com.solab.iso8583.parse.NumericParseInfo;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/** Test that parsing invalid messages is properly handled.
*
* @author Enrique Zamudio
*/
public class TestParsing {
private MessageFactory<IsoMessage> mf;
@Before
public void init() throws IOException {
mf = new MessageFactory<IsoMessage>();
mf.setCharacterEncoding("UTF-8");
mf.setCustomField(48, new CustomField48());
mf.setConfigPath("config.xml");
}
@Test(expected=ParseException.class)
public void testEmpty() throws ParseException, UnsupportedEncodingException {
mf.parseMessage(new byte[0], 0);
}
@Test(expected=ParseException.class)
public void testShort() throws ParseException, UnsupportedEncodingException {
mf.parseMessage(new byte[20], 8);
}
@Test(expected=ParseException.class)
public void testShortBin() throws ParseException, UnsupportedEncodingException {
mf.setUseBinaryMessages(true);
mf.parseMessage(new byte[10], 1);
}
@Test(expected=ParseException.class)
public void testShortSecondaryBitmap() throws ParseException, UnsupportedEncodingException {
mf.parseMessage("02008000000000000000".getBytes(), 0);
}
@Test(expected=ParseException.class)
public void testShortSecondaryBitmapBin() throws ParseException, UnsupportedEncodingException {
mf.setUseBinaryMessages(true);
mf.parseMessage(new byte[]{ 2, 0, (byte)128, 0, 0, 0, 0, 0, 0, 0 }, 0);
}
@Test(expected=ParseException.class)
public void testNoFields() throws ParseException, UnsupportedEncodingException {
mf.parseMessage("0210B23A80012EA080180000000014000004".getBytes(), 0);
}
@Test(expected=ParseException.class)
public void testNoFieldsBin() throws ParseException, UnsupportedEncodingException {
mf.setUseBinaryMessages(true);
mf.parseMessage(new byte[]{2, 0x10, (byte)0xB2, 0x3A, (byte)0x80, 1, 0x2E, (byte)0xA0, (byte)0x80, 0x18, 0, 0, 0, 0, 0x14, 0, 0, 4}, 0);
}
@Test(expected=ParseException.class)
public void testIncompleteFixedField() throws ParseException, UnsupportedEncodingException {
mf.parseMessage("0210B23A80012EA08018000000001400000465000".getBytes(), 0);
}
@Test(expected=ParseException.class)
public void testIncompleteFixedFieldBin() throws ParseException, UnsupportedEncodingException {
mf.setUseBinaryMessages(true);
mf.parseMessage(new byte[]{2, 0x10, (byte)0xB2, 0x3A, (byte)0x80, 1, 0x2E, (byte)0xA0, (byte)0x80, 0x18, 0, 0, 0, 0, 0x14, 0, 0, 4, 0x65, 0}, 0);
}
@Test(expected=ParseException.class)
public void testIncompleteVarFieldHeader() throws ParseException, UnsupportedEncodingException {
mf.parseMessage("0210B23A80012EA08018000000001400000465000000000000300004281305474687711259460428042808115".getBytes(), 0);
}
@Test(expected=ParseException.class)
public void testIncompleteVarFieldHeaderBin() throws ParseException, UnsupportedEncodingException {
mf.setUseBinaryMessages(true);
mf.parseMessage(new byte[]{2, 0x10, (byte)0xB2, 0x3A, (byte)0x80, 1, 0x2E, (byte)0xA0, (byte)0x80, 0x18, 0, 0, 0, 0, 0x14, 0, 0, 4, 0x65, 0, 0, 0, 0, 0, 0, 0x30, 0, 0x04, 0x28, 0x13, 0x05, 0x47, 0x46, (byte)0x87, 0x71, 0x12, 0x59, 0x46, 0x04, 0x28, 0x04, 0x28, 0x08, 0x11}, 0);
}
@Test(expected=ParseException.class)
public void testIncompleteVarFieldData() throws ParseException, UnsupportedEncodingException {
mf.parseMessage("0210B23A80012EA0801800000000140000046500000000000030000428130547468771125946042804280811051234".getBytes(), 0);
}
@Test(expected=ParseException.class)
public void testIncompleteVarFieldDataBin() throws ParseException, UnsupportedEncodingException {
mf.setUseBinaryMessages(true);
mf.parseMessage(new byte[]{2, 0x10, (byte)0xB2, 0x3A, (byte)0x80, 1, 0x2E, (byte)0xA0, (byte)0x80, 0x18, 0, 0, 0, 0, 0x14, 0, 0, 4, 0x65, 0, 0, 0, 0, 0, 0, 0x30, 0, 0x04, 0x28, 0x13, 0x05, 0x47, 0x46, (byte)0x87, 0x71, 0x12, 0x59, 0x46, 0x04, 0x28, 0x04, 0x28, 0x08, 0x11, 0x05, 0x12, 0x34}, 0);
}
@Test
public void testBinaryNumberParsing() throws ParseException {
NumericParseInfo npi = new NumericParseInfo(6);
IsoValue<Number> val = npi.parseBinary(0, new byte[]{0x12, 0x34, 0x56}, 0, null);
Assert.assertEquals(123456, val.getValue().intValue());
}
@Test
public void testComposite() throws ParseException, UnsupportedEncodingException {
IsoMessage m = mf.parseMessage("12000040000000000000016one 03two12345.".getBytes(), 0);
Assert.assertNotNull(m);
CompositeField f = m.getObjectValue(10);
Assert.assertNotNull(f);
Assert.assertEquals(4, f.getValues().size());
Assert.assertEquals("one ", f.getObjectValue(0));
Assert.assertEquals("two", f.getObjectValue(1));
Assert.assertEquals("12345", f.getObjectValue(2));
Assert.assertEquals(".", f.getObjectValue(3));
}
@Test
public void testDates() throws ParseException, UnsupportedEncodingException {
IsoMessage m = mf.parseMessage("060002000000000000000125213456".getBytes(), 0);
Assert.assertNotNull(m);
Date f = m.getObjectValue(7);
Assert.assertNotNull(f);
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(f);
Assert.assertEquals(Calendar.JANUARY, cal.get(Calendar.MONTH));
Assert.assertEquals(25, cal.get(Calendar.DATE));
Assert.assertEquals(21, cal.get(Calendar.HOUR_OF_DAY));
mf.setTimezoneForParseGuide(0x600, 7, TimeZone.getTimeZone("GMT"));
m = mf.parseMessage("060002000000000000000125213456".getBytes(), 0);
f = m.getObjectValue(7);
cal.setTime(f);
Assert.assertEquals(Calendar.JANUARY, cal.get(Calendar.MONTH));
Assert.assertEquals(25, cal.get(Calendar.DATE));
Assert.assertEquals(15, cal.get(Calendar.HOUR_OF_DAY));
mf.setTimezoneForParseGuide(0x600, 7, TimeZone.getTimeZone("GMT+0100"));
m = mf.parseMessage("060002000000000000000125213456".getBytes(), 0);
f = m.getObjectValue(7);
cal.setTime(f);
Assert.assertEquals(Calendar.JANUARY, cal.get(Calendar.MONTH));
Assert.assertEquals(25, cal.get(Calendar.DATE));
Assert.assertEquals(14, cal.get(Calendar.HOUR_OF_DAY));
}
}
@@ -0,0 +1,101 @@
package com.solab.iso8583.parse;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.MessageFactory;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.codecs.BigIntBcdCodec;
import com.solab.iso8583.codecs.LongBcdCodec;
import com.solab.iso8583.util.HexCodec;
import org.junit.Assert;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.text.ParseException;
import java.util.HashMap;
/**
* Unit tests for the numeric CustomBinaryField codecs.
*
* @author Enrique Zamudio
* Date: 07/05/13 13:20
*/
public class CustomBinCodecs {
private final BigInteger b29 = new BigInteger("12345678901234567890123456789");
final byte[] longData2 = new byte[]{ 0x12, 0x34, 0x56, 0x78, (byte)0x90, 00, 00, 00, 00, 00 };
final byte[] bigintData1 = new byte[]{ 1, 0x23, 0x45, 0x67, (byte)0x89, 1, 0x23, 0x45, 0x67, (byte)0x89, 1, 0x23, 0x45, 0x67, (byte)0x89, 00, 00, 00, 00, 00 };
@Test
public void testLongCodec() {
final LongBcdCodec longCodec = new LongBcdCodec();
final byte[] data1 = new byte[]{ 1, 0x23, 0x45, (byte)0x67, (byte)0x89, 00, 00, 00, 00, 00 };
Assert.assertEquals(123456789l, (long) longCodec.decodeBinaryField(data1, 0, 5));
Assert.assertEquals(1234567890l, (long)longCodec.decodeBinaryField(longData2, 0, 5));
final byte[] cod1 = longCodec.encodeBinaryField(123456789l);
final byte[] cod2 = longCodec.encodeBinaryField(1234567890l);
for (int i = 0; i < 5; i++) {
Assert.assertEquals("LONG Data1 differs at pos " + i, data1[i], cod1[i]);
Assert.assertEquals("LONG Data2 differs at pos " + i, longData2[i], cod2[i]);
}
}
@Test
public void testBigIntCodec() {
final BigInteger b30 = new BigInteger("123456789012345678901234567890");
final BigIntBcdCodec bigintCodec = new BigIntBcdCodec();
final byte[] data2 = new byte[]{ 0x12, 0x34, 0x56, 0x78, (byte)0x90, 0x12, 0x34, 0x56, 0x78, (byte)0x90, 0x12, 0x34, 0x56, (byte)0x78, (byte)0x90, 00, 00, 00, 00, 00 };
Assert.assertEquals(b29, bigintCodec.decodeBinaryField(bigintData1, 0, 15));
Assert.assertEquals(b30, bigintCodec.decodeBinaryField(data2, 0, 15));
final byte[] cod1 = bigintCodec.encodeBinaryField(b29);
final byte[] cod2 = bigintCodec.encodeBinaryField(b30);
for (int i = 0; i < 15; i++) {
Assert.assertEquals("BIGINT Data1 differs at pos " + i, bigintData1[i], cod1[i]);
Assert.assertEquals("BIGINT Data2 differs at pos " + i, data2[i], cod2[i]);
}
}
private void testFieldType(final IsoType type, final FieldParseInfo fieldParser, int offset1, int offset2) throws UnsupportedEncodingException, ParseException {
final BigIntBcdCodec bigintCodec = new BigIntBcdCodec();
final LongBcdCodec longCodec = new LongBcdCodec();
final MessageFactory<IsoMessage> mfact = new MessageFactory<IsoMessage>();
IsoMessage tmpl = new IsoMessage();
tmpl.setBinary(true);
tmpl.setType(0x200);
tmpl.setValue(2, 1234567890l, longCodec, type, 0);
tmpl.setValue(3, b29, bigintCodec, type, 0);
mfact.addMessageTemplate(tmpl);
mfact.setCustomField(2, longCodec);
mfact.setCustomField(3, bigintCodec);
HashMap<Integer, FieldParseInfo> parser = new HashMap<Integer,FieldParseInfo>();
parser.put(2, fieldParser);
parser.put(3, fieldParser);
mfact.setParseMap(0x200, parser);
mfact.setUseBinaryMessages(true);
//Test encoding
tmpl = mfact.newMessage(0x200);
byte[] buf = tmpl.writeData();
System.out.println("MENSAJE: " + HexCodec.hexEncode(buf, 0, buf.length));
for (int i = 0; i < 5; i++) {
Assert.assertEquals("LONG Data differs at pos " + i, longData2[i], buf[i+offset1]);
}
for (int i = 0; i < 15; i++) {
Assert.assertEquals("BIGINT Data differs at pos " + i, bigintData1[i], buf[i+offset2]);
}
//Test parsing
tmpl = mfact.parseMessage(buf, 0);
Assert.assertEquals(1234567890l, tmpl.getObjectValue(2));
Assert.assertEquals(b29, tmpl.getObjectValue(3));
}
@Test
public void testLLBIN() throws ParseException, UnsupportedEncodingException {
testFieldType(IsoType.LLBIN, new LlbinParseInfo(), 11, 17);
}
@Test
public void testLLLBIN() throws ParseException, UnsupportedEncodingException {
testFieldType(IsoType.LLLBIN, new LllbinParseInfo(), 12, 19);
}
}
@@ -0,0 +1,82 @@
package com.solab.iso8583.parse;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.IsoValue;
import com.solab.iso8583.codecs.CompositeField;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests for the CompositeField.
*
* @author Enrique Zamudio
* Date: 25/11/13 17:43
*/
public class TestComposites {
final String textData = "One 03Two00999X";
final byte[] binaryData = new byte[]{'O', 'n', 'e', ' ', ' ', 3, 'T', 'w', 'o',
0, 9, (byte) 0x99, 'X'};
@Test
public void testEncodeText() {
final CompositeField f = new CompositeField();
f.addValue(new IsoValue<String>(IsoType.ALPHA, "One", 5));
f.getValues().get(0).setCharacterEncoding("UTF-8");
Assert.assertEquals("One ", f.encodeField(f));
f.addValue("Two", null, IsoType.LLVAR, 0);
f.getValues().get(1).setCharacterEncoding("UTF-8");
Assert.assertEquals("One 03Two", f.encodeField(f));
f.addValue(999, null, IsoType.NUMERIC, 5);
f.getValues().get(2).setCharacterEncoding("UTF-8");
Assert.assertEquals("One 03Two00999", f.encodeField(f));
f.addValue("X", null, IsoType.ALPHA, 1);
Assert.assertEquals(textData, f.encodeField(f));
}
@Test
public void testEncodeBinary() {
final CompositeField f = new CompositeField()
.addValue(new IsoValue<String>(IsoType.ALPHA, "One", 5));
Assert.assertArrayEquals(new byte[]{'O', 'n', 'e', 32, 32}, f.encodeBinaryField(f));
f.addValue(new IsoValue<String>(IsoType.LLVAR, "Two"));
Assert.assertArrayEquals(new byte[]{'O', 'n', 'e', ' ', ' ', 3, 'T', 'w', 'o'},
f.encodeBinaryField(f));
f.addValue(new IsoValue<Long>(IsoType.NUMERIC, 999l, 5));
f.addValue(new IsoValue<String>(IsoType.ALPHA, "X", 1));
Assert.assertArrayEquals(binaryData, f.encodeBinaryField(f));
}
@Test
public void testDecodeText() {
final CompositeField dec = new CompositeField()
.addParser(new AlphaParseInfo(5))
.addParser(new LlvarParseInfo())
.addParser(new NumericParseInfo(5))
.addParser(new AlphaParseInfo(1));
final CompositeField f = dec.decodeField(textData);
Assert.assertNotNull(f);
Assert.assertEquals(4, f.getValues().size());
Assert.assertEquals("One ", f.getValues().get(0).getValue());
Assert.assertEquals("Two", f.getValues().get(1).getValue());
Assert.assertEquals("00999", f.getValues().get(2).getValue());
Assert.assertEquals("X", f.getValues().get(3).getValue());
}
@Test
public void testDecodeBinary() {
final CompositeField dec = new CompositeField()
.addParser(new AlphaParseInfo(5))
.addParser(new LlvarParseInfo())
.addParser(new NumericParseInfo(5))
.addParser(new AlphaParseInfo(1));
final CompositeField f = dec.decodeBinaryField(binaryData, 0, binaryData.length);
Assert.assertNotNull(f);
Assert.assertEquals(4, f.getValues().size());
Assert.assertEquals("One ", f.getValues().get(0).getValue());
Assert.assertEquals("Two", f.getValues().get(1).getValue());
Assert.assertEquals(999l, f.getValues().get(2).getValue());
Assert.assertEquals("X", f.getValues().get(3).getValue());
}
}
@@ -0,0 +1,51 @@
package com.solab.iso8583.parse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.GregorianCalendar;
import org.junit.*;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.IsoValue;
/** Test that the dates are formatted and parsed correctly.
*
* @author Enrique Zamudio
*/
public class TestDates {
@Test
public void testDate4FutureTolerance() throws ParseException, IOException {
GregorianCalendar today = new GregorianCalendar();
Date soon = new Date(today.getTime().getTime() + 50000);
today.set(GregorianCalendar.HOUR,0);
today.set(GregorianCalendar.MINUTE,0);
today.set(GregorianCalendar.SECOND,0);
today.set(GregorianCalendar.MILLISECOND,0);
byte[] buf = IsoType.DATE4.format(soon, null).getBytes();
IsoValue<Date> 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, false);
IsoValue<Date> bin = new Date4ParseInfo().parseBinary(0, bout.toByteArray(), 0, null);
Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime());
}
@Test
public void testDate10FutureTolerance() throws ParseException, IOException {
Date soon = new Date(System.currentTimeMillis() + 50000);
byte[] buf = IsoType.DATE10.format(soon, null).getBytes();
IsoValue<Date> 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, false);
IsoValue<Date> bin = new Date10ParseInfo().parseBinary(0, bout.toByteArray(), 0, null);
Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime());
}
}
@@ -0,0 +1,57 @@
package com.solab.iso8583.util;
import org.junit.Assert;
import org.junit.Test;
/**
* BCD encoding tests.
*
* @author Enrique Zamudio
* Date: 25/11/13 10:43
*/
public class TestBcd {
@Test
public void testEncoding() {
byte[] buf = new byte[2];
buf[0] = 1; buf[1]=1;
Bcd.encode("00", buf);
Assert.assertArrayEquals(new byte[]{0, 1}, buf);
Bcd.encode("79", buf);
Assert.assertArrayEquals(new byte[]{0x79, 1}, buf);
Bcd.encode("80", buf);
Assert.assertArrayEquals(new byte[]{(byte)0x80,1}, buf);
Bcd.encode("99", buf);
Assert.assertArrayEquals(new byte[]{(byte)0x99,1}, buf);
Bcd.encode("100", buf);
Assert.assertArrayEquals(new byte[]{1, 0}, buf);
Bcd.encode("779", buf);
Assert.assertArrayEquals(new byte[]{7, 0x79}, buf);
Bcd.encode("999", buf);
Assert.assertArrayEquals(new byte[]{9,(byte)0x99}, buf);
}
@Test
public void testDecoding() {
byte[] buf = new byte[2];
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 1));
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 2));
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 3));
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 4));
buf[0]=0x79;
Assert.assertEquals(79, Bcd.decodeToLong(buf, 0, 2));
buf[0]=(byte)0x80;
Assert.assertEquals(80, Bcd.decodeToLong(buf, 0, 2));
buf[0]=(byte)0x99;
Assert.assertEquals(99, Bcd.decodeToLong(buf, 0, 2));
buf[0]=1;
Assert.assertEquals(100, Bcd.decodeToLong(buf,0,4));
buf[1]=0x79;
Assert.assertEquals(179, Bcd.decodeToLong(buf,0,4));
buf[1]=(byte)0x99;
Assert.assertEquals(199, Bcd.decodeToLong(buf,0,4));
buf[0]=9;
Assert.assertEquals(999, Bcd.decodeToLong(buf,0,4));
}
}
@@ -0,0 +1,46 @@
package com.solab.iso8583.util;
import org.junit.Assert;
import org.junit.Test;
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, 0, buf.length);
if (reenc.startsWith("0") && !hex.startsWith("0")) {
Assert.assertEquals(reenc.substring(1), hex);
} else {
Assert.assertEquals(hex, reenc);
}
}
@Test
public void testCodec() {
byte[] buf = HexCodec.hexDecode("A");
Assert.assertEquals(0x0a, buf[0]);
encodeDecode("A");
encodeDecode("0123456789ABCDEF");
buf = HexCodec.hexDecode("0123456789ABCDEF");
Assert.assertEquals(1, buf[0]);
Assert.assertEquals(0x23, buf[1]);
Assert.assertEquals(0x45, buf[2]);
Assert.assertEquals(0x67, buf[3]);
Assert.assertEquals(0x89, (buf[4] & 0xff));
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");
}
@Test
public void testPartial() {
Assert.assertEquals("FF01", HexCodec.hexEncode(new byte[]{0, (byte)0xff, 1, 2, 3, 4},
1, 2));
}
}