use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOMultiFieldPackagerTest method testPackArray.
public void testPackArray() throws Exception {
ISOMultiFieldPackager packager = new ISOMultiFieldPackager("Should be 041234", new ISOFieldPackager[] { new IFB_LLNUM(10, "Should not be this", true), new IFE_LLNUM(10, "Should be 041234"), new IFB_LLNUM(10, "The one to pack", true) });
packager.hint("The one to pack");
ISOField field = new ISOField(12, "1234");
TestUtils.assertEquals(new byte[] { (byte) 0x04, (byte) 0x12, (byte) 0x34 }, packager.pack(field));
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOMultiFieldPackagerTest method testUnpackArray.
public void testUnpackArray() throws Exception {
byte[] raw = new byte[] { (byte) 0xF0, (byte) 0xF4, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4 };
ISOMultiFieldPackager packager = new ISOMultiFieldPackager("An Array choice", new ISOFieldPackager[] { new IFB_LLNUM(10, "Should not be this", true), new IFE_LLNUM(10, "Should be 041234"), new IFB_LLNUM(10, "Should not be this", true) });
ISOField field = new ISOField();
packager.unpack(field, raw, 0);
assertEquals("1234", (String) field.getValue());
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOTaggedSequenceTest method testPackingWithPrefixes.
@Test
public void testPackingWithPrefixes() throws ISOException, FileNotFoundException {
ISOMsg msg = new ISOMsg("0100");
GenericTagSequence tagValueSequence = new GenericTagSequence();
tagValueSequence.add(new LiteralTagValue("0012", "19960930000000"));
tagValueSequence.add(new LiteralTagValue("0165", "M"));
tagValueSequence.add(new LiteralTagValue("0023", "CT2"));
ISOMsg field63 = new ISOMsg(63);
field63.set(new ISOField(0, "M"));
tagValueSequence.writeTo(field63);
msg.set(field63);
msg.recalcBitMap();
GenericPackager packager = new GenericPackager(new FileInputStream("build/resources/test/org/jpos/tlv/tagged-sequence-packager.xml"));
msg.setPackager(packager);
byte[] packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
byte[] field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 43, field48Packed.length);
Assert.assertEquals("Pack error", "040M0012014199609300000000165001M0023003CT2", new String(field48Packed));
msg = new ISOMsg();
packager.unpack(msg, packed);
packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
field48Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field48Packed, 0, field48Packed.length);
Assert.assertEquals("Pack error", 43, field48Packed.length);
Assert.assertEquals("Pack error", "040M0012014199609300000000165001M0023003CT2", new String(field48Packed));
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOTaggedSequenceTest method testPacking2.
@Test
public void testPacking2() throws ISOException, FileNotFoundException {
ISOMsg msg = new ISOMsg("0100");
GenericTagSequence tagValueSequence = new GenericTagSequence();
tagValueSequence.add(new LiteralTagValue("12", "A"));
ISOMsg field64 = new ISOMsg(64);
field64.set(new ISOField(0, "R"));
tagValueSequence.writeTo(field64);
msg.set(field64);
msg.recalcBitMap();
GenericPackager packager = new GenericPackager(new FileInputStream("build/resources/test/org/jpos/tlv/tagged-sequence-packager.xml"));
msg.setPackager(packager);
byte[] packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
byte[] field64Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field64Packed, 0, field64Packed.length);
Assert.assertEquals("Pack error", 9, field64Packed.length);
Assert.assertEquals("Pack error", "006R1201A", new String(field64Packed));
msg = new ISOMsg();
packager.unpack(msg, packed);
msg.recalcBitMap();
packed = packager.pack(msg);
// skip 4 byte MTI and 8 byte Primary BitMap
field64Packed = new byte[packed.length - 12];
System.arraycopy(packed, 12, field64Packed, 0, field64Packed.length);
Assert.assertEquals("Pack error", 9, field64Packed.length);
Assert.assertEquals("Pack error", "006R1201A", new String(field64Packed));
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOMultiFieldPackagerTest method testPackNoHintFail.
public void testPackNoHintFail() throws Exception {
ISOMultiFieldPackager packager = new ISOMultiFieldPackager("Should be 041234", new ISOFieldPackager[] { new IFB_LLNUM(10, "Should not be this", true), new IFE_LLNUM(10, "Should be 041234"), new IFB_LLNUM(10, "The one to pack", true) });
// packager.hint("The one to pack");
ISOField field = new ISOField(12, "1234");
try {
TestUtils.assertEquals(new byte[] { (byte) 0x04, (byte) 0x12, (byte) 0x34 }, packager.pack(field));
fail("pack without hint should fail with ISOException!");
} catch (Exception expected) {
// Expected!
}
}
Aggregations