KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestParameterTag.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 java.io.IOException JavaDoc;
21
22 import javax.servlet.ServletException JavaDoc;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.apache.cactus.WebRequest;
28 import org.apache.cactus.WebResponse;
29 import org.apache.struts.taglib.TaglibTestBase;
30
31 /**
32  * Suite of unit tests for the
33  * <code>org.apache.struts.taglib.bean.ParameterTag</code> class.
34  *
35  */

36 public class TestParameterTag extends TaglibTestBase {
37     
38     protected final static String JavaDoc PARAMETERTAG_KEY = "PARAMETERTAG_KEY";
39     protected final static String JavaDoc PARAMETERTAG_VAL = "PARAMETERTAG_VAL";
40
41     /**
42      * Defines the testcase name for JUnit.
43      *
44      * @param theName the testcase's name.
45      */

46     public TestParameterTag(String JavaDoc theName) {
47         super(theName);
48     }
49
50     /**
51      * Start the tests.
52      *
53      * @param theArgs the arguments. Not used
54      */

55     public static void main(String JavaDoc[] theArgs) {
56         junit.awtui.TestRunner.main(new String JavaDoc[] {TestParameterTag.class.getName()});
57     }
58
59     /**
60      * @return a test suite (<code>TestSuite</code>) that includes all methods
61      * starting with "test"
62      */

63     public static Test suite() {
64         // All methods starting with "test" will be executed in the test suite.
65
return new TestSuite(TestParameterTag.class);
66     }
67     
68     
69     private void formatAndTest(String JavaDoc compare, String JavaDoc output) {
70         //fix for introduced carriage return / line feeds
71
output = replace(output,"\r","");
72         output = replace(output,"\n","");
73         output = output.trim();
74         //System.out.println("Testing [" + compare + "] == [" + output + "]");
75
assertEquals(compare, output);
76     }
77
78     public void beginParameterTag(WebRequest webRequest) {
79         webRequest.addParameter("testParam", "Test Value");
80     }
81     public void testParameterTag() throws IOException JavaDoc, ServletException JavaDoc{
82         request.setAttribute("runTest", "testParameterTag");
83         pageContext.forward("/test/org/apache/struts/taglib/bean/TestParameterTag.jsp");
84     }
85     public void endParameterTag(WebResponse response){
86         formatAndTest("Test Value", response.getText());
87     }
88
89     public void testParameterTagValue() throws IOException JavaDoc, ServletException JavaDoc{
90         request.setAttribute("runTest", "testParameterTagValue");
91         pageContext.forward("/test/org/apache/struts/taglib/bean/TestParameterTag.jsp");
92     }
93     public void endParameterTagValue(WebResponse response){
94         formatAndTest("Test Value", response.getText());
95     }
96
97
98 }
99
Popular Tags