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.tctest.server.appserver.unit;
05:
06: import com.meterware.httpunit.WebConversation;
07: import com.meterware.httpunit.WebResponse;
08: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
09: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
10: import com.tc.test.server.appserver.deployment.WebApplicationServer;
11: import com.tc.test.server.util.TcConfigBuilder;
12: import com.tctest.webapp.servletfilters.SimpleFilter;
13: import com.tctest.webapp.servlets.ShutdownNormallyServlet;
14:
15: import junit.framework.Test;
16:
17: /**
18: * Test session filter
19: */
20: public final class SimpleSessionFilterTest extends
21: AbstractTwoServerDeploymentTest {
22: private static final String CONTEXT = "SimpleSessionFilterTest";
23: private static final String SERVLET = "ShutdownNormallyServlet";
24:
25: public static Test suite() {
26: return new SimpleSessionFilterTestSetup();
27: }
28:
29: public void testFilter() throws Exception {
30: WebConversation conversation = new WebConversation();
31:
32: WebResponse response1 = request(server0, "cmd=insert",
33: conversation);
34: assertEquals("OK", response1.getText().trim());
35:
36: WebResponse response2 = request(server1, "cmd=query",
37: conversation);
38: assertEquals("OK", response2.getText().trim());
39: }
40:
41: private WebResponse request(WebApplicationServer server,
42: String params, WebConversation con) throws Exception {
43: return server.ping(
44: "/" + CONTEXT + "/" + SERVLET + "?" + params, con);
45: }
46:
47: private static class SimpleSessionFilterTestSetup extends
48: TwoServerTestSetup {
49:
50: public SimpleSessionFilterTestSetup() {
51: super (SimpleSessionFilterTest.class, CONTEXT);
52: }
53:
54: protected void configureWar(DeploymentBuilder builder) {
55: builder.addServlet("ShutdownNormallyServlet", "/" + SERVLET
56: + "/*", ShutdownNormallyServlet.class, null, false);
57: builder.addFilter("SimpleFilter", "/*", SimpleFilter.class,
58: null);
59: }
60:
61: protected void configureTcConfig(TcConfigBuilder clientConfig) {
62: clientConfig.addWebApplication(CONTEXT);
63: clientConfig.addInstrumentedClass(SimpleFilter.class
64: .getName());
65: }
66: }
67: }
|