tests for LLLLVAR and LLLLBIN #36

This commit is contained in:
Enrique Zamudio
2015-02-19 19:39:16 -06:00
parent 2db47ed814
commit 576dc50b44
4 changed files with 92 additions and 0 deletions
@@ -0,0 +1,10 @@
package com.solab.iso8583.parse;
/**
* Blabla.
*
* @author Enrique Zamudio
* Date: 19/02/15 18:29
*/
public class LlllbinParseInfo {
}
@@ -0,0 +1,10 @@
package com.solab.iso8583.parse;
/**
* Blabla.
*
* @author Enrique Zamudio
* Date: 19/02/15 18:30
*/
public class LlllvarParseInfo {
}
@@ -0,0 +1,62 @@
package com.solab.iso8583;
import com.solab.iso8583.util.HexCodec;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.text.ParseException;
/**
* Tests for LLLLVAR and LLLLBIN.
*
* @author Enrique Zamudio
* Date: 19/02/15 18:25
*/
public class TestLlll {
private MessageFactory<IsoMessage> mfact = new MessageFactory<>();
@Before
public void setup() throws IOException {
mfact.setConfigPath("issue36.xml");
mfact.setAssignDate(false);
}
@Test
public void testTemplate() {
IsoMessage m = mfact.newMessage(0x100);
Assert.assertEquals("010060000000000000000001X0002FF", m.debugString());
m.setBinary(true);
Assert.assertArrayEquals(new byte[]{1, 0, (byte) 0x60, 0, 0, 0, 0, 0, 0, 0,
0, 1, (byte) 'X', 0, 1, (byte)0xff}, m.writeData());
}
@Test
public void testNewMessage() {
IsoMessage m = mfact.newMessage(0x200);
m.setValue(2, "Variable length text", IsoType.LLLLVAR, 0);
m.setValue(3, "FFFF", IsoType.LLLLBIN, 0);
Assert.assertEquals("020060000000000000000020Variable length text0004FFFF", m.debugString());
m.setBinary(true);
m.setValue(2, "XX", IsoType.LLLLVAR, 0);
m.setValue(3, new byte[]{(byte) 0xff}, IsoType.LLLLBIN, 0);
Assert.assertArrayEquals(new byte[]{2, 0, (byte) 0x60, 0, 0, 0, 0, 0, 0, 0,
0, 2, (byte)'X', (byte)'X', 0, 1, (byte)0xff}, m.writeData());
}
@Test
public void testParsing() throws ParseException, IOException {
IsoMessage m = mfact.parseMessage("010060000000000000000001X0002FF".getBytes(), 0);
Assert.assertNotNull(m);
Assert.assertEquals("X", m.getObjectValue(2));
Assert.assertArrayEquals(new byte[]{(byte) 0xff}, (byte[])m.getObjectValue(3));
mfact.setUseBinaryMessages(true);
m = mfact.parseMessage(new byte[]{1, 0, (byte) 0x60, 0, 0, 0, 0, 0, 0, 0,
0, 2, (byte)'X', (byte)'X', 0, 1, (byte)0xff}, 0);
Assert.assertNotNull(m);
Assert.assertEquals("XX", m.getObjectValue(2));
Assert.assertArrayEquals(new byte[]{(byte) 0xff}, (byte[])m.getObjectValue(3));
}
}
+10
View File
@@ -0,0 +1,10 @@
<j8583-config>
<template type="0100">
<field num="2" type="LLLLVAR">X</field>
<field num="3" type="LLLLBIN">FF</field>
</template>
<parse type="0100">
<field num="2" type="LLLLVAR" />
<field num="3" type="LLLLBIN" />
</parse>
</j8583-config>