KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > tomcat50 > TerracottaPipelineTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.tomcat50;
5
6 import org.apache.catalina.Request;
7 import org.apache.catalina.Response;
8 import org.apache.catalina.Valve;
9 import org.apache.catalina.ValveContext;
10 import org.apache.catalina.valves.ValveBase;
11
12 import com.tc.tomcat50.session.SessionValve50;
13
14 import junit.framework.TestCase;
15
16 public class TerracottaPipelineTest extends TestCase {
17
18   public void testValve() {
19     TerracottaPipeline pipeline = new TerracottaPipeline(null);
20     pipeline.getValveObjectNames(); // call this just to make sure it works with our valve
21
Valve[] valves = pipeline.getValves();
22
23     assertEquals(1, valves.length);
24
25     // cast will fail it is some other type
26
SessionValve50 valve = (SessionValve50) valves[0];
27
28     try {
29       pipeline.removeValve(valve);
30       fail();
31     } catch (IllegalArgumentException JavaDoc iae) {
32       // exptected
33
}
34
35     // mutating the array doesn't affect the pipeline
36
valves[0] = null;
37     assertEquals(valve, pipeline.getValves()[0]);
38
39     pipeline.addValve(new DummyValve());
40     assertEquals(2, pipeline.getValves().length);
41     assertEquals(valve, pipeline.getValves()[0]);
42   }
43
44   private static class DummyValve extends ValveBase {
45
46     public void invoke(Request request, Response response, ValveContext valvecontext) {
47       //
48
}
49
50   }
51
52 }
53
Popular Tags