1 17 18 package org.apache.geronimo.jetty6; 19 20 import java.io.BufferedReader ; 21 import java.io.InputStreamReader ; 22 import java.net.HttpURLConnection ; 23 import java.net.URL ; 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 36 public class ApplicationTest extends AbstractWebModuleTest { 37 38 public void testApplication() throws Exception { 39 JettyWebAppContext app = setUpAppContext(null, null, null, null, null, null, null, "war1/"); 40 41 setUpStaticContentServlet(app); 42 43 HttpURLConnection connection = (HttpURLConnection ) new URL ("http://localhost:5678/test/hello.txt").openConnection(); 44 BufferedReader reader = new BufferedReader (new InputStreamReader (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 { 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 connection = (HttpURLConnection ) new URL ("http://localhost:5678/test/hello.txt").openConnection(); 58 BufferedReader reader = new BufferedReader (new InputStreamReader (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 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 |