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 2010/04/26 17:13:58 UTC

svn commit: r938085 - in /geronimo/server/trunk: framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/ testsuite/enterprise-testsuite/appname-tests/appname-ear/src/test/java/org/apache/geronimo/testsuite/appname/ testsuite...

Author: gawor
Date: Mon Apr 26 15:13:57 2010
New Revision: 938085

URL: http://svn.apache.org/viewvc?rev=938085&view=rev
Log:
factor out some http code to make tests a bit simpler

Added:
    geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java   (with props)
Removed:
    geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/resources/
Modified:
    geronimo/server/trunk/testsuite/enterprise-testsuite/appname-tests/appname-ear/src/test/java/org/apache/geronimo/testsuite/appname/ServletTest.java
    geronimo/server/trunk/testsuite/enterprise-testsuite/datasource-test/src/test/java/org/apache/geronimo/testsuite/datasource/TestDataSource.java
    geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/pom.xml
    geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java
    geronimo/server/trunk/testsuite/webservices-testsuite/jaxb-tests/jaxb-war/src/test/java/org/apache/geronimo/testsuite/testset/WebJAXBTest.java
    geronimo/server/trunk/testsuite/webservices-testsuite/stax-tests/stax-war/src/test/java/org/apache/geronimo/testsuite/testset/WebStaxTest.java

Added: geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java?rev=938085&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java (added)
+++ geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java Mon Apr 26 15:13:57 2010
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.testsupport;
+
+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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class HttpUtils {
+    
+    public static String doGET(URL url) throws IOException {
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        try {
+            String reply = doGET(conn);            
+            if (conn.getResponseCode() != 200) {
+                throw new IOException(reply);
+            }            
+            return reply;            
+        } finally {
+            conn.disconnect();
+        }
+    }
+    
+    public static String doGET(HttpURLConnection conn) throws IOException {
+        conn.setRequestMethod("GET");
+        return call(conn, null);        
+    }
+            
+    public static String doPOST(URL url, InputStream input) throws IOException {
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        try {
+            String reply = doPOST(conn, input);            
+            if (conn.getResponseCode() != 200) {
+                throw new IOException(reply);
+            }            
+            return reply;            
+        } finally {
+            conn.disconnect();
+        }
+    }
+    
+    public static String doPOST(HttpURLConnection conn, InputStream input) throws IOException {
+        conn.setRequestMethod("POST");
+        return call(conn, input);        
+    }
+    
+    public static String call(HttpURLConnection conn, InputStream input) throws IOException {        
+        conn.setConnectTimeout(30 * 1000);
+        conn.setReadTimeout(30 * 1000);
+        conn.setUseCaches(false);
+        
+        if (input != null) {
+            conn.setDoOutput(true);
+            
+            OutputStream out = conn.getOutputStream();
+
+            byte[] data = new byte[1024];
+            int read = 0;
+            while ((read = input.read(data, 0, data.length)) != -1) {
+                out.write(data, 0, read);
+            }
+
+            input.close();
+
+            out.flush();
+            out.close();
+        }
+
+        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();
+    }
+    
+    /*
+    private String getAuthorizationValue(String user, String password) {
+        String userPassword = user + ":" + password;
+        byte[] encodedUserPassword = Base64.encode(userPassword.getBytes());
+        String encodedUserPasswordStr = new String(encodedUserPassword, 0, encodedUserPassword.length);
+        return "Basic " + encodedUserPasswordStr;
+    }
+    */
+    
+}

Propchange: geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/testsupport-common/src/main/java/org/apache/geronimo/testsupport/HttpUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/testsuite/enterprise-testsuite/appname-tests/appname-ear/src/test/java/org/apache/geronimo/testsuite/appname/ServletTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/enterprise-testsuite/appname-tests/appname-ear/src/test/java/org/apache/geronimo/testsuite/appname/ServletTest.java?rev=938085&r1=938084&r2=938085&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/enterprise-testsuite/appname-tests/appname-ear/src/test/java/org/apache/geronimo/testsuite/appname/ServletTest.java (original)
+++ geronimo/server/trunk/testsuite/enterprise-testsuite/appname-tests/appname-ear/src/test/java/org/apache/geronimo/testsuite/appname/ServletTest.java Mon Apr 26 15:13:57 2010
@@ -19,12 +19,9 @@
 
 package org.apache.geronimo.testsuite.appname;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
 import java.net.URL;
 
+import org.apache.geronimo.testsupport.HttpUtils;
 import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
 
@@ -41,31 +38,10 @@ public class ServletTest extends TestSup
         String warName = System.getProperty("webAppName");
         assertNotNull(warName);
         URL url = new URL(baseURL + warName + address);
-        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-        connection.setConnectTimeout(30 * 1000);
-        connection.setReadTimeout(30 * 1000);
-        try {
-            BufferedReader reader = new BufferedReader(new InputStreamReader(connection
-                    .getInputStream()));
-            assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
-            assertTrue("AppName", find(reader, "AppName: " + System.getProperty("appName")));
-            assertTrue("ModuleName", find(reader, "ModuleName: web"));
-        } finally {
-            connection.disconnect();
-        }
+        String reply = HttpUtils.doGET(url);
+        assertTrue("AppName", reply.contains("AppName: " + System.getProperty("appName")));
+        assertTrue("ModuleName", reply.contains("ModuleName: web"));
     }
 
