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.fw.util.ClassLoadException; 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 FieldChecksExTest08 extends PropertyTestCase { /** * validateMultiField?gpBean?B */ FieldChecksEx_BeanStub01 javaBean = new FieldChecksEx_BeanStub01(); /** * eXgP?[X?s * GUI AvP?[VN?B * * @param args java R}h?p??[^ */ public static void main(String[] args) { junit.swingui.TestRunner.run(FieldChecksExTest08.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"); FieldChecksEx_MultiFieldValidatorImpl01.value = null; FieldChecksEx_MultiFieldValidatorImpl01.fields = null; FieldChecksEx_MultiFieldValidatorImpl01.validateCalledCount = 0; FieldChecksEx_MultiFieldValidatorImpl01.result = false; } /** * ?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 FieldChecksExTest08(String name) { super(name); this.javaBean.setField1("abc"); this.javaBean.setField2("def"); this.javaBean.setField3("ghi"); this.javaBean.setField4("jkl"); } /** * testValidateByteRange01() * <br><br> * * (??n) * <br> * _?FC,F * <br><br> * l?F(?) bean:null<br> * (?) va:not null<br> * (?) field:not null<br> * var:maxByte=null<br> * var:minByte=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 testValidateByteRange01() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = null; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("maxByte"); var.setValue(null); field.addVar(var); var = new Var(); var.setName("minByte"); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // G?[?OmF assertTrue(LogUTUtil.checkError("bean is null.")); } /** * testValidateByteRange02() * <br><br> * * (??n) * <br> * _?FC,F * <br><br> * l?F(?) bean:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:maxByte="1"<br> * var:minByte="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 testValidateByteRange02() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("maxByte"); var.setValue("1"); field.addVar(var); var = new Var(); var.setName("minByte"); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteRange03() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="1"<br> * var:maxByte="5"<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> * ?beanoCg?fieldminByte?AmaxByte?A * truepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange03() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("maxByte"); var.setValue("5"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("1"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteRange04() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="4"<br> * var:maxByte="8"<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> * ?beanoCg?fieldminByte?AmaxByteO?A * G?[?bZ?[W?AfalsepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange04() 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("maxByte"); var.setValue("8"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("4"); field.addVar(var); 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(); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // falsep?B assertFalse(result); // G?[?2??B assertEquals(2, errors.size()); // ?bZ?[WIuWFNg? Iterator it = errors.get(); List<String> list = new ArrayList<String>(); while (it.hasNext()) { ActionMessage message = (ActionMessage) it.next(); list.add(message.getKey()); } assertTrue(list.contains("testMessage")); assertTrue(list.contains("message")); } /** * testValidateByteRange05() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="4"<br> * var:maxByte="8"<br> * encoding="UTF-8"<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> * ?beanoCg?fieldminByte?AmaxByteO?A * G?[?bZ?[W?AfalsepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange05() 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("maxByte"); var.setValue("8"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("4"); field.addVar(var); 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(); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // falsep?B assertFalse(result); // G?[?2??B assertEquals(2, errors.size()); // ?bZ?[WIuWFNg? Iterator it = errors.get(); List<String> list = new ArrayList<String>(); while (it.hasNext()) { ActionMessage message = (ActionMessage) it.next(); list.add(message.getKey()); } assertTrue(list.contains("testMessage")); assertTrue(list.contains("message")); } /** * testValidateByteRange06() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte=null<br> * var:maxByte=null<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> * fieldminByte?AmaxBytenull?A?A0?AInteger.MAX_VALUE * vZ?smF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange06() 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("maxByte"); var.setValue(null); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue(null); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteRange07() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"aaaaaa"<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte=""<br> * var:maxByte=""<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> * fieldminByte?AmaxByte?A?A0?AInteger.MAX_VALUE * vZ?smF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange07() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "aaaaaa"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("maxByte"); var.setValue(""); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue(""); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteRange08() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="abc"<br> * var:maxByte="def"<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?FG?[<br> * ?bZ?[W?F""<br> * O?FNumberFormatException<br> * ?Ox?Fx??<br> * ?bZ?[W?F<br> * "test-encoding is not supported."<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldminByte?AmaxByte?l?A?A0?A * Integer.MAX_VALUEvZ?smF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange08() 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("maxByte"); var.setValue("abc"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("def"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // G?[?O`FbN assertTrue(LogUTUtil.checkError("", new NumberFormatException())); // x???O`FbN assertTrue(LogUTUtil.checkWarn("test-encoding is not supported.")); } /** * testValidateByteRange09() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="8"<br> * var:maxByte="4"<br> * encoding="UTF-8"<br> * Msg("message","message")<br> * (?) errors:not null<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(l) boolean:false<br> * (?) errors:ActionMessage("message")<br> * * <br> * fieldminBytel?AmaxBytel??Afalsep * mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange09() 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("maxByte"); var.setValue("4"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("8"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // falsep?B assertFalse(result); // G?[?1??B assertEquals(1, errors.size()); // G?[IuWFNg`FbN Iterator it = errors.get(); ActionMessage message = (ActionMessage) it.next(); assertEquals("message", message.getKey()); } /** * testValidateByteRange10() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="4"<br> * var:maxByte="4"<br> * encoding="Windows-31J"<br> * Msg("message","message")<br> * (?) errors:not null<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(l) boolean:true<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldminBytemaxBytelv?A?bean?lv * ???AtruepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange10() 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("maxByte"); var.setValue("4"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("4"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteRange11() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"=""]<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="1"<br> * var:maxByte="10"<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 testValidateByteRange11() 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("maxByte"); var.setValue("10"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("1"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteRange12() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"="1234"]<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="1"<br> * var:maxByte="3"<br> * var: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 testValidateByteRange12() 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("maxByte"); var.setValue("3"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("1"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // falsep?B assertFalse(result); // G?[?1??B assertEquals(1, errors.size()); // G?[IuWFNg`FbN Iterator it = errors.get(); ActionMessage message = (ActionMessage) it.next(); assertEquals("message", message.getKey()); } /** * testValidateByteRange13() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Map:["field1"="123"]<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="1"<br> * var:maxByte="10"<br> * var: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 testValidateByteRange13() 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("maxByte"); var.setValue("10"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("1"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); } /** * testValidateByteRange14() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"aaaaaa"<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte=""<br> * var:maxByte="abc"<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> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F""<br> * O?FNumberFormatException<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldminByte?AmaxByte?l?A * ?A0?AInteger.MAX_VALUEvZ?s?AG?[?O * ?omF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange14() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "aaaaaa"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("maxByte"); var.setValue("abc"); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue(""); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // G?[?O`FbN assertTrue(LogUTUtil.checkError("", new NumberFormatException())); } /** * testValidateByteRange15() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:String:"bbbbb"<br> * (?) va:not null<br> * (?) field:not null<br> * var:minByte="def"<br> * var:maxByte=""<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> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F""<br> * O?FNumberFormatException<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldminByte?l?AmaxByte?A * ?A0?AInteger.MAX_VALUEvZ?s?AG?[?O * ?omF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateByteRange15() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "bbbbb"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("maxByte"); var.setValue(""); field.addVar(var); var = new Var(); var.setName("minByte"); var.setValue("def"); field.addVar(var); 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.validateByteRange(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // G?[?O`FbN assertTrue(LogUTUtil.checkError("", new NumberFormatException())); } /** * testValidateMultiField01() * <br><br> * * (??n) * <br> * _?FC,F * <br><br> * l?F(?) bean:null<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> * (?) MultiFieldValidator:?o<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 testValidateMultiField01() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = null; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?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.validateMultiField(bean, va, field, errors, validator, request); // eXgmF // truep?B assertTrue(result); // G?[??B assertTrue(errors.isEmpty()); // G?[?OmF assertTrue(LogUTUtil.checkError("bean is null.")); } // /** // * testValidateMultiField02() // * <br><br> // * // * (??n) // * <br> // * _?FC,F // * <br><br> // * l?F(?) bean:""<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> // * (?) MultiFieldValidator:?o<br> // * (?) errors:not null<br> // * (vf)<br> // * // * <br> // * ?bean?AtruepmF?B // * <br> // * // * @throws Exception ?\bh?O // */ // public void testValidateMultiField02() throws Exception { // // eXgP?[X?? // } /** * testValidateMultiField03() * <br><br> * * (?n) * <br> * _?FC,F * <br><br> * l?F(?) bean:""<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator=null<br> * Msg("message","message")<br> * (?) errors:not null<br> * (vf)<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(?) MultiFieldValidator:?o<br> * (?) O:IllegalArgumentException<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is required."<br> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is required."<br> * (?) errors:not null<br> * (vf)<br> * * <br> * bean?A`FbN???s?B<br> * fieldmultiFieldValidatornull?AIllegalArgumentException * ?mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField03() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = ""; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); 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 try { FieldChecksEx.validateMultiField(bean, va, field, errors, validator, request); fail(); } catch (IllegalArgumentException e) { assertTrue(errors.isEmpty()); assertEquals("var value[multiFieldValidator] is required.", e.getMessage()); assertTrue(LogUTUtil.checkError("var value[multiFieldValidator] is required.")); } } /** * testValidateMultiField04() * <br><br> * * (?n) * <br> * _?FF,G * <br><br> * l?F(?) bean:"abc"<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator=""<br> * Msg("message","message")<br> * (?) errors:not null<br> * (vf)<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(?) MultiFieldValidator:?o<br> * (?) O:IllegalArgumentException<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is required."<br> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is required."<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldmultiFieldValidator?A * IllegalArgumentException?mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField04() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); 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 try { FieldChecksEx.validateMultiField(bean, va, field, errors, validator, request); fail(); } catch (IllegalArgumentException e) { assertTrue(errors.isEmpty()); assertEquals("var value[multiFieldValidator] is required.", e.getMessage()); assertTrue(LogUTUtil.checkError("var value[multiFieldValidator] is required.")); } } /** * testValidateMultiField05() * <br><br> * * (?n) * <br> * _?FF,G * <br><br> * l?F(?) bean:"abc"<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator="abc"<br> * Msg("message","message")<br> * (?) errors:not null<br> * (vf)<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(?) MultiFieldValidator:?o<br> * (?) O:IllegalArgumentException<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is invalid."<br> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is invalid."<br> * O?F<br> * ClassLoadException(ClassNotFoundException) * (?) errors:not null<br> * (vf)<br> * * <br> * fieldmultiFieldValidatorNXpX??NX?A * IllegalArgumentException?mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField05() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); var.setValue("abc"); 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 try { FieldChecksEx.validateMultiField(bean, va, field, errors, validator, request); fail(); } catch (IllegalArgumentException e) { assertTrue(errors.isEmpty()); assertEquals("var value[multiFieldValidator] is invalid.", e.getMessage()); assertTrue(LogUTUtil.checkError("var value[multiFieldValidator] is invalid.", new ClassLoadException(new ClassNotFoundException()))); } } /** * testValidateMultiField06() * <br><br> * * (?n) * <br> * _?FF,G * <br><br> * l?F(?) bean:"abc"<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator="java.lang.String"<br> * Msg("message","message")<br> * (?) errors:not null<br> * (vf)<br> * (?) validator:not null<br> * (?) request:not null<br> * * <br> * l?F(?) MultiFieldValidator:?o<br> * (?) O:IllegalArgumentException<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is invalid."<br> * (?) ?O:?Ox?FG?[<br> * ?bZ?[W?F<br> * "var value[multiFieldValidator] is invalid."<br> * O?F<br> * ClassCastException<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldmultiFieldValidatorMultiFieldValidatorNX * ?AIllegalArgumentException?mF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField06() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); var.setValue("java.lang.String"); 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 try { FieldChecksEx.validateMultiField(bean, va, field, errors, validator, request); fail(); } catch (IllegalArgumentException e) { assertTrue(errors.isEmpty()); assertEquals("var value[multiFieldValidator] is invalid.", e.getMessage()); assertTrue( LogUTUtil.checkError("var value[multiFieldValidator] is invalid.", new ClassCastException())); } } /** * testValidateMultiField07() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:"abc"<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator=<br> * "jp.terasoluna.fw.web.struts.form.FieldChecksEx_MultiFieldValidatorImpl01"<br> * var:fields=null<br> * Msg("message","message")<br> * (?) errors:not null<br> * (vf)<br> * (?) validator:not null<br> * (?) request:not null<br> * (?) MultiFieldValidator.validate():true<br> * * <br> * l?F(l) boolean:true<br> * (?) MultiFieldValidator:?"abc",vf0z?o?B<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldfieldsnull???AMultiFieldValidator?z * nmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField07() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); var.setValue("jp.terasoluna.fw.web.struts.form." + "FieldChecksEx_MultiFieldValidatorImpl01"); field.addVar(var); var = new Var(); var.setName("fields"); 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); // MultiFieldValidatorl? FieldChecksEx_MultiFieldValidatorImpl01.result = true; // eXg?s boolean result = FieldChecksEx.validateMultiField(bean, va, field, errors, validator, request); // mF assertTrue(result); assertTrue(errors.isEmpty()); // MultiFieldValidator?o?A?mF assertEquals(1, FieldChecksEx_MultiFieldValidatorImpl01.validateCalledCount); assertEquals("abc", FieldChecksEx_MultiFieldValidatorImpl01.value); assertEquals(0, FieldChecksEx_MultiFieldValidatorImpl01.fields.length); } /** * testValidateMultiField08() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:"abc"<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator=<br> * "jp.terasoluna.fw.web.struts.form.FieldChecksEx_MultiFieldValidatorImpl01"<br> * var:fields=""<br> * Msg("message","message")<br> * (?) errors:not null<br> * (vf)<br> * (?) validator:not null<br> * (?) request:not null<br> * (?) MultiFieldValidator.validate():true<br> * * <br> * l?F(l) boolean:true<br> * (?) MultiFieldValidator:?"abc",vf0z?o?B<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldfieldsnull???AMultiFieldValidator?z * nmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField08() throws Exception { //eXgf?[^? // ++++ beanIuWFNg ++++ String bean = "abc"; // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); var.setValue("jp.terasoluna.fw.web.struts.form." + "FieldChecksEx_MultiFieldValidatorImpl01"); field.addVar(var); var = new Var(); var.setName("fields"); 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); // MultiFieldValidatorl? FieldChecksEx_MultiFieldValidatorImpl01.result = true; // eXg?s boolean result = FieldChecksEx.validateMultiField(bean, va, field, errors, validator, request); // mF assertTrue(result); assertTrue(errors.isEmpty()); // MultiFieldValidator?o?A?mF assertEquals(1, FieldChecksEx_MultiFieldValidatorImpl01.validateCalledCount); assertEquals("abc", FieldChecksEx_MultiFieldValidatorImpl01.value); assertEquals(0, FieldChecksEx_MultiFieldValidatorImpl01.fields.length); } /** * testValidateMultiField09() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Bean<br> * field1="abc"<br> * field2="def"<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator=<br> * "jp.terasoluna.fw.web.struts.form.FieldCheckEx_MultiFieldValidatorImpl01"<br> * var:fields="field2"<br> * var:property="field1"<br> * Msg("message","message")<br> * (?) errors:not null<br> * (vf)<br> * (?) validator:not null<br> * (?) request:not null<br> * (?) MultiFieldValidator.validate():true<br> * * <br> * l?F(l) boolean:true<br> * (?) MultiFieldValidator:?"abc",<br> * z{"def"}<br> * ?o?B<br> * (?) errors:not null<br> * (vf)<br> * * <br> * fieldsJ}?w???A * Ov?peBl?bean?A * 1zMultiFieldValidator?nmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField09() throws Exception { //eXgf?[^? // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); var.setValue("jp.terasoluna.fw.web.struts.form." + "FieldChecksEx_MultiFieldValidatorImpl01"); field.addVar(var); var = new Var(); var.setName("fields"); var.setValue("field2"); field.addVar(var); 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(); // ValidatorResourcesCX^X ValidatorResources validatorResources = new ValidatorResources(); // ValidatorCX^X Validator validator = new Validator(validatorResources); // MultiFieldValidatorl? FieldChecksEx_MultiFieldValidatorImpl01.result = true; // eXg?s boolean result = FieldChecksEx.validateMultiField(javaBean, va, field, errors, validator, request); // mF assertTrue(result); assertTrue(errors.isEmpty()); // MultiFieldValidator?o?A?mF assertEquals(1, FieldChecksEx_MultiFieldValidatorImpl01.validateCalledCount); assertEquals("abc", FieldChecksEx_MultiFieldValidatorImpl01.value); assertEquals(1, FieldChecksEx_MultiFieldValidatorImpl01.fields.length); assertEquals("def", FieldChecksEx_MultiFieldValidatorImpl01.fields[0]); } /** * testValidateMultiField10() * <br><br> * * (??n) * <br> * _?FF * <br><br> * l?F(?) bean:Bean<br> * field1="abc"<br> * field2="def"<br> * field3="ghi"<br> * field4="jkl"<br> * (?) va:not null<br> * (?) field:not null<br> * var:multiFieldValidator=<br> * "jp.terasoluna.fw.web.struts.form.FieldCheckEx_MultiFieldValidatorImpl01"<br> * var:fields="field2 ,,test,field3,field4"<br> * var:property="field1"<br> * Msg("message","message")<br> * (?) errors:not null<br> * ActionMessage("testMessage")<br> * (?) validator:not null<br> * (?) request:not null<br> * (?) MultiFieldValidator.validate():false<br> * * <br> * l?F(l) boolean:false<br> * (?) MultiFieldValidator:?"abc",<br> * z{"def",null,"ghi","jkl"}<br> * ?o?B<br> * (?) errors:ActionMessage("testMessage")<br> * ActionMessage("message")<br> * * <br> * fieldsJ}?w???A * J}?SOv?peBl?bean?A * zMultiFieldValidator?nmF?B<br> * MultiFieldValidatorvalidate?\bhfalsep???A * G?[?bZ?[WfalsepmF?B * <br> * * @throws Exception ?\bh?O */ public void testValidateMultiField10() throws Exception { //eXgf?[^? // ++++ ??IuWFNg ValidatorAction va = new ValidatorAction(); va.setName("message"); // ++++ ?tB?[h? Field field = new Field(); Var var = new Var(); var.setName("multiFieldValidator"); var.setValue("jp.terasoluna.fw.web.struts.form." + "FieldChecksEx_MultiFieldValidatorImpl01"); field.addVar(var); var = new Var(); var.setName("fields"); var.setValue("field2 ,,test,field3,field4"); field.addVar(var); 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(); 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); // MultiFieldValidatorl? FieldChecksEx_MultiFieldValidatorImpl01.result = false; // eXg?s boolean result = FieldChecksEx.validateMultiField(javaBean, va, field, errors, validator, request); // mF assertFalse(result); assertEquals(2, errors.size()); // ?bZ?[WIuWFNg`FbN Iterator it = errors.get(); List<String> list = new ArrayList<String>(); while (it.hasNext()) { ActionMessage message = (ActionMessage) it.next(); list.add(message.getKey()); } assertTrue(list.contains("testMessage")); assertTrue(list.contains("message")); // MultiFieldValidator?o?A?mF assertEquals(1, FieldChecksEx_MultiFieldValidatorImpl01.validateCalledCount); assertEquals("abc", FieldChecksEx_MultiFieldValidatorImpl01.value); assertEquals(4, FieldChecksEx_MultiFieldValidatorImpl01.fields.length); assertEquals("def", FieldChecksEx_MultiFieldValidatorImpl01.fields[0]); assertNull(FieldChecksEx_MultiFieldValidatorImpl01.fields[1]); assertEquals("ghi", FieldChecksEx_MultiFieldValidatorImpl01.fields[2]); assertEquals("jkl", FieldChecksEx_MultiFieldValidatorImpl01.fields[3]); } }