Search in sources :

Example 1 with ISOMultiFieldPackager

use of org.jpos.iso.packager.ISOMultiFieldPackager in project jPOS by jpos.

the class ISOMultiFieldPackagerTest method testUnpackList.

public void testUnpackList() throws Exception {
    byte[] raw = new byte[] { (byte) 0xF0, (byte) 0xF4, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4 };
    Vector list = new Vector();
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    list.add(new IFE_LLNUM(10, "Should be 041234"));
    list.add(new IFB_LLNUM(10, "Should not be this", true));
    ISOMultiFieldPackager packager = new ISOMultiFieldPackager("A List choice", list);
    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) Vector(java.util.Vector) IFE_LLNUM(org.jpos.iso.IFE_LLNUM)

Example 2 with ISOMultiFieldPackager

use of org.jpos.iso.packager.ISOMultiFieldPackager in project jPOS by jpos.

the class ISOMultiFieldPackagerTest method testUnpackArrayfromInputStream.

public void testUnpackArrayfromInputStream() 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, (InputStream) new ByteArrayInputStream(raw));
    assertEquals("1234", (String) field.getValue());
}
Also used : ISOField(org.jpos.iso.ISOField) ByteArrayInputStream(java.io.ByteArrayInputStream) ISOMultiFieldPackager(org.jpos.iso.packager.ISOMultiFieldPackager) IFB_LLNUM(org.jpos.iso.IFB_LLNUM) IFE_LLNUM(org.jpos.iso.IFE_LLNUM)

Example 3 with ISOMultiFieldPackager

use of org.jpos.iso.packager.ISOMultiFieldPackager 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 4 with ISOMultiFieldPackager

use of org.jpos.iso.packager.ISOMultiFieldPackager 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 5 with ISOMultiFieldPackager

use of org.jpos.iso.packager.ISOMultiFieldPackager 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

IFB_LLNUM (org.jpos.iso.IFB_LLNUM)6 IFE_LLNUM (org.jpos.iso.IFE_LLNUM)6 ISOField (org.jpos.iso.ISOField)6 ISOMultiFieldPackager (org.jpos.iso.packager.ISOMultiFieldPackager)6 Vector (java.util.Vector)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1