-    private boolean find(BufferedReader reader, String text) throws IOException {
-        String line = null;
-        while ((line = reader.readLine()) != null) {
-            System.out.println(line);
-            if (line.indexOf(text) != -1) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-
 }
 

Modified: geronimo/server/trunk/testsuite/enterprise-testsuite/datasource-test/src/test/java/org/apache/geronimo/testsuite/datasource/TestDataSource.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/enterprise-testsuite/datasource-test/src/test/java/org/apache/geronimo/testsuite/datasource/TestDataSource.java?rev=938085&r1=938084&r2=938085&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/enterprise-testsuite/datasource-test/src/test/java/org/apache/geronimo/testsuite/datasource/TestDataSource.java (original)
+++ geronimo/server/trunk/testsuite/enterprise-testsuite/datasource-test/src/test/java/org/apache/geronimo/testsuite/datasource/TestDataSource.java Mon Apr 26 15:13:57 2010
@@ -19,12 +19,9 @@
 
 package org.apache.geronimo.testsuite.datasource;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
 import java.net.URL;
 
+import org.apache.geronimo.testsupport.HttpUtils;
 import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
 
@@ -41,29 +38,9 @@ public class TestDataSource extends Test
         String warName = System.getProperty("webAppName");
         assertNotNull(warName);
         URL url = new URL(baseURL + warName + address);
-        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-        connection.setConnectTimeout(30 * 1000);
-        connection.setReadTimeout(30 * 1000);
-        try {
-            BufferedReader reader = new BufferedReader(new InputStreamReader(connection
-                    .getInputStream()));
-            assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
-            assertTrue("Contact1", find(reader, "Joe Smith 111 111-"));
-            assertTrue("Contact2", find(reader, "Jane Doe 222 222-"));
-        } finally {
-            connection.disconnect();
-        }
-    }
-
-    private boolean find(BufferedReader reader, String text) throws IOException {
-        String line = null;
-        while ((line = reader.readLine()) != null) {
-            System.out.println(line);
-            if (line.indexOf(text) != -1) {
-                return true;
-            }
-        }
-        return false;
+        String reply = HttpUtils.doGET(url);
+        assertTrue("Contact1", reply.contains("Joe Smith 111 111-"));
+        assertTrue("Contact2", reply.contains("Jane Doe 222 222-"));
     }
 
 }

Modified: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/pom.xml?rev=938085&r1=938084&r2=938085&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/pom.xml (original)
+++ geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/pom.xml Mon Apr 26 15:13:57 2010
@@ -111,27 +111,8 @@
         <profile>
             <id>it</id>
             <build>
-                <pluginManagement>
-                    <plugins>
-                        <plugin>
-                            <groupId>org.apache.maven.plugins</groupId>
-                            <artifactId>maven-failsafe-plugin</artifactId>
-                            <configuration>
-                                <suiteXmlFiles>
-                                    <suiteXmlFile>${project.build.testOutputDirectory}/testng.xml</suiteXmlFile>
-                                </suiteXmlFiles>
-                            </configuration>
-                        </plugin>
-                    </plugins>
-                </pluginManagement>
-
                 <plugins>
                     <plugin>
-                        <groupId>org.codehaus.mojo</groupId>
-                        <artifactId>selenium-maven-plugin</artifactId>
-                    </plugin>
-
-                    <plugin>
                         <groupId>org.apache.geronimo.buildsupport</groupId>
                         <artifactId>geronimo-maven-plugin</artifactId>
                         <executions>

Modified: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java?rev=938085&r1=938084&r2=938085&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java (original)
+++ geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java Mon Apr 26 15:13:57 2010
@@ -19,30 +19,25 @@
 
 package org.apache.geronimo.testsuite.jpa;
 
+import java.net.URL;
+
+import org.apache.geronimo.testsupport.HttpUtils;
+import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
-import org.apache.geronimo.testsupport.SeleniumTestSupport;
 
 /**
- * ???
- *
  * @version $Rev$ $Date$
  */
