Example usage for org.apache.commons.validator ValidatorAction ValidatorAction

List of usage examples for org.apache.commons.validator ValidatorAction ValidatorAction

Introduction

In this page you can find the example usage for org.apache.commons.validator ValidatorAction ValidatorAction.

Prototype

ValidatorAction

Source Link

Usage

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest09.java

/**
 * testValidateDateRange08()/*  ww w.j  a  v a 2  s.  c  om*/
 * <br><br>
 *
 * (??n)
 * <br>
 * _?FF
 * <br><br>
 * l?F(?) bean:"2005/2/28"<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                var:datePattern=null<br>
 *                var:datePatternStrict="yyyy/MM/dd"<br>
 *                Msg("message","message")<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *                Locale=JAPANESE<br>
 *
 * <br>
 * l?F(l) boolean:false<br>
 *         (?) errors:ActionMessage("message")<br>
 *
 * <br>
 * ?bean??t\?AdatePatternw?A
 * datePatternStrictwttH?[}bgbeantH?[}bg
 * Sv???AG?[?bZ?[Wfalsep
 * mF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateDateRange08() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    String bean = "2005/2/28";
    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    va.setName("message");
    // ++++ ?tB?[h?
    Field field = new Field();
    Var var = new Var();
    var.setName("datePattern");
    var.setValue(null);
    field.addVar(var);
    var = new Var();
    var.setName("datePatternStrict");
    var.setValue("yyyy/MM/dd");
    field.addVar(var);
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);
    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setLocale(Locale.JAPANESE);
    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    boolean result = FieldChecksEx.validateDateRange(bean, va, field, errors, validator, request);
    // eXgmF
    // falsep?B
    assertFalse(result);
    // G?[?1??B
    assertEquals(1, errors.size());

    // ?bZ?[WIuWFNgmF
    Iterator it = errors.get();
    ActionMessage message = (ActionMessage) it.next();
    assertEquals("message", message.getKey());
}

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest02.java

/**
 * testValidateHankakuKanaString06()//  ww w.j  a va 2  s .c o  m
 * <br><br>
 *
 * (??n)
 * <br>
 * _?FF
 * <br><br>
 * l?F(?) bean:Map:["field1"=""]<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                property="field1"<br>
 *                Msg("message","message")<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *
 * <br>
 * l?F(l) boolean:true<br>
 *         (?) errors:not null<br>
 *                    (vf)<br>
 *
 * <br>
 * ?beanString^???A
 * fieldOv?peB`FbN?smF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateHankakuKanaString06() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    Map<String, String> bean = new HashMap<String, String>();
    bean.put("field1", "");

    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    va.setName("message");
    // ++++ ?tB?[h?
    Field field = new Field();
    field.setProperty("field1");
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);

    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();
    Validator validator = new Validator(new ValidatorResources());

    // eXg?s
    boolean result = FieldChecksEx.validateHankakuKanaString(bean, va, field, errors, validator, request);
    // eXgmF
    // truep?B
    assertTrue(result);
    // G?[?G?[IuWFNgo^?B
    assertTrue(errors.isEmpty());
}

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest04.java

/**
 * testValidateProhibited02()/*from   w w w .j ava 2s  . c o  m*/
 * <br><br>
 *
 * (??n)
 * <br>
 * _?FC,F
 * <br><br>
 * l?F(?) bean:""<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                var:chars=null<br>
 *                Msg("message","message")<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *
 * <br>
 * l?F(l) boolean:true<br>
 *         (?) errors:not null<br>
 *                    (vf)<br>
 *
 * <br>
 * ?bean?AtruepmF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateProhibited02() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    String bean = "";
    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    // ++++ ?tB?[h?
    Field field = new Field();
    Var var = new Var();
    var.setName("chars");
    var.setValue("a");
    field.addVar(var);
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);
    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();
    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    boolean result = FieldChecksEx.validateProhibited(bean, va, field, errors, validator, request);
    // eXgmF
    // truep?B
    assertTrue(result);
    // G?[??B
    assertTrue(errors.isEmpty());
}

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest07.java

