Search in sources :

Example 21 with ISOField

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));
}
Also used : ISOField(org.jpos.iso.ISOField) ISOMultiFieldPackager(org.jpos.iso.packager.ISOMultiFieldPackager) IFB_LLNUM(org.jpos.iso.IFB_LLNUM) IFE_LLNUM(org.jpos.iso.IFE_LLNUM)

Example 22 with ISOField

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());
}
Also used : ISOField(org.jpos.iso.ISOField) ISOMultiFieldPackager(org.jpos.iso.packager.ISOMultiFieldPackager) IFB_LLNUM(org.jpos.iso.IFB_LLNUM) IFE_LLNUM(org.jpos.iso.IFE_LLNUM)

Example 23 with ISOField

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));
}
Also used : LiteralTagValue(org.jpos.tlv.LiteralTagValue) ISOField(org.jpos.iso.ISOField) ISOMsg(org.jpos.iso.ISOMsg) GenericPackager(org.jpos.iso.packager.GenericPackager) GenericTagSequence(org.jpos.tlv.GenericTagSequence) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 24 with ISOField

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));
}
Also used : LiteralTagValue(org.jpos.tlv.LiteralTagValue) ISOField(org.jpos.iso.ISOField) ISOMsg(org.jpos.iso.ISOMsg) GenericPackager(org.jpos.iso.packager.GenericPackager) GenericTagSequence(org.jpos.tlv.GenericTagSequence) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 25 with ISOField

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!
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOMultiFieldPackager(org.jpos.iso.packager.ISOMultiFieldPackager) IFB_LLNUM(org.jpos.iso.IFB_LLNUM) IFE_LLNUM(org.jpos.iso.IFE_LLNUM)

Aggregations

ISOField (org.jpos.iso.ISOField)50 Test (org.junit.Test)18 ISOException (org.jpos.iso.ISOException)15 ISOTaggedField (org.jpos.tlv.ISOTaggedField)15 IFB_LLNUM (org.jpos.iso.IFB_LLNUM)6 IFE_LLNUM (org.jpos.iso.IFE_LLNUM)6 ISOMsg (org.jpos.iso.ISOMsg)6 ISOMultiFieldPackager (org.jpos.iso.packager.ISOMultiFieldPackager)6 ISOComponent (org.jpos.iso.ISOComponent)5 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)5 ISOVField (org.jpos.iso.ISOVField)5 Vector (java.util.Vector)4 FileInputStream (java.io.FileInputStream)3 Map (java.util.Map)3 ISOBinaryField (org.jpos.iso.ISOBinaryField)3 ByteBuffer (java.nio.ByteBuffer)2 ISOVError (org.jpos.iso.ISOVError)2 GenericPackager (org.jpos.iso.packager.GenericPackager)2 GenericTagSequence (org.jpos.tlv.GenericTagSequence)2 LiteralTagValue (org.jpos.tlv.LiteralTagValue)2