From e5aa694a45e560f6fac233ea2bb460bd46e31543 Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Mon, 13 May 2013 19:34:04 -0500 Subject: [PATCH] More tests for #13 --- src/test/java/j8583/TestEbcdic.java | 62 +++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/src/test/java/j8583/TestEbcdic.java b/src/test/java/j8583/TestEbcdic.java index 8dce996..d6a3c07 100644 --- a/src/test/java/j8583/TestEbcdic.java +++ b/src/test/java/j8583/TestEbcdic.java @@ -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 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 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 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 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 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()); } }