KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > TaglibTestBase


1 /*
2  * $Id: TaglibTestBase.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;
19
20 import junit.framework.Assert;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23
24 import org.apache.cactus.JspTestCase;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.oro.text.perl.Perl5Util;
28
29 public class TaglibTestBase extends JspTestCase{
30     
31     private static Log log = LogFactory.getLog(TaglibTestBase.class);
32     
33     private Perl5Util perl = new Perl5Util();
34     
35     public TaglibTestBase(String JavaDoc arg0) {
36         super(arg0);
37     }
38     // Return the tests included in this test suite
39
public static Test suite() {
40         return (new TestSuite(TaglibTestBase.class));
41     }
42
43     protected void runTest(String JavaDoc whichTest, String JavaDoc jsp) throws Exception JavaDoc {
44         request.setAttribute("runTest", whichTest);
45         pageContext.forward(jsp);
46     }
47     
48     protected String JavaDoc replace(String JavaDoc source, String JavaDoc find, String JavaDoc replace){
49      
50         return perl.substitute("s/" + find + "/" + replace + "/", source);
51         
52     }
53     
54     /**
55      * Utility method for reuse from the test JSPs.
56      * @param expected The expected results for the test.
57      * @param compareTo The results to compare to the expected results.
58      */

59     public static void assertResults(String JavaDoc expected, String JavaDoc compareTo){
60         Perl5Util perl = new Perl5Util();
61         expected = perl.substitute("s/[\\r\\n]//gmx", expected);
62         compareTo = perl.substitute("s/[\\r\\n]//gmx", compareTo);
63         Assert.assertEquals(expected, compareTo);
64     }
65     
66     public static void fail(String JavaDoc msg){
67         Assert.fail(msg);
68     }
69
70 }
71
Popular Tags