More tests for #13

This commit is contained in:
Enrique Zamudio
2013-05-13 19:34:04 -05:00
parent 38df434d0a
commit e5aa694a45
+55 -7
View File
@@ -3,17 +3,16 @@ package j8583;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.IsoValue;
import com.solab.iso8583.parse.LlbinParseInfo;
import com.solab.iso8583.parse.LllbinParseInfo;
import com.solab.iso8583.parse.LllvarParseInfo;
import com.solab.iso8583.parse.LlvarParseInfo;
import com.solab.iso8583.parse.*;
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;
/**
* Test for EBCDIC support.
@@ -84,10 +83,59 @@ public class TestEbcdic {
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) 241, enc[0]);
Assert.assertEquals((byte) 241, enc[1]);
Assert.assertEquals((byte)240, enc[2]);
Assert.assertEquals((byte)240, enc[3]);
Assert.assertEquals((byte) 240, enc[3]);
}
@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());
}
}