jmitchell 2003/03/13 17:19:34 Added: src/test/org/apache/struts/taglib/html TestLinkTag1.java TestLinkTag2.java Log: New tests Revision Changes Path 1.1 jakarta-struts/src/test/org/apache/struts/taglib/html/TestLinkTag1.java Index: TestLinkTag1.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/html/TestLinkTag1.java,v 1.1 2003/03/14 01:19:34 jmitchell Exp $ * $Revision: 1.1 $ * $Date: 2003/03/14 01:19:34 $ * * ==================================================================== * 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.HashMap; import java.util.Locale; import java.util.ArrayList; import java.util.StringTokenizer; 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; import org.apache.struts.util.LabelValueBean; /** * Suite of unit tests for the * <code>org.apache.struts.taglib.bean.LinkTag</code> class. * * @author James Mitchell */ public class TestLinkTag1 extends JspTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestLinkTag1(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[] {TestLinkTag1.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(TestLinkTag1.class); } private void runMyTest(String whichTest, String locale){ pageContext.setAttribute(Globals.LOCALE_KEY, new Locale(locale, locale), PageContext.SESSION_SCOPE); request.setAttribute("runTest", whichTest); try { pageContext.forward("/test/org/apache/struts/taglib/html/TestLinkTag1.jsp"); } catch (Exception e) { e.printStackTrace(); fail("There is a problem that is preventing the tests to continue!"); } } /* * Testing LinkTag. */ //--------Testing attributes using forward------ public void testLinkForward(){ runMyTest("testLinkForward", ""); } public void testLinkForwardAccesskey(){ runMyTest("testLinkForwardAccesskey", ""); } public void testLinkForwardAnchor(){ runMyTest("testLinkForwardAnchor", ""); } public void testLinkForwardIndexedArray(){ ArrayList lst = new ArrayList(); lst.add("Test Message"); pageContext.setAttribute("lst", lst, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedArray", ""); } public void testLinkForwardIndexedArrayProperty(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting(); ArrayList lst = new ArrayList(); lst.add("Test Message"); sbft.setList(lst); pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedArrayProperty", ""); } public void testLinkForwardIndexedMap(){ HashMap map = new HashMap(); map.put("tst1", "Test Message"); pageContext.setAttribute("lst", map, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedMap", ""); } public void testLinkForwardIndexedMapProperty(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting(); HashMap map = new HashMap(); map.put("tst1", "Test Message"); sbft.setMap(map); pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedMapProperty", ""); } public void testLinkForwardIndexedEnumeration(){ StringTokenizer st = new StringTokenizer("Test Message"); pageContext.setAttribute("lst", st, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedEnumeration", ""); } public void testLinkForwardIndexedEnumerationProperty(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting(); StringTokenizer st = new StringTokenizer("Test Message"); sbft.setEnumeration(st); pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedEnumerationProperty", ""); } public void testLinkForwardIndexedAlternateIdArray(){ ArrayList lst = new ArrayList(); lst.add("Test Message"); pageContext.setAttribute("lst", lst, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedAlternateIdArray", ""); } public void testLinkForwardIndexedAlternateIdArrayProperty(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting(); ArrayList lst = new ArrayList(); lst.add("Test Message"); sbft.setList(lst); pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedAlternateIdArrayProperty", ""); } public void testLinkForwardIndexedAlternateIdMap(){ HashMap map = new HashMap(); map.put("tst1", "Test Message"); pageContext.setAttribute("lst", map, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedAlternateIdMap", ""); } public void testLinkForwardIndexedAlternateIdMapProperty(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting(); HashMap map = new HashMap(); map.put("tst1", "Test Message"); sbft.setMap(map); pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedAlternateIdMapProperty", ""); } public void testLinkForwardIndexedAlternateIdEnumeration(){ StringTokenizer st = new StringTokenizer("Test Message"); pageContext.setAttribute("lst", st, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedAlternateIdEnumeration", ""); } public void testLinkForwardIndexedAlternateIdEnumerationProperty(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting(); StringTokenizer st = new StringTokenizer("Test Message"); sbft.setEnumeration(st); pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardIndexedAlternateIdEnumerationProperty", ""); } public void testLinkForwardLinkName(){ runMyTest("testLinkForwardLinkName", ""); } public void testLinkForwardNameNoScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); pageContext.setAttribute("paramMap", map, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardNameNoScope", ""); } public void testLinkForwardNamePropertyNoScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); SimpleBeanForTesting sbft = new SimpleBeanForTesting(map); pageContext.setAttribute("paramPropertyMap", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardNamePropertyNoScope", ""); } public void testLinkForwardNameApplicationScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); pageContext.setAttribute("paramMap", map, PageContext.APPLICATION_SCOPE); runMyTest("testLinkForwardNameApplicationScope", ""); } public void testLinkForwardNamePropertyApplicationScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); SimpleBeanForTesting sbft = new SimpleBeanForTesting(map); pageContext.setAttribute("paramPropertyMap", sbft, PageContext.APPLICATION_SCOPE); runMyTest("testLinkForwardNamePropertyApplicationScope", ""); } public void testLinkForwardNameSessionScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); pageContext.setAttribute("paramMap", map, PageContext.SESSION_SCOPE); runMyTest("testLinkForwardNameSessionScope", ""); } public void testLinkForwardNamePropertySessionScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); SimpleBeanForTesting sbft = new SimpleBeanForTesting(map); pageContext.setAttribute("paramPropertyMap", sbft, PageContext.SESSION_SCOPE); runMyTest("testLinkForwardNamePropertySessionScope", ""); } public void testLinkForwardNameRequestScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); pageContext.setAttribute("paramMap", map, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardNameRequestScope", ""); } public void testLinkForwardNamePropertyRequestScope(){ HashMap map = new HashMap(); map.put("param1","value1"); map.put("param2","value2"); map.put("param3","value3"); map.put("param4","value4"); SimpleBeanForTesting sbft = new SimpleBeanForTesting(map); pageContext.setAttribute("paramPropertyMap", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardNamePropertyRequestScope", ""); } } 1.1 jakarta-struts/src/test/org/apache/struts/taglib/html/TestLinkTag2.java Index: TestLinkTag2.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/html/TestLinkTag2.java,v 1.1 2003/03/14 01:19:34 jmitchell Exp $ * $Revision: 1.1 $ * $Date: 2003/03/14 01:19:34 $ * * ==================================================================== * 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; import org.apache.struts.util.LabelValueBean; /** * Suite of unit tests for the * <code>org.apache.struts.taglib.bean.FrameTag</code> class. * * @author James Mitchell */ public class TestLinkTag2 extends JspTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestLinkTag2(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[] {TestLinkTag2.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(TestLinkTag2.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/TestLinkTag2.jsp"); } catch (Exception e) { e.printStackTrace(); fail("There is a problem that is preventing the tests to continue!"); } } /* * Testing FrameTag. */ //--------Testing attributes using forward------ public void testLinkForwardOnblur(){ runMyTest("testLinkForwardOnblur", ""); } public void testLinkForwardOnclick(){ runMyTest("testLinkForwardOnclick", ""); } public void testLinkForwardOndblclick(){ runMyTest("testLinkForwardOndblclick", ""); } public void testLinkForwardOnfocus(){ runMyTest("testLinkForwardOnfocus", ""); } public void testLinkForwardOnkeydown(){ runMyTest("testLinkForwardOnkeydown", ""); } public void testLinkForwardOnkeypress(){ runMyTest("testLinkForwardOnkeypress", ""); } public void testLinkForwardOnkeyup(){ runMyTest("testLinkForwardOnkeyup", ""); } public void testLinkForwardOnmousedown(){ runMyTest("testLinkForwardOnmousedown", ""); } public void testLinkForwardOnmousemove(){ runMyTest("testLinkForwardOnmousemove", ""); } public void testLinkForwardOnmouseout(){ runMyTest("testLinkForwardOnmouseout", ""); } public void testLinkForwardOnmouseover(){ runMyTest("testLinkForwardOnmouseover", ""); } public void testLinkForwardOnmouseup(){ runMyTest("testLinkForwardOnmouseup", ""); } public void testLinkForwardParamIdParamNameNoScope(){ pageContext.setAttribute("paramName", "paramValue", PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardParamIdParamNameNoScope", ""); } public void testLinkForwardParamIdParamNameParamPropertyNoScope(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting("paramPropertyValue"); pageContext.setAttribute("testingParamProperty", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardParamIdParamNameParamPropertyNoScope", ""); } public void testLinkForwardParamIdParamNameApplicationScope(){ pageContext.setAttribute("paramName", "paramValue", PageContext.APPLICATION_SCOPE); runMyTest("testLinkForwardParamIdParamNameApplicationScope", ""); } public void testLinkForwardParamIdParamNameParamPropertyApplicationScope(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting("paramPropertyValue"); pageContext.setAttribute("testingParamProperty", sbft, PageContext.APPLICATION_SCOPE); runMyTest("testLinkForwardParamIdParamNameParamPropertyApplicationScope", ""); } public void testLinkForwardParamIdParamNameSessionScope(){ pageContext.setAttribute("paramName", "paramValue", PageContext.SESSION_SCOPE); runMyTest("testLinkForwardParamIdParamNameSessionScope", ""); } public void testLinkForwardParamIdParamNameParamPropertySessionScope(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting("paramPropertyValue"); pageContext.setAttribute("testingParamProperty", sbft, PageContext.SESSION_SCOPE); runMyTest("testLinkForwardParamIdParamNameParamPropertySessionScope", ""); } public void testLinkForwardParamIdParamNameRequestScope(){ pageContext.setAttribute("paramName", "paramValue", PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardParamIdParamNameRequestScope", ""); } public void testLinkForwardParamIdParamNameParamPropertyRequestScope(){ SimpleBeanForTesting sbft = new SimpleBeanForTesting("paramPropertyValue"); pageContext.setAttribute("testingParamProperty", sbft, PageContext.REQUEST_SCOPE); runMyTest("testLinkForwardParamIdParamNameParamPropertyRequestScope", ""); } public void testLinkForwardStyle(){ runMyTest("testLinkForwardStyle", ""); } public void testLinkForwardStyleClass(){ runMyTest("testLinkForwardStyleClass", ""); } public void testLinkForwardStyleId(){ runMyTest("testLinkForwardStyleId", ""); } public void testLinkForwardTabIndex(){ runMyTest("testLinkForwardTabIndex", ""); } public void testLinkForwardTarget(){ runMyTest("testLinkForwardTarget", ""); } public void testLinkForwardTitle(){ runMyTest("testLinkForwardTitle", ""); } public void testLinkForwardTitleKey(){ runMyTest("testLinkForwardTitleKey", ""); } public void testLinkForwardTransaction(){ pageContext.setAttribute(Globals.TRANSACTION_TOKEN_KEY, "Some_Token_Here", PageContext.SESSION_SCOPE); runMyTest("testLinkForwardTransaction", ""); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]