KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > ApplicationTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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  */

17
18 package org.apache.geronimo.jetty6;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22 import java.net.HttpURLConnection JavaDoc;
23 import java.net.URL JavaDoc;
24
25 import org.apache.geronimo.clustering.SessionManager;
26 import org.apache.geronimo.clustering.Session;
27 import org.apache.geronimo.clustering.SessionAlreadyExistException;
28 import org.apache.geronimo.clustering.SessionListener;
29 import org.apache.geronimo.clustering.Node;
30 import org.apache.geronimo.clustering.BasicNode;
31 import org.apache.geronimo.jetty6.cluster.ClusteredSessionHandlerFactory;
32
33 /**
34  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
35  */

36 public class ApplicationTest extends AbstractWebModuleTest {
37
38     public void testApplication() throws Exception JavaDoc {
39         JettyWebAppContext app = setUpAppContext(null, null, null, null, null, null, null, "war1/");
40
41         setUpStaticContentServlet(app);
42
43         HttpURLConnection JavaDoc connection = (HttpURLConnection JavaDoc) new URL JavaDoc("http://localhost:5678/test/hello.txt").openConnection();
44         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(connection.getInputStream()));
45         assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
46         assertEquals("Hello World", reader.readLine());
47         connection.disconnect();
48     }
49
50     public void testApplicationWithSessionHandler() throws Exception JavaDoc {
51         SessionManager sessionManager = new MockSessionManager();
52         sessionHandlerFactory = new ClusteredSessionHandlerFactory(sessionManager);
53         JettyWebAppContext app = setUpAppContext(null, null, null, null, null, null, null, "war1/");
54
55         setUpStaticContentServlet(app);
56
57         HttpURLConnection JavaDoc connection = (HttpURLConnection JavaDoc) new URL JavaDoc("http://localhost:5678/test/hello.txt").openConnection();
58         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(connection.getInputStream()));
59         assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
60         assertEquals("Hello World", reader.readLine());
61         connection.disconnect();
62     }
63
64     private static class MockSessionManager implements SessionManager {
65
66         Node node = new BasicNode("testNode");
67
68         public Session createSession(String JavaDoc string) throws SessionAlreadyExistException {
69             return null;
70         }
71
72         public void registerListener(SessionListener sessionListener) {
73         }
74
75         public void unregisterListener(SessionListener sessionListener) {
76         }
77
78         public Node getNode() {
79             return node;
80         }
81     }
82
83 }
84
Popular Tags