You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by jm...@apache.org on 2003/06/07 05:44:53 UTC

cvs commit: jakarta-struts/web/test/test/org/apache/struts/taglib/html TestMultiboxTag4.jsp

jmitchell    2003/06/06 20:44:53

  Added:       src/test/org/apache/struts/taglib/html TestMultiboxTag4.java
               web/test/test/org/apache/struts/taglib/html
                        TestMultiboxTag4.jsp
  Log:
  More tests.....fun fun!!
  
  Revision  Changes    Path
  1.1                  jakarta-struts/src/test/org/apache/struts/taglib/html/TestMultiboxTag4.java
  
  Index: TestMultiboxTag4.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/html/TestMultiboxTag4.java,v 1.1 2003/06/07 03:44:53 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2003/06/07 03:44:53 $
   *
   * ====================================================================
   * 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 apache@apache.org.
   *
   * 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 TestMultiboxTag4 extends JspTestCase {
  
      /**
       * Defines the testcase name for JUnit.
       *
       * @param theName the testcase's name.
       */
      public TestMultiboxTag4(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[] {TestMultiboxTag4.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(TestMultiboxTag4.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/TestMultiboxTag4.jsp");
  		}
  		catch (Exception e) {
  			e.printStackTrace();
  			fail("There is a problem that is preventing the tests to continue!");
  		}
      }
  
      /*
       * Testing MultiboxTag.
       */
      public void testMultiboxBodyPropertyFalse(){
      	runMyTest("testMultiboxBodyPropertyFalse", "");
  	}
      public void testMultiboxBodyPropertyFalseAccesskey(){
      	runMyTest("testMultiboxBodyPropertyFalseAccesskey", "");
  	}
      public void testMultiboxBodyPropertyFalseAlt(){
      	runMyTest("testMultiboxBodyPropertyFalseAlt", "");
  	}
      public void testMultiboxBodyPropertyFalseAltKey1(){
      	runMyTest("testMultiboxBodyPropertyFalseAltKey1", "");
  	}
      public void testMultiboxBodyPropertyFalseAltKey2(){
      	runMyTest("testMultiboxBodyPropertyFalseAltKey2", "");
  	}
      public void testMultiboxBodyPropertyFalseAltKey_fr1(){
      	runMyTest("testMultiboxBodyPropertyFalseAltKey1_fr", "fr");
  	}
      public void testMultiboxBodyPropertyFalseAltKey_fr2(){
      	runMyTest("testMultiboxBodyPropertyFalseAltKey2_fr", "fr");
  	}
      public void testMultiboxBodyPropertyFalseDisabled_False(){
      	runMyTest("testMultiboxBodyPropertyFalseDisabled_True", "");
  	}
      public void testMultiboxBodyPropertyFalseDisabled_False1(){
      	runMyTest("testMultiboxBodyPropertyFalseDisabled_False1", "");
  	}
      public void testMultiboxBodyPropertyFalseDisabled_False2(){
      	runMyTest("testMultiboxBodyPropertyFalseDisabled_False2", "");
  	}
      public void testMultiboxBodyPropertyFalseOnblur(){
      	runMyTest("testMultiboxBodyPropertyFalseOnblur", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnchange(){
      	runMyTest("testMultiboxBodyPropertyFalseOnchange", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnclick(){
      	runMyTest("testMultiboxBodyPropertyFalseOnclick", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOndblclick(){
      	runMyTest("testMultiboxBodyPropertyFalseOndblclick", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnfocus(){
      	runMyTest("testMultiboxBodyPropertyFalseOnfocus", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnkeydown(){
      	runMyTest("testMultiboxBodyPropertyFalseOnkeydown", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnkeypress(){
      	runMyTest("testMultiboxBodyPropertyFalseOnkeypress", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnkeyup(){
      	runMyTest("testMultiboxBodyPropertyFalseOnkeyup", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnmousedown(){
      	runMyTest("testMultiboxBodyPropertyFalseOnmousedown", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnmousemove(){
      	runMyTest("testMultiboxBodyPropertyFalseOnmousemove", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnmouseout(){
      	runMyTest("testMultiboxBodyPropertyFalseOnmouseout", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnmouseover(){
      	runMyTest("testMultiboxBodyPropertyFalseOnmouseover", "");
  	}
  
      public void testMultiboxBodyPropertyFalseOnmouseup(){
      	runMyTest("testMultiboxBodyPropertyFalseOnmouseup", "");
  	}
  
  }
  
  
  
  1.1                  jakarta-struts/web/test/test/org/apache/struts/taglib/html/TestMultiboxTag4.jsp
  
  Index: TestMultiboxTag4.jsp
  ===================================================================
  <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  <%@page 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="testMultiboxBodyPropertyFalse">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseAccesskey">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" accesskey="a">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseAlt">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" alt="Testing alt attribute">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseAltKey1">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" altKey="default.bundle.message">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseAltKey2">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" altKey="no.such.key">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseAltKey1_fr">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" altKey="default.bundle.message">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseAltKey2_fr">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" altKey="no.such.key">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseDisabled_True">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" disabled="true">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseDisabled_False1">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" disabled="false">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseDisabled_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">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnblur">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onblur="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnchange">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onchange="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnclick">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onclick="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOndblclick">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" ondblclick="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnfocus">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onfocus="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnkeydown">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onkeydown="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnkeypress">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onkeypress="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnkeyup">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onkeyup="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnmousedown">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onmousedown="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnmousemove">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onmousemove="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnmouseout">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onmouseout="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnmouseover">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onmouseover="Put script here">
  		value100
  		</html:multibox>
  	</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="testMultiboxBodyPropertyFalseOnmouseup">
  	<bean:define id="TEST_RESULTS" toScope="page">
  		<html:multibox property="stringArray" onmouseup="Put script here">
  		value100
  		</html:multibox>
  	</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: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org