/**
 * testValidateNumber09()//from  w ww. j a  v a  2  s  .c o  m
 * <br><br>
 *
 * (?n)
 * <br>
 * _?FC,F
 * <br><br>
 * l?F(?) bean:String:"123.12"<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                var:integerLength=null<br>
 *                var:scale="3"<br>
 *                var:isAccordedScale=""<br>
 *                Msg("message","message")<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *
 * <br>
 * l?F(l) boolean:true<br>
 *         (?) errors:not null<br>
 *                    (vf)<br>
 *
 * <br>
 * scale?l?AisAccordedScalew?A
 * scale?l?Abean??_??A
 * truep?AG?[?bZ?[WmF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateNumber09() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    String bean = "123.12";
    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    va.setName("message");
    // ++++ ?tB?[h?
    Field field = new Field();
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);
    // ???
    Var varInteger = new Var();
    varInteger.setName("integerLength");
    varInteger.setValue(null);
    field.addVar(varInteger);
    // ???
    Var varScale = new Var();
    varScale.setName("scale");
    varScale.setValue("3");
    field.addVar(varScale);
    // ???vw
    Var varAccorded = new Var();
    varAccorded.setName("isAccordedScale");
    varAccorded.setValue("");
    field.addVar(varAccorded);

    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();

    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    boolean result = FieldChecksEx.validateNumber(bean, va, field, errors, validator, request);

    // eXgmF
    // truep?B
    assertTrue(result);
    // G?[?G?[IuWFNgo^?B
    assertTrue(errors.isEmpty());
}

From source file:jp.terasoluna.fw.validation.FieldChecksTest07.java

/**
 * testValidateProhibited02() <br>
 * <br>/*from www.j av a  2  s  .  co  m*/
 * () <br>
 * A <br>
 * <br>
 * () bean:""<br>
 * () va:not null<br>
 * () field:not null<br>
 * () errors:not null<br>
 * <br>
 * () boolean:true<br>
 * () errors:????<br>
 * <br>
 * ?bean????true??????? <br>
 * @throws Exception ?????
 */
@Test
public void testValidateProhibited02() throws Exception {
    // ??
    // bean : ""
    Object bean = "";
    // va : not null
    ValidatorAction va = new ValidatorAction();
    // field : not null
    Field field = new Field();
    // errors : not null
    FieldChecks_ValidationErrorsImpl01 errors = new FieldChecks_ValidationErrorsImpl01();

    // 
    boolean b = new FieldChecks().validateProhibited(bean, va, field, errors);

    // 
    assertTrue(b);
    assertEquals(0, errors.addErrorCount);
}

From source file:jp.terasoluna.fw.validation.FieldChecksTest06.java

/**
 * testValidateNumber08() <br>/*w w  w.j av  a  2s .  c  o m*/
 * <br>
 * () <br>
 * A <br>
 * <br>
 * () bean:"100.05"<br>
 * () va:not null<br>
 * () field:var:<br>
 * integerLength="3"<br>
 * scale="2"<br>
 * isAccordedInteger="true"<br>
 * isAccordedScale="true"<br>
 * () errors:not null<br>
 * <br>
 * () boolean:true<br>
 * () errors:????<br>
 * <br>
 * var?isAccordedInteger?true?????????????var?integerLength??????var?isAccordedScale?true??????
 * ????var?scale??????true??????? <br>
 * @throws Exception ?????
 */
@Test
public void testValidateNumber08() throws Exception {
    // ??
    // bean : "100.05"
    Object bean = "100.05";
    // va : not null
    ValidatorAction va = new ValidatorAction();
    // field : var:integerLength="3" scale="2" isAccordedInteger="true" isAccordedScale="true"
    Field field = new Field();
    Var var1 = new Var();
    var1.setName("integerLength");
    var1.setValue("3");
    field.addVar(var1);

    Var var2 = new Var();
    var2.setName("scale");
    var2.setValue("2");
    field.addVar(var2);

    Var var3 = new Var();
    var3.setName("isAccordedInteger");
    var3.setValue("true");
    field.addVar(var3);

    Var var4 = new Var();
    var4.setName("isAccordedScale");
    var4.setValue("true");
    field.addVar(var4);

    // errors : not null
    FieldChecks_ValidationErrorsImpl01 errors = new FieldChecks_ValidationErrorsImpl01();

    // 
    boolean b = new FieldChecks().validateNumber(bean, va, field, errors);

    // 
    assertTrue(b);
    assertEquals(0, errors.addErrorCount);
}

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest03.java

/**
 * testValidateZenkakuString03()/*  w  w w  .  j a  v  a2  s  .  c o m*/
 * <br><br>
 *
 * (??n)
 * <br>
 * _?FF
 * <br><br>
 * l?F(?) bean:String:"SpA"<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                Msg("message","message")<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *
 * <br>
 * l?F(l) boolean:true<br>
 *         (?) errors:not null<br>
 *                    (vf)<br>
 *
 * <br>
 * ?beanSp?\??A
 * truepmF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateZenkakuString03() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    String bean = "SpA";
    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    va.setName("message");
    // ++++ ?tB?[h?
    Field field = new Field();
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);

    // G?[?
    ActionMessages errors = new ActionMessages();

    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();
    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    boolean result = FieldChecksEx.validateZenkakuString(bean, va, field, errors, validator, request);
    // eXgmF
    // truep?B
    assertTrue(result);
    // G?[?G?[IuWFNgo^?B
    assertTrue(errors.isEmpty());
}

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest05.java

