KickJava   Java API By Example, From Geeks To Geeks.

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