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 { 13 return test; 14 } 15 16 protected void setUp() throws Exception { 17 } 18 19 public void testFilter() throws Exception { 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 37 Processor traverser = (Processor) state.get("traverser"); 38 40 int i = 0; 41 String filterDirection = ""; 42 while (!filterDirection.equals("stop")) { 43 state.set("filterDirection", ""); 44 traverser.process(state, null); 45 filterDirection = (String ) 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 { 59 if (state != null) { 60 state.set("junit.framework.TestCase", this); 61 } 62 } 63 64 public static void main(String args[]) { 65 junit.textui.TestRunner.run(new TestSuite(WebAppFilterTest.class)); 66 } 67 } 68 119 120 | Popular Tags |