jmitchell 2003/03/06 21:40:59
Added: src/test/org/apache/struts/taglib/html TestHtmlTag.java
web/test/test/org/apache/struts/taglib/html TestHtmlTag.jsp
Log:
Adding more tests
Revision Changes Path
1.1
jakarta-struts/src/test/org/apache/struts/taglib/html/TestHtmlTag.java
Index: TestHtmlTag.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.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.HtmlTag</code> class.
*
* @author James Mitchell
*/
public class TestHtmlTag extends JspTestCase {
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public TestHtmlTag(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[] {TestHtmlTag.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(TestHtmlTag.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/TestHtmlTag.jsp");
}
catch (Exception e) {
e.printStackTrace();
fail("There is a problem that is preventing the tests to
continue!");
}
}
/*
* Testing HtmlTag.
*/
public void testHtml(){
runMyTest("testHtml", "");
}
public void testHtmlLocale1(){
runMyTest("testHtmlLocale1", "");
}
public void testHtmlLocale2(){
runMyTest("testHtmlLocale2", "");
}
public void testHtmlLocale3(){
runMyTest("testHtmlLocale3", "");
}
public void testHtmlLocale4(){
runMyTest("testHtmlLocale4", "");
}
public void testHtmlLocale5(){
runMyTest("testHtmlLocale5", "");
}
public void testHtmlLocale6(){
runMyTest("testHtmlLocale6", "");
}
public void testHtmlLocale_fr1(){
runMyTest("testHtmlLocale_fr1", "fr");
}
public void testHtmlLocale_fr2(){
runMyTest("testHtmlLocale_fr2", "fr");
}
public void testHtmlLocale_fr3(){
runMyTest("testHtmlLocale_fr3", "fr");
}
public void testHtmlLocale_fr4(){
runMyTest("testHtmlLocale_fr4", "fr");
}
public void testHtmlLocale_fr5(){
runMyTest("testHtmlLocale_fr5", "fr");
}
public void testHtmlLocale_fr6(){
runMyTest("testHtmlLocale_fr6", "fr");
}
public void testHtmlXhtml1(){
runMyTest("testHtmlXhtml1", "");
}
public void testHtmlXhtml2(){
runMyTest("testHtmlXhtml2", "");
}
public void testHtmlXhtml3(){
runMyTest("testHtmlXhtml3", "");
}
public void testHtmlXhtml4(){
runMyTest("testHtmlXhtml4", "");
}
public void testHtmlXhtml5(){
runMyTest("testHtmlXhtml5", "");
}
public void testHtmlXhtml6(){
runMyTest("testHtmlXhtml6", "");
}
public void testHtmlLocaleXhtml1(){
runMyTest("testHtmlLocaleXhtml1", "");
}
public void testHtmlLocaleXhtml2(){
runMyTest("testHtmlLocaleXhtml2", "");
}
public void testHtmlLocaleXhtml3(){
runMyTest("testHtmlLocaleXhtml3", "");
}
public void testHtmlLocaleXhtml_fr1(){
runMyTest("testHtmlLocaleXhtml_fr1", "fr");
}
public void testHtmlLocaleXhtml_fr2(){
runMyTest("testHtmlLocaleXhtml_fr2", "fr");
}
public void testHtmlLocaleXhtml_fr3(){
runMyTest("testHtmlLocaleXhtml_fr3", "fr");
}
}
1.1
jakarta-struts/web/test/test/org/apache/struts/taglib/html/TestHtmlTag.jsp
Index: TestHtmlTag.jsp
===================================================================
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<[EMAIL PROTECTED] import="junit.framework.Assert"%>
<[EMAIL PROTECTED] import="org.apache.struts.Globals"%>
<%@ 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="testHtml">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html>
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale1">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="true">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale2">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="True">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale3">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="TRUE">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale4">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="false">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale5">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="False">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale6">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="FALSE">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale_fr1">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="true">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html lang="fr">
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale_fr2">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="True">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html lang="fr">
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale_fr3">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="TRUE">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html lang="fr">
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale_fr4">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="false">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale_fr5">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="False">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocale_fr6">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="FALSE">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlXhtml1">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html xhtml="true">
<bean:write name="<%=Globals.XHTML_KEY%>" scope="page"/>
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html xmlns="http://www.w3.org/1999/xhtml">
true
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlXhtml2">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html xhtml="True">
<bean:write name="<%=Globals.XHTML_KEY%>" scope="page"/>
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html xmlns="http://www.w3.org/1999/xhtml">
true
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlXhtml3">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html xhtml="TRUE">
<bean:write name="<%=Globals.XHTML_KEY%>" scope="page"/>
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html xmlns="http://www.w3.org/1999/xhtml">
true
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlXhtml4">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html xhtml="false">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlXhtml5">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html xhtml="False">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlXhtml6">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html xhtml="FALSE">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocaleXhtml1">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="true" xhtml="false">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocaleXhtml2">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="true" xhtml="true">
<bean:write name="<%=Globals.XHTML_KEY%>" scope="page"/>
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html xmlns="http://www.w3.org/1999/xhtml">
true
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocaleXhtml3">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="false" xhtml="false">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocaleXhtml_fr1">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="true" xhtml="false">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html lang="fr">
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocaleXhtml_fr2">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="true" xhtml="true">
<bean:write name="<%=Globals.XHTML_KEY%>" scope="page"/>
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
true
</html>
</bean:define>
</logic:equal>
<logic:equal name="runTest" value="testHtmlLocaleXhtml_fr3">
<bean:define id="TEST_RESULTS" toScope="page">
<html:html locale="false" xhtml="false">
</html:html>
</bean:define>
<bean:define id="EXPECTED_RESULTS" toScope="page">
<html>
</html>
</bean:define>
</logic:equal>
<%
String expected = "";
String compareTo = "";
if (pageContext.getAttribute("EXPECTED_RESULTS") == null){
throw new 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]