use of org.jpos.iso.ISOValidator in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidate9.
@Test
public void testValidate9() throws Throwable {
ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
ISOValidator[] fvlds = new ISOValidator[2];
fvlds[0] = new ISOFieldValidator(100, 1000, "testISOBaseValidatingPackagerDescription");
fvlds[1] = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
iSOBaseValidatingPackager.setFieldValidator(fvlds);
ISOBaseValidator[] msgVlds = new ISOBaseValidator[2];
msgVlds[0] = new ISOBaseValidator(true);
iSOBaseValidatingPackager.setMsgValidator(msgVlds);
ISOMsg result = (ISOMsg) iSOBaseValidatingPackager.validate(new ISOMsg(100));
assertEquals("result.getDirection()", 0, result.getDirection());
}
use of org.jpos.iso.ISOValidator in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidate13.
@Test
public void testValidate13() throws Throwable {
ISOBaseValidator[] msgVlds = new ISOBaseValidator[1];
msgVlds[0] = new MSGTEST02();
ISOValidator[] fvlds = new ISOFieldValidator[1];
ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
iSOBaseValidatingPackager.setFieldValidator(fvlds);
iSOBaseValidatingPackager.setMsgValidator(msgVlds);
ISOVMsg result = (ISOVMsg) iSOBaseValidatingPackager.validate(new ISOMsg("testISOBaseValidatingPackagerMti"));
assertNotNull("result", result);
}
use of org.jpos.iso.ISOValidator in project jPOS by jpos.
the class GenericValidatingPackager method validate.
public ISOComponent validate(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "validate");
try {
ISOComponent c;
Map<Object, ISOComponent> fields = m.getChildren();
/**
* Field validations *
*/
for (ISOValidator val : fvlds) {
if ((c = fields.get(((ISOFieldValidator) val).getFieldId())) != null) {
try {
m.set(val.validate(c));
} catch (ISOVException e) {
if (!e.treated()) {
m.set(e.getErrComponent());
e.setTreated(true);
}
evt.addMessage("Component Validation Error.");
throw e;
}
}
}
/**
* msg validations *
*/
try {
for (ISOBaseValidator mval : mvlds) m = mval.validate(m);
} catch (ISOVException ex) {
evt.addMessage("Component Validation Error.");
throw ex;
}
return m;
} finally {
Logger.log(evt);
}
}
use of org.jpos.iso.ISOValidator in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidate18.
@Test
public void testValidate18() throws Throwable {
ISOBaseValidator[] msgVlds = new ISOBaseValidator[2];
msgVlds[0] = new TEST0100(true);
msgVlds[1] = new MSGTEST();
ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
iSOBaseValidatingPackager.setMsgValidator(msgVlds);
ISOValidator[] fvlds = new ISOValidator[5];
fvlds[1] = new ISOFieldValidator();
iSOBaseValidatingPackager.setFieldValidator(fvlds);
ISOVMsg result = (ISOVMsg) iSOBaseValidatingPackager.validate(new ISOMsg("testISOBaseValidatingPackagerMti"));
assertNotNull("result", result);
}
use of org.jpos.iso.ISOValidator 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());
}
}
Aggregations