geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r580848 - /geronimo/server/branches/2.0/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java
Date Mon, 01 Oct 2007 05:47:32 GMT
Author: gawor
Date: Sun Sep 30 22:47:32 2007
New Revision: 580848

URL: http://svn.apache.org/viewvc?rev=580848&view=rev
Log:
selenium requires special option to deal with virutal hosts so switched the test to use URLConnection

Modified:
    geronimo/server/branches/2.0/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java

Modified: geronimo/server/branches/2.0/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java?rev=580848&r1=580847&r2=580848&view=diff
==============================================================================
--- geronimo/server/branches/2.0/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java
(original)
+++ geronimo/server/branches/2.0/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java
Sun Sep 30 22:47:32 2007
@@ -19,18 +19,72 @@
 
 package org.apache.geronimo.testsuite.jetty;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
 
-import org.apache.geronimo.testsupport.SeleniumTestSupport;
+import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
 
-public class TestJetty extends SeleniumTestSupport
+public class TestJetty extends TestSupport
 {
     @Test
-    public void testJetty() throws Exception {
-        selenium.open("http://testhost.com:8080/JettyWeb/");
-        selenium.waitForPageToLoad("30000");
-        assertEquals("Testing Jetty.", selenium.getText("xpath=/html/body"));
+    public void testJettyHost() throws Exception {
+        URL url = new URL("http://localhost:8080/JettyWeb/");
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        try {
+            String reply = doGET(conn, "testhost.com");
+
+            assertEquals("responseCode", 200, conn.getResponseCode());
+
+            assertTrue( reply.indexOf("Testing Jetty.") != -1 );
+        } finally {
+            conn.disconnect();
+        }
+    }
+
+    @Test
+    public void testJettyNoHost() throws Exception {
+        URL url = new URL("http://localhost:8080/JettyWeb/");
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        try {
+            String reply = doGET(conn, null);
+
+            assertEquals("responseCode", 404, conn.getResponseCode());
+        } finally {
+            conn.disconnect();
+        }
     }
 
+    private String doGET(HttpURLConnection conn, String host) throws IOException {      
 
+        conn.setDoOutput(true);
+        conn.setUseCaches(false);
+        if (host != null) {
+            conn.setRequestProperty("Host", host);
+        }
+
+        InputStream is = null;
+        
+        try {
+            is = conn.getInputStream();
+        } catch (IOException e) {
+            is = conn.getErrorStream();
+        }
+        
+        StringBuffer buf = new StringBuffer();
+        BufferedReader in = new BufferedReader(new InputStreamReader(is));
+        String inputLine;
+        while ((inputLine = in.readLine()) != null) {
+            System.out.println(inputLine);
+            buf.append(inputLine);
+        }
+        in.close();
+        
+        return buf.toString();
+    }
 
-}
\ No newline at end of file
+}



Mime
View raw message