Search in sources :

Example 11 with ISOBinaryField

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

the class Base1_BITMAP126Test method testPackThrowsNullPointerException.

@Test
public void testPackThrowsNullPointerException() throws Throwable {
    try {
        new Base1_BITMAP126(100, "testBase1_BITMAP126Description").pack(new ISOBinaryField());
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        assertNull("ex.getMessage()", ex.getMessage());
    }
}
Also used : ISOBinaryField(org.jpos.iso.ISOBinaryField) Test(org.junit.Test)

Example 12 with ISOBinaryField

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

the class CTCSubElementPackagerTest method testPack.

@Test
public void testPack() throws Throwable {
    CTCSubElementPackager cTCSubElementPackager = new CTCSubElementPackager();
    ISOFieldPackager[] fld = new ISOFieldPackager[2];
    cTCSubElementPackager.setFieldPackager(fld);
    byte[] result = cTCSubElementPackager.pack(new ISOBinaryField());
    assertEquals("result.length", 0, result.length);
}
Also used : ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOFieldPackager(org.jpos.iso.ISOFieldPackager) Test(org.junit.Test)

Example 13 with ISOBinaryField

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

the class CTCSubFieldPackagerTest method testPackThrowsISOException1.

@Test
public void testPackThrowsISOException1() throws Throwable {
    try {
        new CTCSubFieldPackager().pack(new ISOBinaryField(100));
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "null: null", ex.getMessage());
        assertNull("ex.getNested().getMessage()", ex.getNested().getMessage());
    }
}
Also used : ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOException(org.jpos.iso.ISOException) Test(org.junit.Test)

Example 14 with ISOBinaryField

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

the class TagSequenceBase method readFrom.

@Override
public synchronized void readFrom(ISOMsg isoMsg) throws ISOException {
    int maxField = isoMsg.getMaxField();
    int minField = -1;
    for (int i = 0; i <= maxField; i++) {
        ISOComponent child = isoMsg.getComponent(i);
        if (child instanceof ISOTaggedField) {
            minField = i;
            break;
        }
    }
    if (minField == -1) {
        // No TaggedFields to read
        return;
    }
    for (int i = minField; i <= maxField; i++) {
        ISOComponent child = isoMsg.getComponent(i);
        if (child != null) {
            if (child instanceof ISOTaggedField) {
                TagValue tagValue;
                ISOTaggedField taggedSubField = (ISOTaggedField) child;
                ISOComponent delegate = taggedSubField.getDelegate();
                if (delegate instanceof ISOMsg) {
                    Map subChildren = delegate.getChildren();
                    boolean allTaggedValue = true;
                    for (Object subChild : subChildren.values()) {
                        if (!(subChild instanceof ISOTaggedField)) {
                            allTaggedValue = false;
                            break;
                        }
                    }
                    if (allTaggedValue) {
                        tagValue = createTagValueSequence(taggedSubField.getTag());
                        ((TagSequence) tagValue).readFrom((ISOMsg) delegate);
                    } else {
                        tagValue = new ISOMsgTagValue(getTag(), isoMsg);
                    }
                } else if (delegate instanceof ISOBinaryField) {
                    tagValue = createBinaryTagValuePair(taggedSubField.getTag(), taggedSubField.getBytes());
                } else if (delegate instanceof ISOField) {
                    tagValue = createLiteralTagValuePair(taggedSubField.getTag(), taggedSubField.getValue().toString());
                } else {
                    throw new ISOException("Unknown ISOComponent subclass in ISOTaggedField: " + delegate.getClass());
                }
                this.add(tagValue);
            } else {
                throw new ISOException("Children after first ISOTaggedField should be instance of ISOTaggedField." + " Field " + i + " is not an ISOTaggedField");
            }
        }
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

ISOBinaryField (org.jpos.iso.ISOBinaryField)14 Test (org.junit.Test)11 ISOException (org.jpos.iso.ISOException)7 ISOComponent (org.jpos.iso.ISOComponent)4 ISOField (org.jpos.iso.ISOField)3 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)3 ISOMsg (org.jpos.iso.ISOMsg)3 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Vector (java.util.Vector)1 IFA_LCHAR (org.jpos.iso.IFA_LCHAR)1 IFA_LLBNUM (org.jpos.iso.IFA_LLBNUM)1 TLVDataFormat (org.jpos.tlv.TLVDataFormat)1