From dd83ef7b96f48e15376b0dd5f440c9a2a82d2b98 Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Thu, 26 Mar 2015 11:55:07 -0600 Subject: [PATCH] tests for #38 --- .../solab/iso8583/parse/TestEmptyLvars.java | 97 +++++++++++++++++++ src/test/resources/issue38.xml | 10 ++ 2 files changed, 107 insertions(+) create mode 100644 src/test/java/com/solab/iso8583/parse/TestEmptyLvars.java create mode 100644 src/test/resources/issue38.xml diff --git a/src/test/java/com/solab/iso8583/parse/TestEmptyLvars.java b/src/test/java/com/solab/iso8583/parse/TestEmptyLvars.java new file mode 100644 index 0000000..d2bb4d2 --- /dev/null +++ b/src/test/java/com/solab/iso8583/parse/TestEmptyLvars.java @@ -0,0 +1,97 @@ +package com.solab.iso8583.parse; + +import com.solab.iso8583.IsoType; +import com.solab.iso8583.MessageFactory; +import com.solab.iso8583.IsoMessage; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +/** + * Issue 38. + * + * @author Enrique Zamudio + * Date: 26/03/15 10:54 + */ +public class TestEmptyLvars { + + private static MessageFactory txtfact = new MessageFactory<>(); + private static MessageFactory binfact = new MessageFactory<>(); + @BeforeClass + public static void setupSpec() throws IOException { + txtfact.setConfigPath("issue38.xml"); + binfact.setUseBinaryMessages(true); + binfact.setConfigPath("issue38.xml"); + } + + private void checkString(byte[] txt, byte[] bin, int field) + throws IOException, ParseException { + IsoMessage t = txtfact.parseMessage(txt, 0); + IsoMessage b = binfact.parseMessage(bin, 0); + Assert.assertTrue(t.hasField(field)); + Assert.assertTrue(b.hasField(field)); + Assert.assertTrue(((String) t.getObjectValue(field)).isEmpty()); + Assert.assertTrue(((String) b.getObjectValue(field)).isEmpty()); + } + private void checkBin(byte[] txt, byte[] bin, int field) + throws IOException, ParseException { + IsoMessage t = txtfact.parseMessage(txt, 0); + IsoMessage b = binfact.parseMessage(bin, 0); + Assert.assertTrue(t.hasField(field)); + Assert.assertTrue(b.hasField(field)); + Assert.assertEquals(0, ((byte[]) t.getObjectValue(field)).length); + Assert.assertEquals(0, ((byte[]) b.getObjectValue(field)).length); + } + @Test + public void testEmptyLLVAR() throws Exception { + IsoMessage t = txtfact.newMessage(0x100); + IsoMessage b = binfact.newMessage(0x100); + t.setValue(2, "", IsoType.LLVAR, 0); + b.setValue(2, "", IsoType.LLVAR, 0); + checkString(t.writeData(), b.writeData(), 2); + } + @Test + public void testEmptyLLLVAR() throws Exception { + IsoMessage t = txtfact.newMessage(0x100); + IsoMessage b = binfact.newMessage(0x100); + t.setValue(3, "", IsoType.LLLVAR, 0); + b.setValue(3, "", IsoType.LLLVAR, 0); + checkString(t.writeData(), b.writeData(), 3); + } + @Test + public void testEmptyLLLLVAR() throws Exception { + IsoMessage t = txtfact.newMessage(0x100); + IsoMessage b = binfact.newMessage(0x100); + t.setValue(4, "", IsoType.LLLLVAR, 0); + b.setValue(4, "", IsoType.LLLLVAR, 0); + checkString(t.writeData(), b.writeData(), 4); + } + @Test + public void testEmptyLLBIN() throws Exception { + IsoMessage t = txtfact.newMessage(0x100); + IsoMessage b = binfact.newMessage(0x100); + t.setValue(5, new byte[0], IsoType.LLBIN, 0); + b.setValue(5, new byte[0], IsoType.LLBIN, 0); + checkBin(t.writeData(), b.writeData(), 5); + } + @Test + public void testEmptyLLLBIN() throws Exception { + IsoMessage t = txtfact.newMessage(0x100); + IsoMessage b = binfact.newMessage(0x100); + t.setValue(6, new byte[0], IsoType.LLLBIN, 0); + b.setValue(6, new byte[0], IsoType.LLLBIN, 0); + checkBin(t.writeData(), b.writeData(), 6); + } + @Test + public void testEmptyLLLLBIN() throws Exception { + IsoMessage t = txtfact.newMessage(0x100); + IsoMessage b = binfact.newMessage(0x100); + t.setValue(7, new byte[0], IsoType.LLLLBIN, 0); + b.setValue(7, new byte[0], IsoType.LLLLBIN, 0); + checkBin(t.writeData(), b.writeData(), 7); + } + +} diff --git a/src/test/resources/issue38.xml b/src/test/resources/issue38.xml new file mode 100644 index 0000000..1ce7e2e --- /dev/null +++ b/src/test/resources/issue38.xml @@ -0,0 +1,10 @@ + + + + + + + + + +