KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openinventions > webappfilter > WebAppFilterTest


1 package com.openinventions.webappfilter;
2
3 import com.openinventions.metaframework.*;
4 import org.apache.commons.logging.*;
5 import java.util.*;
6 import junit.framework.*;
7
8 public class WebAppFilterTest extends TestCase {
9     private static final Log log = LogFactory.getLog(WebAppFilterTest.class);
10     private static TestCase test = null;
11     
12     public static TestCase getTest() throws Exception JavaDoc {
13         return test;
14     }
15     
16     protected void setUp() throws Exception JavaDoc {
17     }
18
19     public void testFilter() throws Exception JavaDoc {
20         this.test = this;
21         ElementFactory factory = new JXPathElementFileFactory();
22         State state = new DefaultState();
23         Element config = factory.read("conf/test/html/unit/filter.xml");
24         config.setCached(true);
25         state.set("com.openinventions.metaframework.Config", config);
26         Map application = new HashMap();
27         application.put("com.openinventions.metaframework.Config", config);
28         state.set("com.openinventions.metaframework.ApplicationState", application);
29         state.set("com.openinventions.metaframework.ElementFactory", factory);
30         state.set("nextCommand", "/filters");
31         state.set("rootDir", ".");
32 /* Object o = new com.openinventions.webappfilter.processor.xpathexpression.XPathExpressionParser(new java.io.StringReader("10.0 == \"10.2\"")).parse(state);
33         if (o != null) {
34             log.debug("KENNEDY " + o);
35             return;
36         }*/

37         Processor traverser = (Processor) state.get("traverser");
38 // traverser.process(state, null);
39

40         int i = 0;
41         String JavaDoc filterDirection = "";
42         while (!filterDirection.equals("stop")) {
43             state.set("filterDirection", "");
44             traverser.process(state, null);
45             filterDirection = (String JavaDoc) state.get("filterDirection");
46             if (log.isDebugEnabled()) {
47                 log.debug("filterDirection = " + filterDirection);
48             }
49             if (i > 50) {
50                 log.error("possible error " + i + " filters ran");
51                 break;
52             }
53             i++;
54         }
55
56     }
57
58     private void initTest(State state) throws Exception JavaDoc {
59         if (state != null) {
60             state.set("junit.framework.TestCase", this);
61         }
62     }
63
64     public static void main(String JavaDoc args[]) {
65         junit.textui.TestRunner.run(new TestSuite(WebAppFilterTest.class));
66     }
67 }
68 /* ====================================================================
69  * The webappfilter License, Version 1.1
70  *
71  * Copyright (c) 2002 Ivar Chan. All rights
72  * reserved.
73  *
74  * Redistribution and use in source and binary forms, with or without
75  * modification, are permitted provided that the following conditions
76  * are met:
77  *
78  * 1. Redistributions of source code must retain the above copyright
79  * notice, this list of conditions and the following disclaimer.
80  *
81  * 2. Redistributions in binary form must reproduce the above copyright
82  * notice, this list of conditions and the following disclaimer in
83  * the documentation and/or other materials provided with the
84  * distribution.
85  *
86  * 3. The end-user documentation included with the redistribution,
87  * if any, must include the following acknowledgment:
88  * "This product includes software developed by
89  * Ivar Chan (http://www.openinventions.com/webappfilter/)."
90  * Alternately, this acknowledgment may appear in the software itself,
91  * if and wherever such third-party acknowledgments normally appear.
92  *
93  * 4. The name "webappfilter" must not be used to endorse or promote products
94  * derived from this software without prior written permission. For
95  * written permission, please contact ivarchan@acm.org.
96  *
97  * 5. Products derived from this software may not be called "webappfilter",
98  * nor may "webappfilter" appear in their name, without
99  * prior written permission of Ivar Chan.
100  *
101  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
102  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
103  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
104  * DISCLAIMED. IN NO EVENT SHALL THE IVAR CHAN BE LIABLE FOR ANY
105  * DIRECT, INDIRECT, INCIDENTAL,
106  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
107  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
108  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
109  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
110  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
111  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
112  * SUCH DAMAGE.
113  * ====================================================================
114  *
115  * This software consists of voluntary contributions made by many
116  * individuals. For more information on webappfilter, please see
117  * <http://www.openinventions/webappfilter/>.
118  */

119
120
Popular Tags