jmitchell 2003/06/06 20:44:04 Added: src/test/org/apache/struts/taglib/html TestMultiboxTag3.java web/test/test/org/apache/struts/taglib/html TestMultiboxTag3.jsp Log: More tests.....fun fun!! Revision Changes Path 1.1 jakarta-struts/src/test/org/apache/struts/taglib/html/TestMultiboxTag3.java Index: TestMultiboxTag3.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/html/TestMultiboxTag3.java,v 1.1 2003/06/07 03:44:04 jmitchell Exp $ * $Revision: 1.1 $ * $Date: 2003/06/07 03:44:04 $ * * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Struts", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.struts.taglib.html; import java.util.Locale; import javax.servlet.jsp.PageContext; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.cactus.JspTestCase; import org.apache.struts.Globals; import org.apache.struts.taglib.SimpleBeanForTesting; /** * Suite of unit tests for the * <code>org.apache.struts.taglib.html.MultiboxTag</code> class. * NOTE - These tests were separated into 4 files each because of the * size of the jsp. (not playing well with Tomcat 3.3 * * These tests are numbered as such: * * 1 thru 4 test a single checkbox * TestMultiboxTag1 - These test validate true (a value was in the array) on our form. * TestMultiboxTag2 - Same as 1, but using BodyContent instead of value attribute * * TestMultiboxTag3 - These test validate true (a value was in the array) on our form. * TestMultiboxTag4 - Same as 3, but using BodyContent instead of value attribute * * 5 thru 8 test multiple checkboxes * TestMultiboxTag5 - These test validate true (a value was in the array) on our form. * TestMultiboxTag6 - Same as 5, but using BodyContent instead of value attribute * * TestMultiboxTag7 - These test validate true (a value was in the array) on our form. * TestMultiboxTag8 - Same as 7, but using BodyContent instead of value attribute * * @author James Mitchell */ public class TestMultiboxTag3 extends JspTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestMultiboxTag3(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.awtui.TestRunner.main(new String[] {TestMultiboxTag3.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestMultiboxTag3.class); } private void runMyTest(String whichTest, String locale){ pageContext.setAttribute(Globals.LOCALE_KEY, new Locale(locale, locale), PageContext.SESSION_SCOPE); String[] s = new String[7]; for(int i = 1; i < 7; i++){ s[i] = "value" + i; } SimpleBeanForTesting sbft = new SimpleBeanForTesting(s); pageContext.setAttribute(Constants.BEAN_KEY, sbft, PageContext.REQUEST_SCOPE); request.setAttribute("runTest", whichTest); try { pageContext.forward("/test/org/apache/struts/taglib/html/TestMultiboxTag3.jsp"); } catch (Exception e) { e.printStackTrace(); fail("There is a problem that is preventing the tests to continue!"); } } /* * Testing MultiboxTag. */ public void testMultiboxPropertyFalse(){ runMyTest("testMultiboxPropertyFalse", ""); } public void testMultiboxPropertyFalseAccesskey(){ runMyTest("testMultiboxPropertyFalseAccesskey", ""); } public void testMultiboxPropertyFalseAlt(){ runMyTest("testMultiboxPropertyFalseAlt", ""); } public void testMultiboxPropertyFalseAltKey1(){ runMyTest("testMultiboxPropertyFalseAltKey1", ""); } public void testMultiboxPropertyFalseAltKey2(){ runMyTest("testMultiboxPropertyFalseAltKey2", ""); } public void testMultiboxPropertyFalseAltKey_fr1(){ runMyTest("testMultiboxPropertyFalseAltKey1_fr", "fr"); } public void testMultiboxPropertyFalseAltKey_fr2(){ runMyTest("testMultiboxPropertyFalseAltKey2_fr", "fr"); } public void testMultiboxPropertyFalseDisabled_True(){ runMyTest("testMultiboxPropertyFalseDisabled_True", ""); } public void testMultiboxPropertyFalseDisabled_False1(){ runMyTest("testMultiboxPropertyFalseDisabled_False1", ""); } public void testMultiboxPropertyFalseDisabled_False2(){ runMyTest("testMultiboxPropertyFalseDisabled_False2", ""); } public void testMultiboxPropertyFalseOnblur(){ runMyTest("testMultiboxPropertyFalseOnblur", ""); } public void testMultiboxPropertyFalseOnchange(){ runMyTest("testMultiboxPropertyFalseOnchange", ""); } public void testMultiboxPropertyFalseOnclick(){ runMyTest("testMultiboxPropertyFalseOnclick", ""); } public void testMultiboxPropertyFalseOndblclick(){ runMyTest("testMultiboxPropertyFalseOndblclick", ""); } public void testMultiboxPropertyFalseOnfocus(){ runMyTest("testMultiboxPropertyFalseOnfocus", ""); } public void testMultiboxPropertyFalseOnkeydown(){ runMyTest("testMultiboxPropertyFalseOnkeydown", ""); } public void testMultiboxPropertyFalseOnkeypress(){ runMyTest("testMultiboxPropertyFalseOnkeypress", ""); } public void testMultiboxPropertyFalseOnkeyup(){ runMyTest("testMultiboxPropertyFalseOnkeyup", ""); } public void testMultiboxPropertyFalseOnmousedown(){ runMyTest("testMultiboxPropertyFalseOnmousedown", ""); } public void testMultiboxPropertyFalseOnmousemove(){ runMyTest("testMultiboxPropertyFalseOnmousemove", ""); } public void testMultiboxPropertyFalseOnmouseout(){ runMyTest("testMultiboxPropertyFalseOnmouseout", ""); } public void testMultiboxPropertyFalseOnmouseover(){ runMyTest("testMultiboxPropertyFalseOnmouseover", ""); } public void testMultiboxPropertyFalseOnmouseup(){ runMyTest("testMultiboxPropertyFalseOnmouseup", ""); } } 1.1 jakarta-struts/web/test/test/org/apache/struts/taglib/html/TestMultiboxTag3.jsp Index: TestMultiboxTag3.jsp =================================================================== <%@ page contentType="text/html;charset=UTF-8" language="java" %> <[EMAIL PROTECTED] import="junit.framework.Assert"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <logic:equal name="runTest" value="testMultiboxPropertyFalse"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseAccesskey"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" accesskey="a" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" accesskey="a" value="value100"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseAlt"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" alt="Testing alt attribute" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" alt="Testing alt attribute"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseAltKey1"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="default.bundle.message" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" alt="Testing Message"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseAltKey2"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="no.such.key" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseAltKey1_fr"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="default.bundle.message" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" alt="Message D'Essai"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseAltKey2_fr"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="no.such.key" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseDisabled_True"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" disabled="true" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" disabled="disabled"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseDisabled_False1"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" disabled="false" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseDisabled_False2"> <!-- This was changed recently by overwhelming consensus. The prior functionality was very counter-intuitive. It used to be that putting disabled="false" was the same as putting disabled="true". Craig sited the confusion is due to the HTML spec. --> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" disabled="anything but true" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnblur"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onblur="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onblur="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnchange"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onchange="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onchange="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnclick"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onclick="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onclick="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOndblclick"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" ondblclick="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" ondblclick="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnfocus"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onfocus="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onfocus="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnkeydown"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onkeydown="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onkeydown="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnkeypress"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onkeypress="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onkeypress="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnkeyup"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onkeyup="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onkeyup="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnmousedown"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmousedown="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onmousedown="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnmousemove"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmousemove="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onmousemove="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnmouseout"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmouseout="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onmouseout="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnmouseover"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmouseover="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onmouseover="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyFalseOnmouseup"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmouseup="Put script here" value="value100"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value100" onmouseup="Put script here"> </bean:define> </logic:equal> <% String expected = ""; String compareTo = ""; if (pageContext.getAttribute("EXPECTED_RESULTS") == null){ throw new javax.servlet.jsp.JspException("No tests on this page were called. Please verify that you've setup the tests correctly."); }else{ expected=pageContext.getAttribute("TEST_RESULTS").toString(); } if (pageContext.getAttribute("TEST_RESULTS") != null){ compareTo=pageContext.getAttribute("EXPECTED_RESULTS").toString(); } Assert.assertEquals(compareTo, expected); %>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]