You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2002/06/21 07:24:28 UTC
DO NOT REPLY [Bug 10098] New: -
[PATCH] More logic:equals tag tests
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10098>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10098
[PATCH] More logic:equals tag tests
Summary: [PATCH] More logic:equals tag tests
Product: Struts
Version: 1.1 Beta 1
Platform: Other
OS/Version: Other
Status: NEW
Severity: Enhancement
Priority: Other
Component: Test
AssignedTo: struts-dev@jakarta.apache.org
ReportedBy: dplante@pacbell.net
--- TestEqualTag.java.orig Thu Jun 20 02:31:46 2002
+++ TestEqualTag.java Thu Jun 20 22:10:40 2002
@@ -55,6 +55,8 @@
package org.apache.struts.taglib.logic;
import javax.servlet.*;
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.PageContext;
import junit.framework.*;
import org.apache.cactus.*;
@@ -62,10 +64,21 @@
/**
* Suite of unit tests for the
* <code>org.apache.struts.taglib.logic.EqualTag</code> class.
- *
+ * @author Dominique Plante
* @author David Winterfeldt
*/
public class TestEqualTag 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 EqualTag et = null;
+ protected static String testStringKey;
+ protected static String testStringValue;
+ protected static String testStringValue1;
+ protected static String testIntegerKey;
+ protected static Integer testIntegerValue;
+ protected static Integer testIntegerValue1;
+
/**
* Defines the testcase name for JUnit.
*
@@ -93,21 +106,116 @@
return new TestSuite(TestEqualTag.class);
}
- //----- Test initApplication() method ------------------------------------
--
+ public void setUp()
+ {
+ testStringKey = "testString";
+ testStringValue = "abc";
+ testStringValue1 = "abcd";
+ testIntegerKey = "testInteger";
+ testIntegerValue = new Integer(21);
+ testIntegerValue1 = new Integer(testIntegerValue.intValue() + 1);
+
+ et = new EqualTag();
+ et.setPageContext(pageContext);
+ }
+
+ public void tearDown()
+ {
+ et = null;
+ }
+
+ /**
+ * Create cookie for testCookieStringEquals method test.
+ */
+ public void beginCookieStringEquals(WebRequest testRequest) {
+ testRequest.addCookie(COOKIE_KEY, "abc");
+ }
+
+ public void testCookieStringEquals() throws ServletException,
javax.servlet.jsp.JspException {
+ et.setCookie(COOKIE_KEY);
+ et.setValue(testStringValue);
+
+ assertEquals("Cookie string equals comparison", true, et.condition(0,
0));
+ }
+
+ /**
+ * Create cookie for testCookieStringNotEquals method test.
+ */
+ public void beginCookieStringNotEquals(WebRequest testRequest) {
+ testRequest.addCookie(COOKIE_KEY, "abc");
+ }
+
+ public void testCookieStringNotEquals() throws ServletException,
javax.servlet.jsp.JspException {
+ et.setCookie(COOKIE_KEY);
+ et.setValue(testStringValue1);
+
+ assertEquals("Cookie string not equals comparison", false,
et.condition(0, 0));
+ }
+
+ /**
+ * Create cookie for testHeaderStringEquals method test.
+ */
+ public void beginHeaderStringEquals(WebRequest testRequest) {
+ testRequest.addHeader(COOKIE_KEY, "abc");
+ }
+
+ public void testHeaderStringEquals() throws ServletException,
javax.servlet.jsp.JspException {
+ et.setHeader(COOKIE_KEY);
+ et.setValue(testStringValue);
+
+ assertEquals("Header string equals comparison", true, et.condition(0,
0));
+ }
+
+ /**
+ * Create cookie for testHeaderStringNotEquals method test.
+ */
+ public void beginHeaderStringNotEquals(WebRequest testRequest) {
+ testRequest.addHeader(COOKIE_KEY, "abc");
+ }
+
+ public void testHeaderStringNotEquals() throws ServletException,
javax.servlet.jsp.JspException {
+ et.setHeader(COOKIE_KEY);
+ et.setValue(testStringValue1);
+
+ assertEquals("Header string not equals comparison", false,
et.condition(0, 0));
+ }
+
+ /**
+ * Create cookie for testParameterStringEquals method test.
+ */
+ public void beginParameterStringEquals(WebRequest testRequest) {
+ testRequest.addParameter(PARAMETER_KEY, "abc");
+ }
+
+ public void testParameterStringEquals() throws ServletException,
javax.servlet.jsp.JspException {
+ et.setParameter(PARAMETER_KEY);
+ et.setValue(testStringValue);
+
+ assertEquals("Parameter string equals comparison", true, et.condition
(0, 0));
+ }
+
+ /**
+ * Create cookie for testParameterStringNotEquals method test.
+ */
+ public void beginParameterStringNotEquals(WebRequest testRequest) {
+ testRequest.addParameter(PARAMETER_KEY, "abc");
+ }
+
+ public void testParameterStringNotEquals() throws ServletException,
javax.servlet.jsp.JspException {
+ et.setParameter(PARAMETER_KEY);
+ et.setValue(testStringValue1);
+
+ assertEquals("Parameter string not equals comparison", false,
et.condition(0, 0));
+ }
/**
* Verify that two <code>String</code>s match using the
<code>EqualTag</code>.
*/
public void testStringEquals() throws ServletException,
javax.servlet.jsp.JspException {
- EqualTag et = new EqualTag();
- String testStringKey = "testString";
- String testStringValue = "abc";
-
request.setAttribute(testStringKey, testStringValue);
- et.setPageContext(pageContext);
- et.setName(testStringKey);
- et.setValue(testStringValue);
-
+ et.setName(testStringKey);
+ et.setValue(testStringValue);
+ System.out.println("testing");
assertEquals("String equals comparison", true, et.condition(0, 0));
}
@@ -115,16 +223,10 @@
* Verify that two <code>String</code>s do not match using the
<code>EqualTag</code>.
*/
public void testStringNotEquals() throws ServletException,
javax.servlet.jsp.JspException {
- EqualTag et = new EqualTag();
- String testStringKey = "testString";
- String testStringValue = "abc";
- String testStringValue1 = "abcd";
-
request.setAttribute(testStringKey, testStringValue);
- et.setPageContext(pageContext);
- et.setName(testStringKey);
- et.setValue(testStringValue1);
-
+ et.setName(testStringKey);
+ et.setValue(testStringValue1);
+
assertEquals("String not equals comparison", false, et.condition(0,
0));
}
@@ -133,15 +235,10 @@
* match using the <code>EqualTag</code>.
*/
public void testIntegerEquals() throws ServletException,
javax.servlet.jsp.JspException {
- EqualTag et = new EqualTag();
- String testIntegerKey = "testInteger";
- Integer testIntegerValue = new Integer(21);
-
request.setAttribute(testIntegerKey, testIntegerValue);
- et.setPageContext(pageContext);
- et.setName(testIntegerKey);
- et.setValue(testIntegerValue.toString());
-
+ et.setName(testIntegerKey);
+ et.setValue(testIntegerValue.toString());
+
assertEquals("Integer equals comparison", true, et.condition(0, 0));
}
@@ -149,17 +246,40 @@
* Verify that two <code>String</code>s do not match using the
<code>EqualTag</code>.
*/
public void testIntegerNotEquals() throws ServletException,
javax.servlet.jsp.JspException {
- EqualTag et = new EqualTag();
- String testIntegerKey = "testInteger";
- Integer testIntegerValue = new Integer(21);
- Integer testIntegerValue1 = new Integer(testIntegerValue.intValue() +
1);
-
request.setAttribute(testIntegerKey, testIntegerValue);
- et.setPageContext(pageContext);
- et.setName(testIntegerKey);
- et.setValue(testIntegerValue1.toString());
-
+ et.setName(testIntegerKey);
+ et.setValue(testIntegerValue1.toString());
+
assertEquals("Integer equals comparison", false, et.condition(0, 0));
}
+ /**
+ * Verify that there is an application scope String in scope using the
<code>EqualTag</code>.
+ */
+ public void testApplicationScopeStringEquals() throws ServletException,
javax.servlet.jsp.JspException {
+ String testKey = "testApplicationScopeStringEquals";
+
+ pageContext.setAttribute(testKey, testStringValue,
PageContext.APPLICATION_SCOPE);
+ et.setPageContext(pageContext);
+ et.setName(testKey);
+ et.setScope("application");
+ et.setValue(testStringValue);
+
+ assertEquals("String in application scope equals", true, et.condition
(0, 0));
+ }
+
+ /**
+ * Verify that there is an application scope String that is not equal
using the <code>EqualTag</code>.
+ */
+ public void testApplicationScopeStringNotEquals() throws
ServletException, javax.servlet.jsp.JspException {
+ String testKey = "testApplicationScopeStringNotEquals";
+
+ pageContext.setAttribute(testKey, testStringValue,
PageContext.APPLICATION_SCOPE);
+ et.setPageContext(pageContext);
+ et.setName(testKey);
+ et.setScope("application");
+ et.setValue(testStringValue1);
+
+ assertEquals("String in application scope not equals", false,
et.condition(0, 0));
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>