Search in sources :

Example 6 with ISOException

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

the class BERTLVPackager method packTLV.

private byte[] packTLV(ISOTaggedField c) throws ISOException {
    byte[] b;
    final byte[] rawValueBytes;
    try {
        rawValueBytes = packValue(c.getTag(), c);
    } catch (UnknownTagNumberException e) {
        throw new ISOException(e);
    }
    byte[] valueBytes = new byte[valueInterpreter.getPackedLength(rawValueBytes.length)];
    valueInterpreter.interpret(rawValueBytes, valueBytes, 0);
    byte[] tagBytes = packTag(c);
    byte[] lengthBytes = packLength(valueBytes);
    b = new byte[tagBytes.length + lengthBytes.length + valueBytes.length];
    System.arraycopy(tagBytes, 0, b, 0, tagBytes.length);
    System.arraycopy(lengthBytes, 0, b, tagBytes.length, lengthBytes.length);
    System.arraycopy(valueBytes, 0, b, tagBytes.length + lengthBytes.length, valueBytes.length);
    return b;
}
Also used : ISOException(org.jpos.iso.ISOException) UnknownTagNumberException(org.jpos.emv.UnknownTagNumberException)

Example 7 with ISOException

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

the class MSGTEST1Test method testValidateThrowsISOException.

@Test
public void testValidateThrowsISOException() throws Throwable {
    try {
        new MSGTEST(true).validate(new ISOBinaryField());
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "Can't call validate on non Composite", ex.getMessage());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOException(org.jpos.iso.ISOException) Test(org.junit.Test)

Example 8 with ISOException

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

the class ChannelAdaptorTest method stopCanWaitForWorkersEvenWhenOutgoingChannelNeverConnects.

@Test
public void stopCanWaitForWorkersEvenWhenOutgoingChannelNeverConnects() throws Exception {
    ISOChannel channel = mock(ISOChannel.class);
    when(channel.isConnected()).thenReturn(false);
    when(channel.receive()).thenThrow(new ISOException("unconnected ISOChannel"));
    // repeat test to ensure clean up occurs after stop
    for (int i = 0; i < 10; i++) {
        channelAdaptor = configureAndStart(new ChannelAdaptorWithoutQ2(channel));
        waitForSenderAndReceiverToStart();
        assertCallToStopCompletes(i);
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ISOChannel(org.jpos.iso.ISOChannel) Test(org.junit.Test)

Example 9 with ISOException

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

the class CTCSubElementPackagerTest method testUnpackThrowsISOException.

@Test
public void testUnpackThrowsISOException() throws Throwable {
    CTCSubElementPackager cTCSubElementPackager = new CTCSubElementPackager();
    ISOFieldPackager[] fld = new ISOFieldPackager[2];
    cTCSubElementPackager.setFieldPackager(fld);
    cTCSubElementPackager.setLogger(new Logger(), "testCTCSubElementPackagerRealm");
    cTCSubElementPackager.setFieldPackager(0, new IFE_CHAR());
    byte[] b = new byte[2];
    try {
        cTCSubElementPackager.unpack(new ISOVField(new ISOField(100, "testCTCSubElementPackagerv"), null), b);
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "Can't add to Leaf", ex.getMessage());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOException(org.jpos.iso.ISOException) ISOVField(org.jpos.iso.ISOVField) ISOFieldPackager(org.jpos.iso.ISOFieldPackager) Logger(org.jpos.util.Logger) IFE_CHAR(org.jpos.iso.IFE_CHAR) Test(org.junit.Test)

Example 10 with ISOException

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

the class CTCSubElementPackagerTest method testPackThrowsISOException.

@Test
public void testPackThrowsISOException() throws Throwable {
    CTCSubElementPackager cTCSubElementPackager = new CTCSubElementPackager();
    ISOFieldPackager[] fld = new ISOFieldPackager[2];
    cTCSubElementPackager.setFieldPackager(fld);
    try {
        cTCSubElementPackager.pack(new ISOMsg("testCTCSubElementPackagerMti"));
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getNested().getClass()", ClassCastException.class, ex.getNested().getClass());
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOFieldPackager(org.jpos.iso.ISOFieldPackager) Test(org.junit.Test)

Aggregations

ISOException (org.jpos.iso.ISOException)66 Test (org.junit.Test)36 ISOMsg (org.jpos.iso.ISOMsg)29 ISOField (org.jpos.iso.ISOField)15 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)12 ISOBaseValidator (org.jpos.iso.ISOBaseValidator)8 IOException (java.io.IOException)7 ISOBinaryField (org.jpos.iso.ISOBinaryField)7 TEST0100 (org.jpos.iso.validator.TEST0100)7 Map (java.util.Map)6 ConfigurationException (org.jpos.core.ConfigurationException)6 ISOComponent (org.jpos.iso.ISOComponent)6 ISOFieldValidator (org.jpos.iso.ISOFieldValidator)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LogEvent (org.jpos.util.LogEvent)5 SAXParseException (org.xml.sax.SAXParseException)5 IVA_ALPHANUMNOBLANK (org.jpos.iso.IVA_ALPHANUMNOBLANK)4 ISOVException (org.jpos.iso.validator.ISOVException)4 ISOTaggedField (org.jpos.tlv.ISOTaggedField)4 ArrayList (java.util.ArrayList)3