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/02/07 01:32:06 UTC
cvs commit: jakarta-struts/src/test/org/apache/struts/taglib/logic SimpleBeanForTesting.java TestEmptyTag.java TestGreaterEqualTag.java TestLessEqualTag.java TestLessThanTag.java TestGreaterThanTag.java
jmitchell 2003/02/06 16:32:06
Modified: src/test/org/apache/struts/taglib/logic
TestGreaterThanTag.java
Added: src/test/org/apache/struts/taglib/logic
SimpleBeanForTesting.java TestEmptyTag.java
TestGreaterEqualTag.java TestLessEqualTag.java
TestLessThanTag.java
Log:
Adding more test cases. Almost finished with all the logic tags.
Revision Changes Path
1.2 +159 -15 jakarta-struts/src/test/org/apache/struts/taglib/logic/TestGreaterThanTag.java
Index: TestGreaterThanTag.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/logic/TestGreaterThanTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestGreaterThanTag.java 6 Feb 2003 04:36:30 -0000 1.1
+++ TestGreaterThanTag.java 7 Feb 2003 00:32:06 -0000 1.2
@@ -70,12 +70,13 @@
* @author James Mitchell
*/
public class TestGreaterThanTag extends JspTestCase {
+
protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
- protected final static String COOKIE_VAL = "5";
protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
- protected final static String HEADER_VAL = "5";
protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
- protected final static String PARAMETER_VAL = "5";
+ protected final static String GREATER_VAL = "6";
+ protected final static String LESSER_VAL = "4";
+
/**
* Defines the testcase name for JUnit.
@@ -110,21 +111,21 @@
* Create cookie for testCookiePresent method test.
*/
public void beginCookieGreaterThan(WebRequest testRequest) {
- testRequest.addCookie(COOKIE_KEY, COOKIE_VAL);
+ testRequest.addCookie(COOKIE_KEY, GREATER_VAL);
}
/**
* Create header for testHeaderGreaterThan method test.
*/
public void beginHeaderGreaterThan(WebRequest testRequest) {
- testRequest.addHeader(HEADER_KEY, HEADER_VAL);
+ testRequest.addHeader(HEADER_KEY, GREATER_VAL);
}
/**
* Create header for testParameterGreaterThan method test.
*/
public void beginParameterGreaterThan(WebRequest testRequest) {
- testRequest.addParameter(PARAMETER_KEY, PARAMETER_VAL);
+ testRequest.addParameter(PARAMETER_KEY, GREATER_VAL);
}
/**
@@ -132,13 +133,12 @@
*/
public void testCookieGreaterThan() throws ServletException, JspException {
GreaterThanTag gt = new GreaterThanTag();
- String testVal = "4";
gt.setPageContext(pageContext);
gt.setCookie(COOKIE_KEY);
- gt.setValue(testVal);
+ gt.setValue(LESSER_VAL);
assertTrue(
- "Cookie Value (" + COOKIE_VAL + ") is greater than test value (" + testVal + ")",
+ "Cookie Value (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")",
gt.condition());
}
@@ -147,13 +147,12 @@
*/
public void testHeaderGreaterThan() throws ServletException, JspException {
GreaterThanTag gt = new GreaterThanTag();
- String testVal = "4";
gt.setPageContext(pageContext);
gt.setHeader(HEADER_KEY);
- gt.setValue(testVal);
+ gt.setValue(LESSER_VAL);
assertTrue(
- "Header Value (" + HEADER_VAL + ") is greater than test value (" + testVal + ")",
+ "Header Value (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")",
gt.condition());
}
@@ -162,15 +161,160 @@
*/
public void testParameterGreaterThan() throws ServletException, JspException {
GreaterThanTag gt = new GreaterThanTag();
- String testVal = "4";
gt.setPageContext(pageContext);
gt.setParameter(PARAMETER_KEY);
- gt.setValue(testVal);
+ gt.setValue(LESSER_VAL);
+
+ assertTrue(
+ "Parameter Value (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")",
+ gt.condition());
+ }
+
+
+ /**
+ * Testing <code>GreaterThanTag</code> using name attribute in
+ * the application scope.
+ */
+ public void testApplicationScopeNameGreaterThan()
+ throws ServletException, JspException {
+
+ GreaterThanTag gt = new GreaterThanTag();
+
+ String testKey = "testApplicationScopeNameGreaterThan";
+ Integer itgr = new Integer(GREATER_VAL);
+
+ pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE);
+ gt.setPageContext(pageContext);
+ gt.setName(testKey);
+ gt.setScope("application");
+ gt.setValue(LESSER_VAL);
+
+ assertTrue(
+ "Application scope value from name (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")",
+ gt.condition());
+ }
+
+ /**
+ * Testing <code>GreaterThanTag</code> using name attribute in
+ * the session scope.
+ */
+ public void testSessionScopeNameGreaterThan()
+ throws ServletException, JspException {
+
+ GreaterThanTag gt = new GreaterThanTag();
+
+ String testKey = "testSessionScopeNameGreaterThan";
+ Integer itgr = new Integer(GREATER_VAL);
+
+ pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE);
+ gt.setPageContext(pageContext);
+ gt.setName(testKey);
+ gt.setScope("session");
+ gt.setValue(LESSER_VAL);
assertTrue(
- "Parameter Value (" + PARAMETER_VAL + ") is greater than test value (" + testVal + ")",
+ "Session scope value from name (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")",
gt.condition());
}
+
+ /**
+ * Testing <code>GreaterThanTag</code> using name attribute in
+ * the request scope.
+ */
+ public void testRequestScopeNameGreaterThan()
+ throws ServletException, JspException {
+
+ GreaterThanTag gt = new GreaterThanTag();
+
+ String testKey = "testRequestScopeNameGreaterThan";
+ Integer itgr = new Integer(GREATER_VAL);
+
+ pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE);
+ gt.setPageContext(pageContext);
+ gt.setName(testKey);
+ gt.setScope("request");
+ gt.setValue(LESSER_VAL);
+
+ assertTrue(
+ "Request scope value from name (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")",
+ gt.condition());
+ }
+
+
+
+
+ /**
+ * Testing <code>GreaterThanTag</code> using name and property attribute in
+ * the application scope.
+ */
+ public void testApplicationScopePropertyGreaterThan()
+ throws ServletException, JspException {
+
+ GreaterThanTag gt = new GreaterThanTag();
+
+ String testKey = "testApplicationScopePropertyGreaterThan";
+ LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
+
+ pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE);
+ gt.setPageContext(pageContext);
+ gt.setName(testKey);
+ gt.setScope("application");
+ gt.setProperty("value");
+ gt.setValue(LESSER_VAL);
+
+ assertTrue(
+ "Value (" + LESSER_VAL + ") is greater than value (" + GREATER_VAL + ")",
+ gt.condition());
+ }
+
+ /**
+ * Testing <code>GreaterThanTag</code> using name and property attribute in
+ * the session scope.
+ */
+ public void testSessionScopePropertyGreaterThan()
+ throws ServletException, JspException {
+
+ GreaterThanTag gt = new GreaterThanTag();
+
+ String testKey = "testSessionScopePropertyGreaterThan";
+ LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
+
+ pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE);
+ gt.setPageContext(pageContext);
+ gt.setName(testKey);
+ gt.setScope("session");
+ gt.setProperty("value");
+ gt.setValue(LESSER_VAL);
+
+ assertTrue(
+ "Value (" + LESSER_VAL + ") is greater than value (" + GREATER_VAL + ")",
+ gt.condition());
+ }
+
+ /**
+ * Testing <code>GreaterThanTag</code> using name and property attribute in
+ * the request scope.
+ */
+ public void testRequestScopePropertyGreaterThan()
+ throws ServletException, JspException {
+
+ GreaterThanTag gt = new GreaterThanTag();
+
+ String testKey = "testRequestScopePropertyGreaterThan";
+ LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
+
+ pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE);
+ gt.setPageContext(pageContext);
+ gt.setName(testKey);
+ gt.setScope("request");
+ gt.setProperty("value");
+ gt.setValue(LESSER_VAL);
+
+ assertTrue(
+ "Value (" + LESSER_VAL + ") is greater than value (" + GREATER_VAL + ")",
+ gt.condition());
+ }
+
}
1.1 jakarta-struts/src/test/org/apache/struts/taglib/logic/SimpleBeanForTesting.java
Index: SimpleBeanForTesting.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 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.logic;
import java.util.List;
import java.util.Map;
/**
* Simple bean for unit tests.
*
* @author James Mitchell
*/
public class SimpleBeanForTesting {
public SimpleBeanForTesting(){
super();
}
public SimpleBeanForTesting(List lst, Map map){
this.lst = lst;
this.map = map;
}
private String string;
private List lst;
private Map map;
/**
* Returns the lst.
* @return List
*/
public List getList() {
return lst;
}
/**
* Returns the map.
* @return Map
*/
public Map getMap() {
return map;
}
/**
* Sets the lst.
* @param lst The lst to set
*/
public void setList(List lst) {
this.lst = lst;
}
/**
* Sets the map.
* @param map The map to set
*/
public void setMap(Map map) {
this.map = map;
}
/**
* Returns the string.
* @return String
*/
public String getString() {
return string;
}
/**
* Sets the string.
* @param string The string to set
*/
public void setString(String string) {
this.string = string;
}
}
1.1 jakarta-struts/src/test/org/apache/struts/taglib/logic/TestEmptyTag.java
Index: TestEmptyTag.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 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.logic;
import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.ServletException;
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.cactus.WebRequest;
import org.apache.struts.util.LabelValueBean;
/**
* Suite of unit tests for the
* <code>org.apache.struts.taglib.logic.EmptyTag</code> class.
*
* @author James Mitchell
*/
public class TestEmptyTag extends JspTestCase {
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public TestEmptyTag(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[] {TestEmptyTag.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(TestEmptyTag.class);
}
private void runNameTest(String testKey, EmptyTag et,
Object o, int scope, String whichScope, boolean condition, boolean useProperty, String property)
throws ServletException, JspException {
pageContext.setAttribute(testKey, o, scope);
et.setPageContext(pageContext);
et.setName(testKey);
if (useProperty){
et.setProperty(property);
}
et.setScope(whichScope);
assertEquals(
"Testing " + testKey + " with EmtpyTag in " + whichScope + " scope",
condition,
et.condition());
}
/**
* Testing <code>EmptyTag</code> using name attribute in
* the application scope.
*/
public void testEmptyTagUsingName()
throws ServletException, JspException {
String tst = "";
runNameTest("testStringEmptyString", new EmptyTag(), tst, PageContext.APPLICATION_SCOPE, "application", true, false, null);
runNameTest("testStringEmptyString", new EmptyTag(), tst, PageContext.SESSION_SCOPE, "session", true, false, null);
runNameTest("testStringEmptyString", new EmptyTag(), tst, PageContext.REQUEST_SCOPE, "request", true, false, null);
tst = "hello";
runNameTest("testStringNotEmpty", new EmptyTag(), tst, PageContext.APPLICATION_SCOPE, "application", false, false, null);
runNameTest("testStringNotEmpty", new EmptyTag(), tst, PageContext.SESSION_SCOPE, "session", false, false, null);
runNameTest("testStringNotEmpty", new EmptyTag(), tst, PageContext.REQUEST_SCOPE, "request", false, false, null);
// Testing ArrayList
ArrayList lst = new ArrayList();
runNameTest("testArrayListEmpty", new EmptyTag(), lst, PageContext.APPLICATION_SCOPE, "application", true, false, null);
runNameTest("testArrayListEmpty", new EmptyTag(), lst, PageContext.SESSION_SCOPE, "session", true, false, null);
runNameTest("testArrayListEmpty", new EmptyTag(), lst, PageContext.REQUEST_SCOPE, "request", true, false, null);
lst.add(0, "test");
runNameTest("testArrayListNotEmpty", new EmptyTag(), lst, PageContext.APPLICATION_SCOPE, "application", false, false, null);
runNameTest("testArrayListNotEmpty", new EmptyTag(), lst, PageContext.SESSION_SCOPE, "session", false, false, null);
runNameTest("testArrayListNotEmpty", new EmptyTag(), lst, PageContext.REQUEST_SCOPE, "request", false, false, null);
// Testing HashMap
HashMap map = new HashMap();
runNameTest("testMapEmpty", new EmptyTag(), map, PageContext.APPLICATION_SCOPE, "application", true, false, null);
runNameTest("testMapEmpty", new EmptyTag(), map, PageContext.SESSION_SCOPE, "session", true, false, null);
runNameTest("testMapEmpty", new EmptyTag(), map, PageContext.REQUEST_SCOPE, "request", true, false, null);
map.put("testKey", "test");
runNameTest("testMapNotEmpty", new EmptyTag(), map, PageContext.APPLICATION_SCOPE, "application", false, false, null);
runNameTest("testMapNotEmpty", new EmptyTag(), map, PageContext.SESSION_SCOPE, "session", false, false, null);
runNameTest("testMapNotEmpty", new EmptyTag(), map, PageContext.REQUEST_SCOPE, "request", false, false, null);
}
/**
* Testing <code>EmptyTag</code> using name attribute in
* the application scope.
*/
public void testEmptyTagUsingProperty()
throws ServletException, JspException {
LabelValueBean lvb = new LabelValueBean(null, null);
runNameTest("testStringEmptyString", new EmptyTag(), lvb, PageContext.APPLICATION_SCOPE, "application", true, true, "value");
runNameTest("testStringEmptyString", new EmptyTag(), lvb, PageContext.SESSION_SCOPE, "session", true, true, "value");
runNameTest("testStringEmptyString", new EmptyTag(), lvb, PageContext.REQUEST_SCOPE, "request", true, true, "value");
lvb.setValue("");
runNameTest("testStringNotEmpty", new EmptyTag(), lvb, PageContext.APPLICATION_SCOPE, "application", true, true, "value");
runNameTest("testStringNotEmpty", new EmptyTag(), lvb, PageContext.SESSION_SCOPE, "session", true, true, "value");
runNameTest("testStringNotEmpty", new EmptyTag(), lvb, PageContext.REQUEST_SCOPE, "request", true, true, "value");
lvb.setValue("hello");
runNameTest("testStringNotEmpty", new EmptyTag(), lvb, PageContext.APPLICATION_SCOPE, "application", false, true, "value");
runNameTest("testStringNotEmpty", new EmptyTag(), lvb, PageContext.SESSION_SCOPE, "session", false, true, "value");
runNameTest("testStringNotEmpty", new EmptyTag(), lvb, PageContext.REQUEST_SCOPE, "request", false, true, "value");
// Testing ArrayList
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
ArrayList lst = new ArrayList();
sbft.setList(lst);
runNameTest("testArrayListEmpty", new EmptyTag(), sbft, PageContext.APPLICATION_SCOPE, "application", true, true, "list");
runNameTest("testArrayListEmpty", new EmptyTag(), sbft, PageContext.SESSION_SCOPE, "session", true, true, "list");
runNameTest("testArrayListEmpty", new EmptyTag(), sbft, PageContext.REQUEST_SCOPE, "request", true, true, "list");
lst.add(0, "test");
runNameTest("testArrayListNotEmpty", new EmptyTag(), sbft, PageContext.APPLICATION_SCOPE, "application", false, true, "list");
runNameTest("testArrayListNotEmpty", new EmptyTag(), sbft, PageContext.SESSION_SCOPE, "session", false, true, "list");
runNameTest("testArrayListNotEmpty", new EmptyTag(), sbft, PageContext.REQUEST_SCOPE, "request", false, true, "list");
// Testing HashMap
HashMap map = new HashMap();
sbft.setMap(map);
runNameTest("testMapEmpty", new EmptyTag(), sbft, PageContext.APPLICATION_SCOPE, "application", true, true, "map");
runNameTest("testMapEmpty", new EmptyTag(), sbft, PageContext.SESSION_SCOPE, "session", true, true, "map");
runNameTest("testMapEmpty", new EmptyTag(), sbft, PageContext.REQUEST_SCOPE, "request", true, true, "map");
map.put("testKey", "test");
runNameTest("testMapNotEmpty", new EmptyTag(), sbft, PageContext.APPLICATION_SCOPE, "application", false, true, "map");
runNameTest("testMapNotEmpty", new EmptyTag(), sbft, PageContext.SESSION_SCOPE, "session", false, true, "map");
runNameTest("testMapNotEmpty", new EmptyTag(), sbft, PageContext.REQUEST_SCOPE, "request", false, true, "map");
}
}
1.1 jakarta-struts/src/test/org/apache/struts/taglib/logic/TestGreaterEqualTag.java
Index: TestGreaterEqualTag.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 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.logic;
import javax.servlet.ServletException;
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.cactus.WebRequest;
import org.apache.struts.util.LabelValueBean;
/**
* Suite of unit tests for the
* <code>org.apache.struts.taglib.logic.GreaterEqualTag</code> class.
*
* @author James Mitchell
*/
public class TestGreaterEqualTag extends JspTestCase {
protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
protected final static String GREATER_VAL = "5";
protected final static String LESSER_VAL = "5";
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public TestGreaterEqualTag(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[] {TestGreaterEqualTag.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(TestGreaterEqualTag.class);
}
//----- Test initApplication() method --------------------------------------
/**
* Create cookie for testCookiePresent method test.
*/
public void beginCookieGreaterEqual(WebRequest testRequest) {
testRequest.addCookie(COOKIE_KEY, GREATER_VAL);
}
/**
* Create header for testHeaderGreaterEqual method test.
*/
public void beginHeaderGreaterEqual(WebRequest testRequest) {
testRequest.addHeader(HEADER_KEY, GREATER_VAL);
}
/**
* Create header for testParameterGreaterEqual method test.
*/
public void beginParameterGreaterEqual(WebRequest testRequest) {
testRequest.addParameter(PARAMETER_KEY, GREATER_VAL);
}
/**
* Verify the value stored in a cookie using <code>GreaterEqualTag</code>.
*/
public void testCookieGreaterEqual() throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
ge.setPageContext(pageContext);
ge.setCookie(COOKIE_KEY);
ge.setValue(LESSER_VAL);
assertTrue(
"Cookie Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Verify the value stored in header using <code>GreaterEqualTag</code>.
*/
public void testHeaderGreaterEqual() throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
ge.setPageContext(pageContext);
ge.setHeader(HEADER_KEY);
ge.setValue(LESSER_VAL);
assertTrue(
"Header Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Verify the value stored in parameter using <code>GreaterEqualTag</code>.
*/
public void testParameterGreaterEqual() throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
ge.setPageContext(pageContext);
ge.setParameter(PARAMETER_KEY);
ge.setValue(LESSER_VAL);
assertTrue(
"Parameter Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>GreaterEqualTag</code> using name attribute in
* the application scope.
*/
public void testApplicationScopeNameGreaterEqual()
throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
String testKey = "testApplicationScopeNameGreaterEqual";
Integer itgr = new Integer(GREATER_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("application");
ge.setValue(LESSER_VAL);
assertTrue(
"Application scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>GreaterEqualTag</code> using name attribute in
* the session scope.
*/
public void testSessionScopeNameGreaterEqual()
throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
String testKey = "testSessionScopeNameGreaterEqual";
Integer itgr = new Integer(GREATER_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("session");
ge.setValue(LESSER_VAL);
assertTrue(
"Session scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>GreaterEqualTag</code> using name attribute in
* the request scope.
*/
public void testRequestScopeNameGreaterEqual()
throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
String testKey = "testRequestScopeNameGreaterEqual";
Integer itgr = new Integer(GREATER_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("request");
ge.setValue(LESSER_VAL);
assertTrue(
"Request scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>GreaterEqualTag</code> using name and property attribute in
* the application scope.
*/
public void testApplicationScopePropertyGreaterEqual()
throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
String testKey = "testApplicationScopePropertyGreaterEqual";
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("application");
ge.setProperty("value");
ge.setValue(LESSER_VAL);
assertTrue(
"Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
ge.condition());
}
/**
* Testing <code>GreaterEqualTag</code> using name and property attribute in
* the session scope.
*/
public void testSessionScopePropertyGreaterEqual()
throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
String testKey = "testSessionScopePropertyGreaterEqual";
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("session");
ge.setProperty("value");
ge.setValue(LESSER_VAL);
assertTrue(
"Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
ge.condition());
}
/**
* Testing <code>GreaterEqualTag</code> using name and property attribute in
* the request scope.
*/
public void testRequestScopePropertyGreaterEqual()
throws ServletException, JspException {
GreaterEqualTag ge = new GreaterEqualTag();
String testKey = "testRequestScopePropertyGreaterEqual";
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("request");
ge.setProperty("value");
ge.setValue(LESSER_VAL);
assertTrue(
"Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
ge.condition());
}
}
1.1 jakarta-struts/src/test/org/apache/struts/taglib/logic/TestLessEqualTag.java
Index: TestLessEqualTag.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 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.logic;
import javax.servlet.ServletException;
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.cactus.WebRequest;
import org.apache.struts.util.LabelValueBean;
/**
* Suite of unit tests for the
* <code>org.apache.struts.taglib.logic.LessEqualTag</code> class.
*
* @author James Mitchell
*/
public class TestLessEqualTag extends JspTestCase {
protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
protected final static String GREATER_VAL = "5";
protected final static String LESSER_VAL = "5";
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public TestLessEqualTag(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[] {TestLessEqualTag.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(TestLessEqualTag.class);
}
//----- Test initApplication() method --------------------------------------
/**
* Create cookie for testCookiePresent method test.
*/
public void beginCookieLessEqual(WebRequest testRequest) {
testRequest.addCookie(COOKIE_KEY, GREATER_VAL);
}
/**
* Create header for testHeaderLessEqual method test.
*/
public void beginHeaderLessEqual(WebRequest testRequest) {
testRequest.addHeader(HEADER_KEY, GREATER_VAL);
}
/**
* Create header for testParameterLessEqual method test.
*/
public void beginParameterLessEqual(WebRequest testRequest) {
testRequest.addParameter(PARAMETER_KEY, GREATER_VAL);
}
/**
* Verify the value stored in a cookie using <code>LessEqualTag</code>.
*/
public void testCookieLessEqual() throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
ge.setPageContext(pageContext);
ge.setCookie(COOKIE_KEY);
ge.setValue(LESSER_VAL);
assertTrue(
"Cookie Value (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Verify the value stored in header using <code>LessEqualTag</code>.
*/
public void testHeaderLessEqual() throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
ge.setPageContext(pageContext);
ge.setHeader(HEADER_KEY);
ge.setValue(LESSER_VAL);
assertTrue(
"Header Value (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Verify the value stored in parameter using <code>LessEqualTag</code>.
*/
public void testParameterLessEqual() throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
ge.setPageContext(pageContext);
ge.setParameter(PARAMETER_KEY);
ge.setValue(LESSER_VAL);
assertTrue(
"Parameter Value (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessEqualTag</code> using name attribute in
* the application scope.
*/
public void testApplicationScopeNameLessEqual()
throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
String testKey = "testApplicationScopeNameLessEqual";
Integer itgr = new Integer(GREATER_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("application");
ge.setValue(LESSER_VAL);
assertTrue(
"Application scope value from name (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessEqualTag</code> using name attribute in
* the session scope.
*/
public void testSessionScopeNameLessEqual()
throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
String testKey = "testSessionScopeNameLessEqual";
Integer itgr = new Integer(GREATER_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("session");
ge.setValue(LESSER_VAL);
assertTrue(
"Session scope value from name (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessEqualTag</code> using name attribute in
* the request scope.
*/
public void testRequestScopeNameLessEqual()
throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
String testKey = "testRequestScopeNameLessEqual";
Integer itgr = new Integer(GREATER_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("request");
ge.setValue(LESSER_VAL);
assertTrue(
"Request scope value from name (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessEqualTag</code> using name and property attribute in
* the application scope.
*/
public void testApplicationScopePropertyLessEqual()
throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
String testKey = "testApplicationScopePropertyLessEqual";
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("application");
ge.setProperty("value");
ge.setValue(LESSER_VAL);
assertTrue(
"Value (" + LESSER_VAL + ") is less than or equal to value (" + GREATER_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessEqualTag</code> using name and property attribute in
* the session scope.
*/
public void testSessionScopePropertyLessEqual()
throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
String testKey = "testSessionScopePropertyLessEqual";
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("session");
ge.setProperty("value");
ge.setValue(LESSER_VAL);
assertTrue(
"Value (" + LESSER_VAL + ") is less than or equal to value (" + GREATER_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessEqualTag</code> using name and property attribute in
* the request scope.
*/
public void testRequestScopePropertyLessEqual()
throws ServletException, JspException {
LessEqualTag ge = new LessEqualTag();
String testKey = "testRequestScopePropertyLessEqual";
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("request");
ge.setProperty("value");
ge.setValue(LESSER_VAL);
assertTrue(
"Value (" + LESSER_VAL + ") is less than or equal to value (" + GREATER_VAL + ")",
ge.condition());
}
}
1.1 jakarta-struts/src/test/org/apache/struts/taglib/logic/TestLessThanTag.java
Index: TestLessThanTag.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 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.logic;
import javax.servlet.ServletException;
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.cactus.WebRequest;
import org.apache.struts.util.LabelValueBean;
/**
* Suite of unit tests for the
* <code>org.apache.struts.taglib.logic.LessThanTag</code> class.
*
* @author James Mitchell
*/
public class TestLessThanTag extends JspTestCase {
protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
protected final static String COMPARE_VAL = "4";
protected final static String COMPARE_TO_VAL = "5";
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public TestLessThanTag(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[] {TestLessThanTag.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(TestLessThanTag.class);
}
//----- Test initApplication() method --------------------------------------
/**
* Create cookie for testCookiePresent method test.
*/
public void beginCookieLessThan(WebRequest testRequest) {
testRequest.addCookie(COOKIE_KEY, COMPARE_VAL);
}
/**
* Create header for testHeaderLessThan method test.
*/
public void beginHeaderLessThan(WebRequest testRequest) {
testRequest.addHeader(HEADER_KEY, COMPARE_VAL);
}
/**
* Create header for testParameterLessThan method test.
*/
public void beginParameterLessThan(WebRequest testRequest) {
testRequest.addParameter(PARAMETER_KEY, COMPARE_VAL);
}
/**
* Verify the value stored in a cookie using <code>LessThanTag</code>.
*/
public void testCookieLessThan() throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
ge.setPageContext(pageContext);
ge.setCookie(COOKIE_KEY);
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Cookie Value (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")",
ge.condition());
}
/**
* Verify the value stored in header using <code>LessThanTag</code>.
*/
public void testHeaderLessThan() throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
ge.setPageContext(pageContext);
ge.setHeader(HEADER_KEY);
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Header Value (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")",
ge.condition());
}
/**
* Verify the value stored in parameter using <code>LessThanTag</code>.
*/
public void testParameterLessThan() throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
ge.setPageContext(pageContext);
ge.setParameter(PARAMETER_KEY);
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Parameter Value (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessThanTag</code> using name attribute in
* the application scope.
*/
public void testApplicationScopeNameLessThan()
throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
String testKey = "testApplicationScopeNameLessThan";
Integer itgr = new Integer(COMPARE_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("application");
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Application scope value from name (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessThanTag</code> using name attribute in
* the session scope.
*/
public void testSessionScopeNameLessThan()
throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
String testKey = "testSessionScopeNameLessThan";
Integer itgr = new Integer(COMPARE_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("session");
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Session scope value from name (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessThanTag</code> using name attribute in
* the request scope.
*/
public void testRequestScopeNameLessThan()
throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
String testKey = "testRequestScopeNameLessThan";
Integer itgr = new Integer(COMPARE_VAL);
pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("request");
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Request scope value from name (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessThanTag</code> using name and property attribute in
* the application scope.
*/
public void testApplicationScopePropertyLessThan()
throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
String testKey = "testApplicationScopePropertyLessThan";
LabelValueBean lvb = new LabelValueBean("The Key", COMPARE_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("application");
ge.setProperty("value");
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Value (" + COMPARE_TO_VAL + ") is less than value (" + COMPARE_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessThanTag</code> using name and property attribute in
* the session scope.
*/
public void testSessionScopePropertyLessThan()
throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
String testKey = "testSessionScopePropertyLessThan";
LabelValueBean lvb = new LabelValueBean("The Key", COMPARE_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("session");
ge.setProperty("value");
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Value (" + COMPARE_TO_VAL + ") is less than value (" + COMPARE_VAL + ")",
ge.condition());
}
/**
* Testing <code>LessThanTag</code> using name and property attribute in
* the request scope.
*/
public void testRequestScopePropertyLessThan()
throws ServletException, JspException {
LessThanTag ge = new LessThanTag();
String testKey = "testRequestScopePropertyLessThan";
LabelValueBean lvb = new LabelValueBean("The Key", COMPARE_VAL);
pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE);
ge.setPageContext(pageContext);
ge.setName(testKey);
ge.setScope("request");
ge.setProperty("value");
ge.setValue(COMPARE_TO_VAL);
assertTrue(
"Value (" + COMPARE_TO_VAL + ") is less than value (" + COMPARE_VAL + ")",
ge.condition());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org