Search in sources :

Example 16 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class ISOBaseValidatingPackagerTest method testValidateThrowsNullPOinterException1.

@Test
public void testValidateThrowsNullPOinterException1() throws Throwable {
    try {
        new ISOBaseValidatingPackager().validate(new ISOField(100, "testISOBaseValidatingPackagerv"));
        fail("Expected ClassCastException to be thrown");
    } catch (NullPointerException ex) {
        assertEquals("ex.getClass()", NullPointerException.class, ex.getClass());
    }
}
Also used : ISOField(org.jpos.iso.ISOField) Test(org.junit.Test)

Example 17 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class GICCSubFieldPackager method pack.

public byte[] pack(ISOComponent c) throws ISOException {
    try {
        int len = 0;
        byte[] result;
        Map tab = c.getChildren();
        List list = new ArrayList();
        // Handle first IF_CHAR field
        ISOField f0 = (ISOField) tab.get(0);
        if (f0 != null) {
            String s = (String) f0.getValue();
            list.add(s.getBytes());
            len += s.getBytes().length;
        }
        for (int i = 1; i < fld.length; i++) {
            Object obj = tab.get(i);
            if (obj instanceof ISOComponent) {
                ISOComponent f = (ISOComponent) obj;
                byte[] b = fld[i].pack(f);
                list.add(b);
                len += b.length;
            }
        }
        result = new byte[len];
        int k = 0;
        for (int i = 0; i < list.size(); i++) {
            byte[] b = (byte[]) list.get(i);
            for (int j = 0; j < b.length; j++) result[k++] = b[j];
        }
        return result;
    } catch (Exception ex) {
        throw new ISOException(ex);
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOException(org.jpos.iso.ISOException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ISOException(org.jpos.iso.ISOException)

Example 18 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class ISOMultiFieldPackager method unpack.

/**
 * @param m      - the ISOComponent to receive the value consumed from ...
 * @param b      - the byte[] holding the raw message
 * @param offset - the current position within b.
 */
public int unpack(ISOComponent m, byte[] b, int offset) throws ISOException {
    ListIterator i = possibles.listIterator();
    while (i.hasNext()) {
        try {
            current = (ISOFieldPackager) i.next();
            ISOField f = new ISOField();
            int consumed = current.unpack(f, b, offset);
            m.setValue(f.getValue());
            return consumed;
        } catch (ISOException eok) {
            current = null;
        }
    }
    throw new ISOException("unpack failed in List process!");
}
Also used : ISOField(org.jpos.iso.ISOField) ISOException(org.jpos.iso.ISOException) ListIterator(java.util.ListIterator)

Example 19 with ISOField

use of org.jpos.iso.ISOField 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 20 with ISOField

use of org.jpos.iso.ISOField 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)

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