01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.jetty6;
17:
18: import java.io.BufferedReader;
19: import java.io.IOException;
20: import java.io.InputStreamReader;
21: import java.net.HttpURLConnection;
22: import java.net.URL;
23:
24: import javax.servlet.ServletException;
25: import javax.servlet.http.HttpServletRequest;
26: import javax.servlet.http.HttpServletResponse;
27:
28: import org.mortbay.jetty.servlet.SessionHandler;
29:
30: /**
31: * @version $Rev: 609571 $ $Date: 2008-01-07 03:11:35 -0800 (Mon, 07 Jan 2008) $
32: */
33: public class ApplicationTest extends AbstractWebModuleTest {
34:
35: public void testApplication() throws Exception {
36: JettyWebAppContext app = setUpAppContext(null, null, null,
37: null, null, null, null, "war1/");
38:
39: setUpStaticContentServlet(app);
40:
41: HttpURLConnection connection = (HttpURLConnection) new URL(
42: "http://localhost:5678/test/hello.txt")
43: .openConnection();
44: BufferedReader reader = new BufferedReader(
45: new InputStreamReader(connection.getInputStream()));
46: assertEquals(HttpURLConnection.HTTP_OK, connection
47: .getResponseCode());
48: assertEquals("Hello World", reader.readLine());
49: connection.disconnect();
50: }
51:
52: public void testApplicationWithSessionHandler() throws Exception {
53: preHandlerFactory = new MockPreHandlerFactory();
54: sessionHandlerFactory = new MockSessionHandlerFactory();
55: JettyWebAppContext app = setUpAppContext(null, null, null,
56: null, null, null, null, "war1/");
57:
58: setUpStaticContentServlet(app);
59:
60: HttpURLConnection connection = (HttpURLConnection) new URL(
61: "http://localhost:5678/test/hello.txt")
62: .openConnection();
63: BufferedReader reader = new BufferedReader(
64: new InputStreamReader(connection.getInputStream()));
65: assertEquals(HttpURLConnection.HTTP_OK, connection
66: .getResponseCode());
67: assertEquals("Hello World", reader.readLine());
68: connection.disconnect();
69: }
70:
71: public class MockPreHandlerFactory implements PreHandlerFactory {
72: public PreHandler createHandler() {
73: return new AbstractPreHandler() {
74:
75: public void handle(String target,
76: HttpServletRequest request,
77: HttpServletResponse response, int dispatch)
78: throws IOException, ServletException {
79: next.handle(target, request, response, dispatch);
80: }
81:
82: };
83: }
84:
85: }
86:
87: public class MockSessionHandlerFactory implements
88: SessionHandlerFactory {
89: public SessionHandler createHandler(PreHandler preHandler) {
90: return new SessionHandler();
91: }
92: }
93:
94: }
|