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;
}
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());
}
}
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);
}
}
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());
}
}
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());
}
}
Aggregations