Fix #4 (which wasn't really a bug but uncovered a couple of them)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package j8583;
|
||||
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
import com.solab.iso8583.MessageFactory;
|
||||
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,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE j8583-config PUBLIC "-//J8583//DTD CONFIG 1.0//EN"
|
||||
"http://j8583.sourceforge.net/j8583.dtd">
|
||||
<j8583-config>
|
||||
<template type="0800">
|
||||
<field num="3" type="NUMERIC" length="6">990000</field>
|
||||
<field num="7" type="DATE10">1227120330</field>
|
||||
<field num="11" type="NUMERIC" length="6">2</field>
|
||||
<field num="24" type="NUMERIC" length="3">831</field>
|
||||
<field num="41" type="ALPHA" length="8">42001</field>
|
||||
<field num="42" type="ALPHA" length="15">420000000000001</field>
|
||||
</template>
|
||||
<parse type="0800">
|
||||
<field num="3" type="NUMERIC" length="6" />
|
||||
<field num="7" type="DATE10" />
|
||||
<field num="11" type="NUMERIC" length="6" />
|
||||
<field num="24" type="NUMERIC" length="3" />
|
||||
<field num="41" type="ALPHA" length="8" />
|
||||
<field num="42" type="ALPHA" length="15" />
|
||||
</parse>
|
||||
</j8583-config>
|
||||
@@ -0,0 +1,4 @@
|
||||
log4j.rootLogger=TRACE, A1
|
||||
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %C{1} - %m%n
|
||||
Reference in New Issue
Block a user