01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest.server.appserver.unit;
06:
07: import com.meterware.httpunit.WebConversation;
08: import com.meterware.httpunit.WebResponse;
09: import com.tc.test.server.appserver.deployment.AbstractOneServerDeploymentTest;
10: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
11: import com.tc.test.server.appserver.deployment.WebApplicationServer;
12: import com.tc.test.server.util.TcConfigBuilder;
13: import com.tctest.webapp.servlets.RequestForwardTestForwardeeServlet;
14: import com.tctest.webapp.servlets.RequestForwardTestForwarderServlet;
15:
16: import junit.framework.Test;
17:
18: public class RequestForwardTest extends AbstractOneServerDeploymentTest {
19: private static final String CONTEXT = "RequestForward";
20: private static final String MAPPING1 = "RequestForwardTestForwarderServlet";
21: private static final String MAPPING2 = "RequestForwardTestForwardeeServlet";
22:
23: public static Test suite() {
24: return new RequestForwardTestSetup();
25: }
26:
27: private WebResponse request(WebApplicationServer server,
28: String mapping, String params, WebConversation wc)
29: throws Exception {
30: return server.ping(
31: "/" + CONTEXT + "/" + mapping + "?" + params, wc);
32: }
33:
34: public void testSessionForwardSession() throws Exception {
35: WebConversation conversation = new WebConversation();
36: WebResponse response = request(server0, MAPPING1, "action=0",
37: conversation);
38: assertEquals("INVALID REQUEST", response.getText().trim());
39:
40: response = request(server0, MAPPING1, "action=s-f-s&target="
41: + MAPPING2, conversation);
42: assertEquals("FORWARD GOT SESSION", response.getText().trim());
43: }
44:
45: public void testForwardSession() throws Exception {
46: WebConversation conversation = new WebConversation();
47: WebResponse response = request(server0, MAPPING1, "action=0",
48: conversation);
49: assertEquals("INVALID REQUEST", response.getText().trim());
50:
51: response = request(server0, MAPPING1, "action=n-f-s&target="
52: + MAPPING2, conversation);
53: assertEquals("FORWARD GOT SESSION", response.getText().trim());
54: }
55:
56: public void testSessionForward() throws Exception {
57: WebConversation conversation = new WebConversation();
58: WebResponse response = request(server0, MAPPING1, "action=0",
59: conversation);
60: assertEquals("INVALID REQUEST", response.getText().trim());
61:
62: response = request(server0, MAPPING1, "action=s-f-n&target="
63: + MAPPING2, conversation);
64: assertEquals("FORWARD DID NOT GET SESSION", response.getText()
65: .trim());
66: }
67:
68: private static class RequestForwardTestSetup extends
69: OneServerTestSetup {
70:
71: public RequestForwardTestSetup() {
72: super (RequestForwardTest.class, CONTEXT);
73: }
74:
75: protected void configureWar(DeploymentBuilder builder) {
76: builder.addServlet("RequestForwardTestForwarderServlet",
77: "/" + MAPPING1 + "/*",
78: RequestForwardTestForwarderServlet.class, null,
79: false);
80: builder.addServlet("RequestForwardTestForwardeeServlet",
81: "/" + MAPPING2 + "/*",
82: RequestForwardTestForwardeeServlet.class, null,
83: false);
84: }
85:
86: protected void configureTcConfig(TcConfigBuilder tcConfigBuilder) {
87: tcConfigBuilder.addWebApplication(CONTEXT);
88: }
89:
90: }
91: }
|