-@Test
-public class JPATest
-    extends SeleniumTestSupport
-{
+public class JPATest extends TestSupport {
+
     @Test
     public void testIndexContent() throws Exception {
-        selenium.open("/jpa/servlet");
-        waitForPageLoad();
-        //assertEquals("Hello J2EE 1.4", selenium.getTitle());
-        assertEquals("TestServlet\n" +
-                "Test EJB container managed entity manager test OK: true\n" +
-                "Test EJB app managed entity manager factory test OK: true\n" +
-                "Test servlet container managed entity manager test OK: true\n" +
-                "Test servlet app managed entity manager factory test OK: true\n" +
-                "commit OK", selenium.getText("xpath=/html/body"));
-
+        URL url = new URL("http://localhost:8080/jpa/servlet");
+        String reply = HttpUtils.doGET(url);
+        assertTrue("EJB container managed", reply.contains("Test EJB container managed entity manager test OK: true"));
+        assertTrue("EJB app managed", reply.contains("Test EJB app managed entity manager factory test OK: true"));
+        assertTrue("Servlet container managed", reply.contains("Test servlet container managed entity manager test OK: true"));
+        assertTrue("Serlvet app managed", reply.contains("Test servlet app managed entity manager factory test OK: true"));
+        assertTrue("Commit", reply.contains("commit OK"));
     }
 }
-

Modified: geronimo/server/trunk/testsuite/webservices-testsuite/jaxb-tests/jaxb-war/src/test/java/org/apache/geronimo/testsuite/testset/WebJAXBTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/webservices-testsuite/jaxb-tests/jaxb-war/src/test/java/org/apache/geronimo/testsuite/testset/WebJAXBTest.java?rev=938085&r1=938084&r2=938085&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/webservices-testsuite/jaxb-tests/jaxb-war/src/test/java/org/apache/geronimo/testsuite/testset/WebJAXBTest.java (original)
+++ geronimo/server/trunk/testsuite/webservices-testsuite/jaxb-tests/jaxb-war/src/test/java/org/apache/geronimo/testsuite/testset/WebJAXBTest.java Mon Apr 26 15:13:57 2010
@@ -18,12 +18,9 @@
  */
 package org.apache.geronimo.testsuite.testset;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
 import java.net.URL;
 
+import org.apache.geronimo.testsupport.HttpUtils;
 import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
 
@@ -47,30 +44,9 @@ public class WebJAXBTest extends TestSup
         String warName = System.getProperty("webAppName");
         assertNotNull(warName);
         URL url = new URL(baseURL + warName + address);
-        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
-        connection.setConnectTimeout(30 * 1000);
-        connection.setReadTimeout(30 * 1000);
-        try {
-            BufferedReader reader = 
-                new BufferedReader(new InputStreamReader(connection.getInputStream()));
-            assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
-            assertTrue("Implementation", 
-                       find(reader, "com.sun.xml.bind.v2.runtime.JAXBContextImpl"));
-        } finally {
-            connection.disconnect();
-        }
+        String reply = HttpUtils.doGET(url);     
+        assertTrue("Implementation", 
+                   reply.contains("com.sun.xml.bind.v2.runtime.JAXBContextImpl"));
     }
-
-    private boolean find(BufferedReader reader, String text) 
-        throws IOException {
-        String line = null;
-        while ((line = reader.readLine()) != null) {
-            System.out.println(line);
-            if (line.indexOf(text) != -1) {
-                return true;
-            }
-        }
-        return false;
-    }
-
+  
 }

Modified: geronimo/server/trunk/testsuite/webservices-testsuite/stax-tests/stax-war/src/test/java/org/apache/geronimo/testsuite/testset/WebStaxTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/webservices-testsuite/stax-tests/stax-war/src/test/java/org/apache/geronimo/testsuite/testset/WebStaxTest.java?rev=938085&r1=938084&r2=938085&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/webservices-testsuite/stax-tests/stax-war/src/test/java/org/apache/geronimo/testsuite/testset/WebStaxTest.java (original)
+++ geronimo/server/trunk/testsuite/webservices-testsuite/stax-tests/stax-war/src/test/java/org/apache/geronimo/testsuite/testset/WebStaxTest.java Mon Apr 26 15:13:57 2010
@@ -18,12 +18,9 @@
  */
 package org.apache.geronimo.testsuite.testset;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
 import java.net.URL;
 
+import org.apache.geronimo.testsupport.HttpUtils;
 import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
 
@@ -46,34 +43,13 @@ public class WebStaxTest extends TestSup
         String warName = System.getProperty("webAppName");
         assertNotNull(warName);
         URL url = new URL(baseURL + warName + address);
-        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
-        connection.setConnectTimeout(30 * 1000);
-        connection.setReadTimeout(30 * 1000);
-        try {
-            BufferedReader reader = 
-                new BufferedReader(new InputStreamReader(connection.getInputStream()));
-            assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
-            assertTrue("InputFactory", 
-                       find(reader, "com.ctc.wstx.stax.WstxInputFactory"));
-            assertTrue("OutputFactory", 
-                       find(reader, "com.ctc.wstx.stax.WstxOutputFactory"));
-            assertTrue("EventFactory", 
-                       find(reader, "com.ctc.wstx.stax.WstxEventFactory"));
-        } finally {
-            connection.disconnect();
-        }
+        String reply = HttpUtils.doGET(url);
+        assertTrue("InputFactory", 
+                   reply.contains("com.ctc.wstx.stax.WstxInputFactory"));
+        assertTrue("OutputFactory", 
+                   reply.contains("com.ctc.wstx.stax.WstxOutputFactory"));
+        assertTrue("EventFactory", 
+                   reply.contains("com.ctc.wstx.stax.WstxEventFactory"));
     }
-
-    private boolean find(BufferedReader reader, String text) 
-        throws IOException {
-        String line = null;
-        while ((line = reader.readLine()) != null) {
-            System.out.println(line);
-            if (line.indexOf(text) != -1) {
-                return true;
-            }
-        }
-        return false;
-    }
-
+    
 }