KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestStrutsTag.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.WebResponse;
28 import org.apache.struts.taglib.TaglibTestBase;
29
30 /**
31  * Suite of unit tests for the
32  * <code>org.apache.struts.taglib.bean.StrutsTag</code> class.
33  *
34  */

35 public class TestStrutsTag extends TaglibTestBase {
36     protected final static String JavaDoc TEST_VAL = "Test Value";
37     protected final static String JavaDoc REQUEST_KEY = "REQUEST_KEY";
38
39     /**
40      * Defines the testcase name for JUnit.
41      *
42      * @param theName the testcase's name.
43      */

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

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

61     public static Test suite() {
62         // All methods starting with "test" will be executed in the test suite.
63
return new TestSuite(TestStrutsTag.class);
64     }
65     
66     private void formatAndTest(String JavaDoc compare, String JavaDoc output) {
67         //fix for introduced carriage return / line feeds
68
output = replace(output,"\r","");
69         output = replace(output,"\n","");
70         output = output.trim();
71         //System.out.println("Testing [" + compare + "] == [" + output + "]");
72
assertEquals(compare, output);
73     }
74
75
76
77     public void testStrutsTagFormBean() throws IOException JavaDoc, ServletException JavaDoc{
78         request.setAttribute("runTest", "testStrutsTagFormBean");
79         pageContext.forward("/test/org/apache/struts/taglib/bean/TestStrutsTag.jsp");
80     }
81     public void endStrutsTagFormBean(WebResponse response){
82         formatAndTest("testFormBean", response.getText());
83     }
84
85     public void testStrutsTagDynaFormBean() throws IOException JavaDoc, ServletException JavaDoc{
86         request.setAttribute("runTest", "testStrutsTagDynaFormBean");
87         pageContext.forward("/test/org/apache/struts/taglib/bean/TestStrutsTag.jsp");
88     }
89     public void endStrutsTagDynaFormBean(WebResponse response){
90         formatAndTest("testDynaFormBean", response.getText());
91     }
92
93     public void testStrutsTagForward() throws IOException JavaDoc, ServletException JavaDoc{
94         request.setAttribute("runTest", "testStrutsTagForward");
95         pageContext.forward("/test/org/apache/struts/taglib/bean/TestStrutsTag.jsp");
96     }
97     public void endStrutsTagForward(WebResponse response){
98         formatAndTest("testIncludeTagForward", response.getText());
99     }
100
101     public void testStrutsTagMapping() throws IOException JavaDoc, ServletException JavaDoc{
102         request.setAttribute("runTest", "testStrutsTagMapping");
103         pageContext.forward("/test/org/apache/struts/taglib/bean/TestStrutsTag.jsp");
104     }
105     public void endStrutsTagMapping(WebResponse response){
106         formatAndTest("/testIncludeTagTransaction", response.getText());
107     }
108
109
110 }
111
Popular Tags