jmitchell    2003/03/06 21:38:24

  Added:       src/test/org/apache/struts/taglib/html TestFormTag1.java
               web/test/test/org/apache/struts/taglib/html TestFormTag1.jsp
  Log:
  Adding more tests
  
  Revision  Changes    Path
  1.1                  
jakarta-struts/src/test/org/apache/struts/taglib/html/TestFormTag1.java
  
  Index: TestFormTag1.java
  ===================================================================
  /*
   * 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.JspException;
  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.bean.FormTag</code> class.
   *
   * @author James Mitchell
   */
  public class TestFormTag1 extends JspTestCase {
  
      /**
       * Defines the testcase name for JUnit.
       *
       * @param theName the testcase's name.
       */
      public TestFormTag1(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[] {TestFormTag1.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(TestFormTag1.class);
      }
  
      private void runMyTest(String whichTest, String locale){
        pageContext.setAttribute(Globals.LOCALE_KEY, new Locale(locale, locale), 
PageContext.SESSION_SCOPE);
        pageContext.setAttribute(Constants.BEAN_KEY, new SimpleBeanForTesting("Test 
Value"), PageContext.REQUEST_SCOPE);
                request.setAttribute("runTest", whichTest);
          try {
                        
pageContext.forward("/test/org/apache/struts/taglib/html/TestFormTag1.jsp");
                }
                catch (Exception e) {
                        e.printStackTrace();
                        fail("There is a problem that is preventing the tests to 
continue!");
                }
      }
  
      /*
       * Testing FormTag.
       */
      public void testFormAction(){ 
        runMyTest("testFormAction", "");
        }
      public void testFormActionEnctype(){ 
        runMyTest("testFormActionEnctype", "");
        }
      public void testFormActionFocus(){ 
        runMyTest("testFormActionFocus", "");
        }
      public void testFormActionFocusIndexed(){ 
        runMyTest("testFormActionFocusIndexed", "");
        }
      public void testFormActionMethod1(){ 
        runMyTest("testFormActionMethod1", "");
        }
      public void testFormActionMethod2(){ 
        runMyTest("testFormActionMethod2", "");
        }
      public void testFormActionMethod3(){ 
        runMyTest("testFormActionMethod3", "");
        }
      public void testFormActionMethod4(){ 
        runMyTest("testFormActionMethod4", "");
        }
      public void testFormActionMethod5(){ 
        runMyTest("testFormActionMethod5", "");
        }
      public void testFormActionOnreset(){ 
        runMyTest("testFormActionOnreset", "");
        }
      public void testFormActionOnsubmit(){ 
        runMyTest("testFormActionOnsubmit", "");
        }
      public void testFormActionStyle(){ 
        runMyTest("testFormActionStyle", "");
        }
      public void testFormActionStyleClass(){ 
        runMyTest("testFormActionStyleClass", "");
        }
      public void testFormActionStyleId(){ 
        runMyTest("testFormActionStyleId", "");
        }
      public void testFormActionTarget(){ 
        runMyTest("testFormActionTarget", "");
        }
  
  
  
  
        
        
  }
  
  
  
  1.1                  
jakarta-struts/web/test/test/org/apache/struts/taglib/html/TestFormTag1.jsp
  
  Index: TestFormTag1.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="testFormAction">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="post" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
        </bean:define>
  </logic:equal>
  
  
  <logic:equal name="runTest" value="testFormActionEnctype">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" enctype="multipart/form-data">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="post" 
action="<%=response.encodeURL("/test/testFormTag.do")%>" enctype="multipart/form-data">
                </form>
        </bean:define>
  </logic:equal>
   
  
  <logic:equal name="runTest" value="testFormActionFocus">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" focus="string">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="post" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
  <script type="text/javascript" language="JavaScript">
    <!--
    var focusControl = document.forms["testFormBean"].elements["string"];
  
    if (focusControl.type != "hidden") {
       focusControl.focus();
    } 
    // -->
  </script>
        </bean:define>
  </logic:equal>
   
  
  <logic:equal name="runTest" value="testFormActionFocusIndexed">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" focus="stringIndexed" focusIndex="2">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="post" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
  <script type="text/javascript" language="JavaScript">
    <!--
    var focusControl = document.forms["testFormBean"].elements["stringIndexed"];
  
    if (focusControl.type != "hidden") {
       focusControl[2].focus();
    } 
    // -->
  </script>
        </bean:define>
  </logic:equal>
   
  
  <logic:equal name="runTest" value="testFormActionMethod1">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="post">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="post" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionMethod2">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="Post">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="Post" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionMethod3">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="get">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="get" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionMethod4">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="Get">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="Get" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionMethod5">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="GET">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="GET" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionMethod6">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="misc">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="misc" 
action="<%=response.encodeURL("/test/testFormTag.do")%>">
                </form>
        </bean:define>
  </logic:equal>
  
  
  <logic:equal name="runTest" value="testFormActionOnreset">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="misc" onreset="script goes 
here">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="misc" 
action="<%=response.encodeURL("/test/testFormTag.do")%>" onreset="script goes here">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionOnsubmit">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="misc" onsubmit="script goes 
here">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="misc" 
action="<%=response.encodeURL("/test/testFormTag.do")%>" onsubmit="script goes here">
                </form>
        </bean:define>
  </logic:equal>
  
  
  <logic:equal name="runTest" value="testFormActionStyle">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="misc" style="style.goes.here">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="misc" 
action="<%=response.encodeURL("/test/testFormTag.do")%>" style="style.goes.here">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionStyleClass">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="misc" 
styleClass="style.goes.here">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="misc" 
action="<%=response.encodeURL("/test/testFormTag.do")%>" class="style.goes.here">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionStyleId">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="misc" styleId="id.goes.here">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="misc" 
action="<%=response.encodeURL("/test/testFormTag.do")%>" id="id.goes.here">
                </form>
        </bean:define>
  </logic:equal>
  
  <logic:equal name="runTest" value="testFormActionTarget">
        <bean:define id="TEST_RESULTS" toScope="page">
                <html:form action="/testFormTag" method="misc" target="_new">
                </html:form>
        </bean:define>
        <bean:define id="EXPECTED_RESULTS" toScope="page">
                <form name="testFormBean" method="misc" 
action="<%=response.encodeURL("/test/testFormTag.do")%>" target="_new">
                </form>
        </bean:define>
  </logic:equal>
  
  
  <% 
  String expected  = (String) pageContext.getAttribute("EXPECTED_RESULTS");
  String compareTo = (String) pageContext.getAttribute("TEST_RESULTS");
  
  if ((expected == null) || (expected == null)){
      Assert.fail("An invalid (or mispelled) test on this page was called.  Please 
verify that you've setup the tests (and spellings) correctly.");
  }
        
  Assert.assertEquals(compareTo, expected);
  %>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to