Java tutorial
/* * Copyright (c) 2007 NTT DATA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jp.terasoluna.fw.web.struts.form; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import jp.terasoluna.utlib.LogUTUtil; import jp.terasoluna.utlib.MockHttpServletRequest; import jp.terasoluna.utlib.PropertyTestCase; import org.apache.commons.validator.Field; import org.apache.commons.validator.Msg; import org.apache.commons.validator.Validator; import org.apache.commons.validator.ValidatorAction; import org.apache.commons.validator.ValidatorResources; import org.apache.commons.validator.Var; import org.apache.struts.Globals; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; /** * {@link jp.terasoluna.fw.web.struts.form.FieldChecksEx} * NXubN{bNXeXg?B * * <p> * <h4>?yNXTv?z</h4> * Validator?[NX?B * <p> * * @see jp.terasoluna.fw.web.struts.form.FieldChecksEx */ public class FieldChecksExTest05 extends PropertyTestCase { /** * eXgP?[X?s * GUI AvP?[VN?B * * @param args java R}h?p??[^ */ public static void main(String[] args) { junit.swingui.TestRunner.run(FieldChecksExTest05.class); } /** * ????s?B * * @throws Exception ?\bh?O * @see jp.terasoluna.utlib.spring.PropertyTestCase#setUpData() */ @Override protected void setUpData() throws Exception { LogUTUtil.flush(); deleteProperty("validation.hankaku.kana.list"); deleteProperty("validation.zenkaku.kana.list"); } /** * ?I???s?B * * @throws Exception ?\bh?O * @see jp.terasoluna.utlib.spring.PropertyTestCase#cleanUpData() */ @Override protected void cleanUpData() throws Exception { } /** * RXgN^?B * * @param name eXgP?[XO?B */ public FieldChecksExTest05(String name) { super(name); } /** * testValidateStringLength01() * <br><br> * * (??n) * <br> * _?FC,F * <br><br> * l?F(?) bean:null<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength=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> * (?) ?O:?Ox?F<br> * G?[<br> * ?bZ?[W?F<br> * bean is null.<br> * (?) errors:not null<br> * (vf)<br> * * <br> * ?beannull?AG?[?O?otruep * mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateStringLength01() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = null; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("stringLength"); var.setValue(null); 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.validateStringLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // G?[?OmF assertTrue(LogUTUtil.checkError("bean is null.")); } /** * testValidateStringLength02() * <br><br> * * (??n) * <br> * _?FC,F * <br><br> * l?F(?) bean:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength="4"<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 testValidateStringLength02() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??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 var = new Var(); var.setName("stringLength"); var.setValue("4"); 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()); } /** * testValidateStringLength03() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"abc0#"<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength=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> * fieldstringLengthlnull?AtruemF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateStringLength03() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc0#"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("stringLength"); var.setValue(null); 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.validateStringLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateStringLength04() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"abc0#"<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength=""<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> * fieldstringLengthl?AtruemF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateStringLength04() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc0#"; // ++++ ??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 var = new Var(); var.setName("stringLength"); var.setValue(""); 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()); } /** * testValidateStringLength05() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"abc0#"<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength="A"<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> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F<br> * "stringLength is not numeric(integer)."<br> * O?FNumberFormatException<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldstringLengthl?l?Atrue * mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateStringLength05() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc0#"; // ++++ ??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 var = new Var(); var.setName("stringLength"); var.setValue("A"); 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()); // G?[?OmF assertTrue(LogUTUtil.checkError("stringLength is not numeric(integer).", new NumberFormatException())); } /** * testValidateStringLength06() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"abc"<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength="4"<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> * fieldstringLengthwl?A?bean?v???A * truepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateStringLength06() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc"; // ++++ ??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 var = new Var(); var.setName("stringLength"); var.setValue("4"); 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()); } /** * testValidateStringLength07() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"abc0#"<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength="4"<br> * Msg("message","message")<br> * (?) errors:not null<br> * ActionMessage("testMessage")<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(l) boolean:false<br> * (?) errors:ActionMessage("testMessage")<br> * ActionMessage("message")<br> * * <br> * fieldstringLengthwl?A?bean?v???A * falsepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateStringLength07() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc0#"; // ++++ ??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 var = new Var(); var.setName("stringLength"); var.setValue("4"); field.addVar(var); // G?[??iActionMessage1???j ActionMessages errors = new ActionMessages(); ActionMessage error = new ActionMessage("testMessage"); errors.add(Globals.ERROR_KEY, error); // [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 // falsep?B assertFalse(result); // G?[?G?[IuWFNg2o^?B assertEquals(2, errors.size()); // G?[???bZ?[Wo^?B // ActionMessage???B Iterator it = errors.get(); List<String> list = new ArrayList<String>(); while (it.hasNext()) { ActionMessage retError = (ActionMessage) it.next(); list.add(retError.getKey()); } assertTrue(list.contains("testMessage")); assertTrue(list.contains("message")); } /** * testValidateStringLength08() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"="a 1 "]<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength="5"<br> * Msg("message","message")<br> * property?="field1"<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 * `FbN?smF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateStringLength08() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ Map<String, String> bean = new HashMap<String, String>(); bean.put("field1", "a 1 "); // ++++ ??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); 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()); } /** * testValidateStringLength09() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"="1234"]<br> * (?) va:not null<br> * (?) field:not null<br> * var:stringLength="5"<br> * Msg("message","message")<br> * property?="field1"<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 testValidateStringLength09() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ Map<String, String> bean = new HashMap<String, String>(); bean.put("field1", "1234"); // ++++ ??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); 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 // falsep?B assertFalse(result); // G?[?G?[IuWFNgo^?B assertEquals(1, errors.size()); // G?[???bZ?[Wo^?B Iterator it = errors.get(); ActionMessage error = (ActionMessage) it.next(); assertEquals("message", error.getKey()); } /** * testValidateStringLength10() * <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()); } /** * testValidateByteLength01() * <br><br> * * (??n) * <br> * _?FC,F * <br><br> * l?F(?) bean:null<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength=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> * (?) ?O:?Ox?F<br> * G?[<br> * ?bZ?[W?F<br> * bean is null.<br> * (?) errors:not null<br> * (vf)<br> * * <br> * ?beannull?AG?[?O?otruep * mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength01() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = null; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue(null); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // G?[?OmF assertTrue(LogUTUtil.checkError("bean is null.")); } /** * testValidateByteLength02() * <br><br> * * (??n) * <br> * _?FC,F * <br><br> * l?F(?) bean:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="4"<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 testValidateByteLength02() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue("4"); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteLength03() * <br><br> * * (?n) * <br> * _?FC,F * <br><br> * l?F(?) bean:String:"abc0#"<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength=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> * (?) ?O:?Ox?F?<br> * ?bZ?[W?F<br> * "length is not specified."<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldbyteLengthlnull?AtruemF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength03() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc0#"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue(null); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // ??O`FbN assertTrue(LogUTUtil.checkInfo("length is not specified.")); } /** * testValidateByteLength04() * <br><br> * * (?n) * <br> * _?FC,F * <br><br> * l?F(?) bean:String:"abc0#"<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength=""<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> * (?) ?O:?Ox?F?<br> * ?bZ?[W?F<br> * "length is not specified."<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldbyteLengthl?AtruemF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength04() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc0#"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue(""); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // ??O`FbN assertTrue(LogUTUtil.checkInfo("length is not specified.")); } /** * testValidateByteLength05() * <br><br> * * (?n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"abc0#"<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="A"<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> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F<br> * "byteLength is not numeric(integer)."<br> * O?FNumberFormatException<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldbyteLengthl?l?A * truemF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength05() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc0#"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // ??O`FbN assertTrue(LogUTUtil.checkError("byteLength is not numeric(integer).", new NumberFormatException())); } /** * testValidateByteLength06() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="3"<br> * encoding="UTF-8"<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> * fieldbyteLengthwl?A?beanoCg?v???A * truepmF?B<br> * ?getByteLength?\bheXg?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength06() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue("3"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue("UTF-8"); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteLength07() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="3"<br> * encoding="Windows-31J"<br> * Msg("message","message")<br> * (?) errors:not null<br> * ActionMessage("testMessage")<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(l) boolean:false<br> * (?) errors:ActionMessage("testMessage")<br> * ActionMessage("message")<br> * * <br> * fieldbyteLengthwl?A?bean?v???A * falsepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength07() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue("3"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue("Windows-31J"); field.addVar(var); // ?bZ?[W? Msg msg = new Msg(); msg.setKey("message"); msg.setName("message"); msg.setResource(false); field.addMsg(msg); // G?[??iActionMessage1???j ActionMessages errors = new ActionMessages(); ActionMessage error = new ActionMessage("testMessage"); errors.add(Globals.ERROR_KEY, error); // [HTTPNGXg MockHttpServletRequest request = new MockHttpServletRequest(); // ValidatorResourcesCX^X ValidatorResources validatorResources = new ValidatorResources(); // ValidatorCX^X Validator validator = new Validator(validatorResources); // eXg?s boolean result = FieldChecksEx.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // falsep?B assertFalse(result); // G?[?1??B assertEquals(2, errors.size()); // ?bZ?[WIuWFNg? Iterator it = errors.get(); List<String> list = new ArrayList<String>(); while (it.hasNext()) { ActionMessage retError = (ActionMessage) it.next(); list.add(retError.getKey()); } assertTrue(list.contains("testMessage")); assertTrue(list.contains("message")); } /** * testValidateByteLength08() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="2"<br> * encoding=null<br> * Msg("message","message")<br> * (?) errors:not null<br> * ActionMessage("testMessage")<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(l) boolean:true<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldencodingnull???AVMftHgGR?[fBO * oCg?vZmF?B<br> * ?getByteLength?\bheXg?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength08() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue("2"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue(null); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteLength09() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="2"<br> * encoding=""<br> * Msg("message","message")<br> * (?) errors:not null<br> * ActionMessage("testMessage")<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(l) boolean:true<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldencoding???AVMftHgGR?[fBO * oCg?vZmF?B<br> * ?getByteLength?\bheXg?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength09() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue("2"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue(""); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteLength10() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="2"<br> * encoding="test-encoding"<br> * Msg("message","message")<br> * (?) errors:not null<br> * ActionMessage("testMessage")<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(l) boolean:true<br> * (?) ?O:?Ox?Fx??<br> * ?bZ?[W?F<br> * "test-encoding is not supported."<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldencodingT|?[gGR?[fBO???A * VMftHgGR?[fBOoCg?vZmF?B<br> * ?getByteLength?\bheXg?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength10() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("byteLength"); var.setValue("2"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue("test-encoding"); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // x???O`FbN assertTrue(LogUTUtil.checkWarn("test-encoding is not supported.")); } /** * testValidateByteLength11() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"=""]<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="9"<br> * var:encoding="UTF-8"<br> * Msg("message","message")<br> * property?="field1"<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 * `FbN?smF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteLength11() 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"); Var var = new Var(); var.setName("byteLength"); var.setValue("9"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue("UTF-8"); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteLength12() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"="1234"]<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="5"<br> * encoding="Windows-31J"<br> * Msg("message","message")<br> * property?="field1"<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 testValidateByteLength12() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ Map<String, String> bean = new HashMap<String, String>(); bean.put("field1", "1234"); // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); field.setProperty("field1"); Var var = new Var(); var.setName("byteLength"); var.setValue("5"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue("Windows-31J"); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // falsep?B assertFalse(result); // G?[?1??B assertEquals(1, errors.size()); // ?bZ?[WIuWFNg? Iterator it = errors.get(); ActionMessage message = (ActionMessage) it.next(); assertEquals("message", message.getKey()); } /** * testValidateByteLength13() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"="123"]<br> * (?) va:not null<br> * (?) field:not null<br> * var:byteLength="5"<br> * encoding="UTF-8"<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 testValidateByteLength13() 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"); Var var = new Var(); var.setName("byteLength"); var.setValue("5"); field.addVar(var); // GR?[fBO? var = new Var(); var.setName("encoding"); var.setValue("UTF-8"); 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.validateByteLength(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } }