Merge pull request #52 from lOlIl/llllvar-hotfix
fix #50 LLLLVar length
This commit is contained in:
@@ -277,7 +277,7 @@ public class IsoValue<T> implements Cloneable {
|
||||
}
|
||||
if (binary) {
|
||||
if (digits == 4) {
|
||||
outs.write((((l % 1000) / 100) << 4) | ((l % 1000)/100));
|
||||
outs.write((((l % 10000) / 1000) << 4) | ((l % 1000)/100));
|
||||
} else if (digits == 3) {
|
||||
outs.write(l / 100); //00 to 09 automatically in BCD
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class LlllvarParseInfo extends FieldParseInfo {
|
||||
"Insufficient data for bin LLLLVAR header, field %d pos %d",
|
||||
field, pos), pos);
|
||||
}
|
||||
final int len = ((buf[pos] & 0xf0) * 1000) + ((buf[pos] & 0x0f) * 100)
|
||||
final int len = (((buf[pos] & 0xf0) >> 4) * 1000) + ((buf[pos] & 0x0f) * 100)
|
||||
+ (((buf[pos + 1] & 0xf0) >> 4) * 10) + (buf[pos + 1] & 0x0f);
|
||||
if (len < 0) {
|
||||
throw new ParseException(String.format(
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.solab.iso8583;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Extended test for LLLLVar field
|
||||
*
|
||||
* @author Peter Margetiak
|
||||
*/
|
||||
public class TestLlllPatch {
|
||||
|
||||
private MessageFactory<IsoMessage> mfact = new MessageFactory<>();
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
mfact.setConfigPath("issue50.xml");
|
||||
mfact.setAssignDate(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingLength() throws Exception {
|
||||
final int LENGTH = 1234;
|
||||
|
||||
// prepare
|
||||
String LLLLVar = makeLLLLVar(LENGTH);
|
||||
StringBuilder LLLLVarBuilder = new StringBuilder();
|
||||
LLLLVarBuilder.append("01004000000000000000")
|
||||
.append(String.format("%04d", LENGTH)).append(LLLLVar);
|
||||
|
||||
// parse
|
||||
IsoMessage m = mfact.parseMessage(LLLLVarBuilder.toString().getBytes(), 0);
|
||||
Assert.assertNotNull(m);
|
||||
Assert.assertEquals(LLLLVar, m.getObjectValue(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialiseParseSmall() throws Exception {
|
||||
testSerialiseParse(88);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialiseParseMedium() throws Exception {
|
||||
testSerialiseParse(258);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialiseParseLarge() throws Exception {
|
||||
testSerialiseParse(9919);
|
||||
}
|
||||
|
||||
private void testSerialiseParse(final int LENGTH) throws Exception {
|
||||
// prepare
|
||||
String LLLLVar = makeLLLLVar(LENGTH);
|
||||
IsoMessage m = mfact.newMessage(0x100);
|
||||
m.setValue(2, LLLLVar, IsoType.LLLLVAR, 0);
|
||||
m.setBinary(true);
|
||||
|
||||
// write
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
m.write(bout, 2);
|
||||
bout.close();
|
||||
|
||||
// read
|
||||
byte[] buf = new byte[2];
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
bin.read(buf);
|
||||
Assert.assertNotEquals(buf, new byte[2]);
|
||||
|
||||
int len = ((buf[0] & 0xff) << 8) | (buf[1] & 0xff);
|
||||
buf = new byte[len];
|
||||
bin.read(buf);
|
||||
bin.close();
|
||||
|
||||
// parse
|
||||
mfact.setUseBinaryMessages(true);
|
||||
m = mfact.parseMessage(buf, mfact.getIsoHeader(0x100).length());
|
||||
Assert.assertNotNull(m);
|
||||
Assert.assertEquals(LLLLVar, m.getObjectValue(2));
|
||||
}
|
||||
|
||||
private String makeLLLLVar(final int length) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
sb.append("a");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<j8583-config>
|
||||
<header type="100">ISO999999999</header>
|
||||
<parse type="100">
|
||||
<field num="2" type="LLLLVAR" />
|
||||
</parse>
|
||||
</j8583-config>
|
||||
Reference in New Issue
Block a user