jmitchell 2003/06/06 20:41:31 Added: src/test/org/apache/struts/taglib/html TestMultiboxTag1.java web/test/test/org/apache/struts/taglib/html TestMultiboxTag1.jsp Log: More tests.....fun fun!! Revision Changes Path 1.1 jakarta-struts/src/test/org/apache/struts/taglib/html/TestMultiboxTag1.java Index: TestMultiboxTag1.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/html/TestMultiboxTag1.java,v 1.1 2003/06/07 03:41:31 jmitchell Exp $ * $Revision: 1.1 $ * $Date: 2003/06/07 03:41:31 $ * * ==================================================================== * 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 TestMultiboxTag1 extends JspTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestMultiboxTag1(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[] {TestMultiboxTag1.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(TestMultiboxTag1.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/TestMultiboxTag1.jsp"); } catch (Exception e) { e.printStackTrace(); fail("There is a problem that is preventing the tests to continue!"); } } /* * Testing MultiboxTag. */ public void testMultiboxPropertyTrue(){ runMyTest("testMultiboxPropertyTrue", ""); } public void testMultiboxPropertyTrueAccesskey(){ runMyTest("testMultiboxPropertyTrueAccesskey", ""); } public void testMultiboxPropertyTrueAlt(){ runMyTest("testMultiboxPropertyTrueAlt", ""); } public void testMultiboxPropertyTrueAltKey1(){ runMyTest("testMultiboxPropertyTrueAltKey1", ""); } public void testMultiboxPropertyTrueAltKey2(){ runMyTest("testMultiboxPropertyTrueAltKey2", ""); } public void testMultiboxPropertyTrueAltKey_fr1(){ runMyTest("testMultiboxPropertyTrueAltKey1_fr", "fr"); } public void testMultiboxPropertyTrueAltKey_fr2(){ runMyTest("testMultiboxPropertyTrueAltKey2_fr", "fr"); } public void testMultiboxPropertyTrueDisabled_True(){ runMyTest("testMultiboxPropertyTrueDisabled_True", ""); } public void testMultiboxPropertyTrueDisabled_False1(){ runMyTest("testMultiboxPropertyTrueDisabled_False1", ""); } public void testMultiboxPropertyTrueDisabled_False2(){ runMyTest("testMultiboxPropertyTrueDisabled_False2", ""); } public void testMultiboxPropertyTrueOnblur(){ runMyTest("testMultiboxPropertyTrueOnblur", ""); } public void testMultiboxPropertyTrueOnchange(){ runMyTest("testMultiboxPropertyTrueOnchange", ""); } public void testMultiboxPropertyTrueOnclick(){ runMyTest("testMultiboxPropertyTrueOnclick", ""); } public void testMultiboxPropertyTrueOndblclick(){ runMyTest("testMultiboxPropertyTrueOndblclick", ""); } public void testMultiboxPropertyTrueOnfocus(){ runMyTest("testMultiboxPropertyTrueOnfocus", ""); } public void testMultiboxPropertyTrueOnkeydown(){ runMyTest("testMultiboxPropertyTrueOnkeydown", ""); } public void testMultiboxPropertyTrueOnkeypress(){ runMyTest("testMultiboxPropertyTrueOnkeypress", ""); } public void testMultiboxPropertyTrueOnkeyup(){ runMyTest("testMultiboxPropertyTrueOnkeyup", ""); } public void testMultiboxPropertyTrueOnmousedown(){ runMyTest("testMultiboxPropertyTrueOnmousedown", ""); } public void testMultiboxPropertyTrueOnmousemove(){ runMyTest("testMultiboxPropertyTrueOnmousemove", ""); } public void testMultiboxPropertyTrueOnmouseout(){ runMyTest("testMultiboxPropertyTrueOnmouseout", ""); } public void testMultiboxPropertyTrueOnmouseover(){ runMyTest("testMultiboxPropertyTrueOnmouseover", ""); } public void testMultiboxPropertyTrueOnmouseup(){ runMyTest("testMultiboxPropertyTrueOnmouseup", ""); } } 1.1 jakarta-struts/web/test/test/org/apache/struts/taglib/html/TestMultiboxTag1.jsp Index: TestMultiboxTag1.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="testMultiboxPropertyTrue"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueAccesskey"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" accesskey="a" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" accesskey="a" value="value1" checked="checked"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueAlt"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" alt="Testing alt attribute" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" alt="Testing alt attribute"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueAltKey1"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="default.bundle.message" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" alt="Testing Message"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueAltKey2"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="no.such.key" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueAltKey1_fr"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="default.bundle.message" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" alt="Message D'Essai"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueAltKey2_fr"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" altKey="no.such.key" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueDisabled_True"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" disabled="true" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" disabled="disabled"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueDisabled_False1"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" disabled="false" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueDisabled_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="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnblur"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onblur="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onblur="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnchange"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onchange="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onchange="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnclick"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onclick="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onclick="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOndblclick"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" ondblclick="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" ondblclick="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnfocus"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onfocus="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onfocus="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnkeydown"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onkeydown="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onkeydown="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnkeypress"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onkeypress="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onkeypress="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnkeyup"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onkeyup="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onkeyup="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnmousedown"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmousedown="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onmousedown="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnmousemove"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmousemove="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onmousemove="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnmouseout"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmouseout="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onmouseout="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnmouseover"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmouseover="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" onmouseover="Put script here"> </bean:define> </logic:equal> <logic:equal name="runTest" value="testMultiboxPropertyTrueOnmouseup"> <bean:define id="TEST_RESULTS" toScope="page"> <html:multibox property="stringArray" onmouseup="Put script here" value="value1"/> </bean:define> <bean:define id="EXPECTED_RESULTS" toScope="page"> <input type="checkbox" name="stringArray" value="value1" checked="checked" 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]