001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest.server.appserver.unit;
006:
007: import com.meterware.httpunit.WebConversation;
008: import com.meterware.httpunit.WebResponse;
009: import com.tc.test.server.appserver.AppServerFactory;
010: import com.tc.test.server.appserver.deployment.AbstractDeploymentTest;
011: import com.tc.test.server.appserver.deployment.Deployment;
012: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
013: import com.tc.test.server.appserver.deployment.ServerTestSetup;
014: import com.tc.test.server.appserver.deployment.WebApplicationServer;
015: import com.tc.test.server.util.TcConfigBuilder;
016: import com.tctest.webapp.servlets.ServerHopCookieRewriteTestServlet;
017:
018: import junit.framework.Test;
019:
020: public final class ServerHopCookieRewriteTest extends
021: AbstractDeploymentTest {
022: private static final String CONTEXT = "CookieRewrite";
023: private static final String MAPPING = "ServerHopCookieRewriteTestServlet";
024: private Deployment deployment;
025:
026: public static Test suite() {
027: return new ServerTestSetup(ServerHopCookieRewriteTest.class);
028: }
029:
030: public void setUp() throws Exception {
031: super .setUp();
032: if (deployment == null)
033: deployment = makeDeployment();
034: }
035:
036: public void testCookieRewrite() throws Exception {
037: TcConfigBuilder tcConfigBuilder = new TcConfigBuilder();
038: tcConfigBuilder.addWebApplication(CONTEXT);
039:
040: WebApplicationServer server0 = createServer(tcConfigBuilder);
041: server0.start();
042:
043: WebApplicationServer server1 = createServer(tcConfigBuilder);
044: server1.start();
045:
046: WebConversation conversation = new WebConversation();
047: WebResponse response = request(server0, "server=0",
048: conversation);
049: assertEquals("OK", response.getText().trim());
050:
051: response = request(server1, "server=1", conversation);
052: assertEquals("OK", response.getText().trim());
053:
054: response = request(server0, "server=2", conversation);
055: assertEquals("OK", response.getText().trim());
056:
057: response = request(server0, "server=3", conversation);
058: assertEquals("OK", response.getText().trim());
059: }
060:
061: private WebResponse request(WebApplicationServer server,
062: String params, WebConversation con) throws Exception {
063: return server.ping(
064: "/" + CONTEXT + "/" + MAPPING + "?" + params, con);
065: }
066:
067: private WebApplicationServer createServer(
068: TcConfigBuilder configBuilder) throws Exception {
069: WebApplicationServer server = makeWebApplicationServer(configBuilder);
070: server.addWarDeployment(deployment, CONTEXT);
071: int appId = AppServerFactory.getCurrentAppServerId();
072: if (appId != AppServerFactory.WEBSPHERE) {
073: server.getServerParameters().appendSysProp(
074: "com.tc.session.delimiter",
075: ServerHopCookieRewriteTestServlet.DLM);
076: }
077: return server;
078: }
079:
080: // public void testSessions() throws Exception {
081: // int appId = AppServerFactory.getCurrentAppServerId();
082: //
083: // final String[] args;
084: //
085: // if (AppServerFactory.WEBSPHERE == appId) {
086: // args = new String[] {};
087: // } else {
088: // args = new String[] { "-Dcom.tc.session.delimiter=" + ServerHopCookieRewriteTestServlet.DLM };
089: // }
090: //
091: // int port0 = startAppServer(true, new Properties(), args).serverPort();
092: // int port1 = startAppServer(true, new Properties(), args).serverPort();
093: //
094: // URL url0 = new URL(createUrl(port0, ServerHopCookieRewriteTestServlet.class) + "?server=0");
095: // URL url1 = new URL(createUrl(port1, ServerHopCookieRewriteTestServlet.class) + "?server=1");
096: // URL url2 = new URL(createUrl(port0, ServerHopCookieRewriteTestServlet.class) + "?server=2");
097: // URL url3 = new URL(createUrl(port0, ServerHopCookieRewriteTestServlet.class) + "?server=3");
098: // assertEquals("OK", HttpUtil.getResponseBody(url0, client));
099: // assertEquals("OK", HttpUtil.getResponseBody(url1, client));
100: // assertEquals("OK", HttpUtil.getResponseBody(url2, client));
101: // assertEquals("OK", HttpUtil.getResponseBody(url3, client));
102: // }
103:
104: private Deployment makeDeployment() throws Exception {
105: DeploymentBuilder builder = makeDeploymentBuilder(CONTEXT
106: + ".war");
107: builder.addServlet(MAPPING, "/" + MAPPING + "/*",
108: ServerHopCookieRewriteTestServlet.class, null, false);
109: return builder.makeDeployment();
110: }
111: }
|