use of org.jpos.iso.ISOException in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException4.
@Test
public void testValidateThrowsISOException4() throws Throwable {
ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
msgVlds[0] = new MSGTEST(false);
msgVlds[1] = new MSGTEST();
msgVlds[2] = new TEST0100(true);
ISOValidator[] fvlds = new ISOFieldValidator[3];
ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
iSOBaseValidatingPackager.setFieldValidator(fvlds);
iSOBaseValidatingPackager.setMsgValidator(msgVlds);
try {
iSOBaseValidatingPackager.validate(new ISOMsg());
fail("Expected ISOException to be thrown");
} catch (ISOException ex) {
assertEquals("ex.getMessage()", "MTI not available", ex.getMessage());
assertNull("ex.getNested()", ex.getNested());
}
}
use of org.jpos.iso.ISOException in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException6.
@Test
public void testValidateThrowsISOException6() throws Throwable {
ISOFieldValidator iVA_ALPHANUMNOBLANK = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
msgVlds[0] = new MSGTEST(true);
ISOFieldValidator[] fvlds = new ISOFieldValidator[3];
fvlds[0] = iVA_ALPHANUMNOBLANK;
ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
iSOBaseValidatingPackager.setFieldValidator(fvlds);
iSOBaseValidatingPackager.setMsgValidator(msgVlds);
try {
iSOBaseValidatingPackager.validate(new ISOMsg());
fail("Expected ISOException to be thrown");
} catch (ISOException ex) {
assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
assertFalse("ex.treated()", ((ISOVException) ex).treated());
assertNotNull("ex.getErrComponent()", ((ISOVException) ex).getErrComponent());
assertNull("ex.getNested()", ex.getNested());
}
}
use of org.jpos.iso.ISOException in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException3.
@Test
public void testValidateThrowsISOException3() throws Throwable {
ISOFieldValidator iVA_ALPHANUMNOBLANK = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
msgVlds[2] = new TEST0100(true);
ISOFieldValidator[] fvlds = new ISOFieldValidator[3];
fvlds[0] = iVA_ALPHANUMNOBLANK;
ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
iSOBaseValidatingPackager.setFieldValidator(fvlds);
iSOBaseValidatingPackager.setMsgValidator(msgVlds);
try {
iSOBaseValidatingPackager.validate(new ISOMsg());
fail("Expected ISOException to be thrown");
} catch (ISOException ex) {
assertEquals("ex.getMessage()", "MTI not available", ex.getMessage());
assertNull("ex.getNested()", ex.getNested());
}
}
use of org.jpos.iso.ISOException in project jPOS by jpos.
the class TLVList method getTLVMsg.
/**
* Read next TLV Message from stream and return it
* @param buffer the buffer
* @return TLVMsg
*/
private TLVMsg getTLVMsg(ByteBuffer buffer) throws ISOException {
// tag = 0 if tag not found
int tag = getTAG(buffer);
if (tag == 0)
return null;
// Get Length if buffer remains!
if (!buffer.hasRemaining())
throw new ISOException(String.format("BAD TLV FORMAT - tag (%x)" + " without length or value", tag));
int length = getValueLength(buffer);
if (length > buffer.remaining())
throw new ISOException(String.format("BAD TLV FORMAT - tag (%x)" + " length (%d) exceeds available data.", tag, length));
byte[] arrValue = new byte[length];
buffer.get(arrValue);
return getTLVMsg(tag, arrValue);
}
use of org.jpos.iso.ISOException 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");
}
}
}
}
Aggregations