Search in sources :

Example 11 with ISOFieldValidator

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

the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException2.

@Test
public void testValidateThrowsISOException2() throws Throwable {
    ISOFieldValidator iVA_ALPHANUMNOBLANK = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
    msgVlds[0] = new MSGTEST(false);
    msgVlds[1] = new MSGTEST();
    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());
    }
}
Also used : IVA_ALPHANUMNOBLANK(org.jpos.iso.IVA_ALPHANUMNOBLANK) MSGTEST(org.jpos.iso.validator.MSGTEST) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) TEST0100(org.jpos.iso.validator.TEST0100) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Example 12 with ISOFieldValidator

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

Example 13 with ISOFieldValidator

use of org.jpos.iso.ISOFieldValidator 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 14 with ISOFieldValidator

use of org.jpos.iso.ISOFieldValidator 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 15 with ISOFieldValidator

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

the class QFactory2Test method testSetConfiguration1.

@Test
public void testSetConfiguration1() throws Throwable {
    String[] args = new String[0];
    ISOFieldValidator obj = new ISOFieldValidator(true);
    new QFactory(new ObjectName(""), new Q2(args)).setConfiguration(obj, new Element("testQFactoryName"));
    assertFalse("obj.breakOnError()", obj.breakOnError());
}
Also used : Element(org.jdom2.Element) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

ISOFieldValidator (org.jpos.iso.ISOFieldValidator)26 Test (org.junit.Test)25 ISOBaseValidator (org.jpos.iso.ISOBaseValidator)22 ISOMsg (org.jpos.iso.ISOMsg)21 ISOValidator (org.jpos.iso.ISOValidator)9 IVA_ALPHANUMNOBLANK (org.jpos.iso.IVA_ALPHANUMNOBLANK)9 MSGTEST (org.jpos.iso.validator.MSGTEST)8 ISOVMsg (org.jpos.iso.ISOVMsg)7 TEST0100 (org.jpos.iso.validator.TEST0100)7 ISOException (org.jpos.iso.ISOException)6 MSGTEST02 (org.jpos.iso.validator.MSGTEST02)6 IVA_ALPHANUM (org.jpos.iso.IVA_ALPHANUM)5 Hashtable (java.util.Hashtable)3 ISOComponent (org.jpos.iso.ISOComponent)3 ISOVException (org.jpos.iso.validator.ISOVException)3 Properties (java.util.Properties)1 ObjectName (javax.management.ObjectName)1 Element (org.jdom2.Element)1 ISOVError (org.jpos.iso.ISOVError)1 IVA_ALPHANUMNOZERO_NOBLANK (org.jpos.iso.IVA_ALPHANUMNOZERO_NOBLANK)1