01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.tomcat50;
05:
06: import org.apache.catalina.Request;
07: import org.apache.catalina.Response;
08: import org.apache.catalina.Valve;
09: 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 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,
47: ValveContext valvecontext) {
48: //
49: }
50:
51: }
52:
53: }
|