You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2007/10/01 07:49:49 UTC

svn commit: r580849 - in /geronimo/server/trunk/testsuite/web-testsuite/test-jetty: pom.xml src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java

Author: gawor
Date: Sun Sep 30 22:49:49 2007
New Revision: 580849

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

Modified:
    geronimo/server/trunk/testsuite/web-testsuite/test-jetty/pom.xml
    geronimo/server/trunk/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java

Modified: geronimo/server/trunk/testsuite/web-testsuite/test-jetty/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/web-testsuite/test-jetty/pom.xml?rev=580849&r1=580848&r2=580849&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/web-testsuite/test-jetty/pom.xml (original)
+++ geronimo/server/trunk/testsuite/web-testsuite/test-jetty/pom.xml Sun Sep 30 22:49:49 2007
@@ -49,11 +49,6 @@
             <id>child</id>
             <build>
               <plugins>
-                   <plugin>
-                      <groupId>org.codehaus.mojo</groupId>
-                      <artifactId>selenium-maven-plugin</artifactId>
-                   </plugin>
-
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-surefire-plugin</artifactId>

Modified: geronimo/server/trunk/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java?rev=580849&r1=580848&r2=580849&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java (original)
+++ geronimo/server/trunk/testsuite/web-testsuite/test-jetty/src/test/java/org/apache/geronimo/testsuite/jetty/TestJetty.java Sun Sep 30 22:49:49 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
+}