KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > bean > TestCookieTag


1 /*
2  * $Id: TestCookieTag.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.struts.taglib.bean;
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22 import org.apache.struts.taglib.TaglibTestBase;
23
24 /**
25  * Suite of unit tests for the
26  * <code>org.apache.struts.taglib.bean.CookieTag</code> class.
27  *
28  */

29 public class TestCookieTag extends TaglibTestBase {
30
31     protected final static String JavaDoc COOKIE_KEY = "COOKIE_KEY";
32     protected final static String JavaDoc COOKIE_VAL = "COOKIE_VAL";
33
34     /**
35      * Defines the testcase name for JUnit.
36      *
37      * @param theName the testcase's name.
38      */

39     public TestCookieTag(String JavaDoc theName) {
40         super(theName);
41     }
42
43     /**
44      * Start the tests.
45      *
46      * @param theArgs the arguments. Not used
47      */

48     public static void main(String JavaDoc[] theArgs) {
49         junit.awtui.TestRunner.main(new String JavaDoc[] {TestCookieTag.class.getName()});
50     }
51
52     /**
53      * @return a test suite (<code>TestSuite</code>) that includes all methods
54      * starting with "test"
55      */

56     public static Test suite() {
57         // All methods starting with "test" will be executed in the test suite.
58
return new TestSuite(TestCookieTag.class);
59     }
60
61
62
63     private void runMyTest(String JavaDoc whichTest) throws Exception JavaDoc {
64         request.setAttribute("runTest", whichTest);
65         pageContext.forward("/test/org/apache/struts/taglib/bean/TestCookieTag.jsp");
66     }
67
68     private void formatAndTest(String JavaDoc compare, String JavaDoc output) {
69         //fix for introduced carriage return / line feeds
70
output = replace(output,"\r","");
71         output = replace(output,"\n","");
72         output = output.trim();
73         //System.out.println("Testing [" + compare + "] == [" + output + "]");
74
assertEquals(compare, output);
75     }
76
77
78     /*
79      * Testing CookieTag, with Name specified in tags.
80      */

81     /* FIXME: Cactus does not send cookies?
82     public void beginCookieTagName(WebRequest webRequest) {
83                 webRequest.addCookie(COOKIE_KEY, COOKIE_VAL);
84         webRequest.addParameter("cacheId", "1");
85     }
86     public void testCookieTagName() throws Exception {
87         runMyTest("testCookieTagName");
88     }
89     public void endCookieTagName(WebResponse response){
90         formatAndTest(COOKIE_VAL, response.getText());
91     }
92     */

93
94
95     /*
96      * Testing CookieTag, with Name and Multiple specified in tags.
97      */

98     /* FIXME: Cactus does not send cookies?
99     public void beginCookieTagNameMultiple(WebRequest webRequest) {
100         for (int i = 0; i < 10; i++) {
101             webRequest.addCookie(COOKIE_KEY, COOKIE_VAL + i);
102         }
103         webRequest.addParameter("cacheId", "1");
104     }
105     public void testCookieTagNameMultiple() throws Exception {
106         runMyTest("testCookieTagNameMultiple");
107     }
108     public void endCookieTagNameMultiple(WebResponse response){
109         String compareTo = "";
110         for (int i = 0; i < 10; i++) {
111             compareTo += COOKIE_VAL + i;
112         }
113         formatAndTest(compareTo, response.getText());
114     }
115     */

116
117     /*
118      * Testing CookieTag, with Name and Value specified in tags.
119      */

120     /* FIXME: Cactus does not send cookies?
121     public void beginCookieTagNameValue(WebRequest webRequest) {
122         webRequest.addParameter("cacheId", "1");
123     }
124     public void testCookieTagNameValue() throws Exception {
125         runMyTest("testCookieTagNameValue");
126     }
127     public void endCookieTagNameValue(WebResponse response){
128         formatAndTest(COOKIE_VAL, response.getText());
129     }
130     */

131
132     /* FIXME: dummy test since all others commented out */
133     public void testDummy() {
134     }
135
136 }
137
Popular Tags