/**
 * testValidateStringLength10()//from  w  w w  .jav a  2 s.c  o  m
 * <br><br>
 *
 * (??n)
 * <br>
 * _?FF
 * <br><br>
 * l?F(?) bean:Map:["field1"="123"]<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                var:stringLength="5"<br>
 *                Msg("message","message")<br>
 *                property?="field2"<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *
 * <br>
 * l?F(l) boolean:true<br>
 *         (?) errors:not null<br>
 *                    (vf)<br>
 *
 * <br>
 * ?beanString^?AfieldOv?peB
 * ????AtruemF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateStringLength10() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    Map<String, String> bean = new HashMap<String, String>();
    bean.put("field1", "123");

    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    va.setName("message");
    // ++++ ?tB?[h?
    Field field = new Field();
    field.setProperty("field2");
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);
    Var var = new Var();
    var.setName("stringLength");
    var.setValue("5");
    field.addVar(var);

    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();
    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    boolean result = FieldChecksEx.validateStringLength(bean, va, field, errors, validator, request);
    // eXgmF
    // truep?B
    assertTrue(result);
    // G?[??B
    assertTrue(errors.isEmpty());
}

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest06.java

/**
 * testValidateArraysIndex09()//from  www  . j  a  va2s.c  o  m
 * <br><br>
 *
 * (?n)
 * <br>
 * _?FF
 * <br><br>
 * l?F(?) bean:*<br>
 *         (?) va:methodParams?F6??<br>
 *                name?F"stringLengthArray"<br>
 *         (?) field:not null<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *         (?) session:not null<br>
 *         (?) ActionForm:not null<br>
 *
 * <br>
 * l?F(l) boolean:true<br>
 *         (?) ?O:?Ox?FG?[<br>
 *                    ONX?F<br>
 *                    NoSuchMethodException<br>
 *                    ?Ox?FG?[<br>
 *                    ?bZ?[W?F<br>
 *                    "Can not get validateMethod."<br>
 *         (?) errors:not null<br>
 *                    (vf)<br>
 *
 * <br>
 * va?`FbN?\bh??A
 * methodParamsw?v???A
 * truemF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateArraysIndex09() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    String bean = null;

    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    String argStr = "javax.servlet.http.HttpServletRequest," + "org.apache.commons.validator.ValidatorAction,"
            + "org.apache.commons.validator.Field," + "org.apache.struts.action.ActionMessages,"
            + "org.apache.commons.validator.Validator," + "java.lang.Object";
    va.setMethodParams(argStr);
    va.setName("stringLengthArray");

    // ++++ ?tB?[h?
    Field field = new Field();

    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    HttpServletRequest request = new MockHttpServletRequest();

    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    boolean result = FieldChecksEx.validateArraysIndex(bean, va, field, errors, validator, request);
    // eXgmF
    // truep?B
    assertTrue(result);
    // G?[??B
    assertTrue(errors.isEmpty());

    // G?[?O`FbN
    assertTrue(LogUTUtil.checkError("", new NoSuchMethodException()));
    assertTrue(LogUTUtil.checkError("Can not get validateMethod."));
}

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest02.java

/**
 * testValidateHankakuKanaString07()/*from   w  ww . j av a 2s .c om*/
 * <br><br>
 *
 * (??n)
 * <br>
 * _?FF
 * <br><br>
 * l?F(?) bean:Map:["field1"="123"]<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                property="field1"<br>
 *                Msg("message","message")<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *
 * <br>
 * l?F(l) boolean:false<br>
 *         (?) errors:ActionMessage("message")<br>
 *
 * <br>
 * ?beanString^???AfieldOv?peB
 * `FbN?smF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateHankakuKanaString07() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    Map<String, String> bean = new HashMap<String, String>();
    bean.put("field1", "123");

    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    va.setName("message");
    // ++++ ?tB?[h?
    Field field = new Field();
    field.setProperty("field1");
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);

    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();
    Validator validator = new Validator(new ValidatorResources());

    // eXg?s
    boolean result = FieldChecksEx.validateHankakuKanaString(bean, va, field, errors, validator, request);
    // eXgmF
    // falsep?B
    assertFalse(result);
    // G?[?G?[IuWFNgo^?B
    assertFalse(errors.isEmpty());
    // G?[???bZ?[Wo^?B
    Iterator it = errors.get();
    ActionMessage error = (ActionMessage) it.next();
    assertEquals("message", error.getKey());
    // G?[1?
    assertFalse(it.hasNext());
}