Search in sources :

Example 16 with ISOBaseValidator

use of org.jpos.iso.ISOBaseValidator 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);
}
Also used : ISOMsg(org.jpos.iso.ISOMsg) ISOValidator(org.jpos.iso.ISOValidator) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOVMsg(org.jpos.iso.ISOVMsg) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) MSGTEST02(org.jpos.iso.validator.MSGTEST02) Test(org.junit.Test)

Example 17 with ISOBaseValidator

use of org.jpos.iso.ISOBaseValidator 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);
    }
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) LogEvent(org.jpos.util.LogEvent) ISOVException(org.jpos.iso.validator.ISOVException) ISOValidator(org.jpos.iso.ISOValidator) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator)

Example 18 with ISOBaseValidator

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

the class GenericValidatingPackagerTest method testValidateThrowsNullPointerException.

@Test
public void testValidateThrowsNullPointerException() throws Throwable {
    GenericValidatingPackager genericValidatingPackager = new GenericValidatingPackager();
    ISOFieldValidator[] fvlds = new ISOFieldValidator[0];
    genericValidatingPackager.setFieldValidator(fvlds);
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[2];
    msgVlds[0] = new ISOBaseValidator();
    msgVlds[1] = new MSGTEST02();
    genericValidatingPackager.setMsgValidator(msgVlds);
    try {
        genericValidatingPackager.validate(new ISOMsg());
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        assertNull("ex.getMessage()", ex.getMessage());
    }
}
Also used : ISOMsg(org.jpos.iso.ISOMsg) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) MSGTEST02(org.jpos.iso.validator.MSGTEST02) Test(org.junit.Test)

Example 19 with ISOBaseValidator

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

the class GenericValidatingPackagerTest method testValidateThrowsISOVException.

@Test
public void testValidateThrowsISOVException() throws Throwable {
    GenericValidatingPackager genericValidatingPackager = new GenericValidatingPackager();
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
    msgVlds[0] = new MSGTEST(false);
    msgVlds[1] = new MSGTEST(true);
    genericValidatingPackager.setMsgValidator(msgVlds);
    ISOFieldValidator[] fvlds = new ISOFieldValidator[1];
    fvlds[0] = new IVA_ALPHANUM("testGenericValidatingPackagerDescription");
    genericValidatingPackager.setFieldValidator(fvlds);
    try {
        genericValidatingPackager.validate(new ISOMsg(100));
        fail("Expected ISOVException to be thrown");
    } catch (ISOVException ex) {
        assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
        assertFalse("ex.treated()", ex.treated());
        assertNotNull("ex.getErrComponent()", ex.getErrComponent());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : MSGTEST(org.jpos.iso.validator.MSGTEST) ISOMsg(org.jpos.iso.ISOMsg) IVA_ALPHANUM(org.jpos.iso.IVA_ALPHANUM) ISOVException(org.jpos.iso.validator.ISOVException) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Example 20 with ISOBaseValidator

use of org.jpos.iso.ISOBaseValidator 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);
}
Also used : MSGTEST(org.jpos.iso.validator.MSGTEST) ISOMsg(org.jpos.iso.ISOMsg) ISOValidator(org.jpos.iso.ISOValidator) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) TEST0100(org.jpos.iso.validator.TEST0100) ISOVMsg(org.jpos.iso.ISOVMsg) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Aggregations

ISOBaseValidator (org.jpos.iso.ISOBaseValidator)32 Test (org.junit.Test)31 ISOMsg (org.jpos.iso.ISOMsg)30 ISOFieldValidator (org.jpos.iso.ISOFieldValidator)22 ISOValidator (org.jpos.iso.ISOValidator)18 TEST0100 (org.jpos.iso.validator.TEST0100)12 MSGTEST (org.jpos.iso.validator.MSGTEST)9 MSGTEST02 (org.jpos.iso.validator.MSGTEST02)9 ISOException (org.jpos.iso.ISOException)8 ISOVMsg (org.jpos.iso.ISOVMsg)8 IVA_ALPHANUMNOBLANK (org.jpos.iso.IVA_ALPHANUMNOBLANK)7 ISOComponent (org.jpos.iso.ISOComponent)5 IVA_ALPHANUM (org.jpos.iso.IVA_ALPHANUM)5 ISOVException (org.jpos.iso.validator.ISOVException)3 ISOVError (org.jpos.iso.ISOVError)2 IVA_ALPHANUMNOZERO_NOBLANK (org.jpos.iso.IVA_ALPHANUMNOZERO_NOBLANK)2 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 LogEvent (org.jpos.util.LogEvent)1