Refactoring to allow easier re-use.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 31 Oct 2009 11:01:48 +0000 (11:01 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 31 Oct 2009 11:01:48 +0000 (11:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@831530 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/catalina/startup/TestTomcat.java
test/org/apache/catalina/startup/TestTomcatBase.java

index 98b4c01..8984137 100644 (file)
  */
 package org.apache.catalina.startup;
 
-import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
 import java.net.URL;
-import java.util.List;
-import java.util.Map;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -216,35 +211,4 @@ public class TestTomcat extends TestTomcatBase {
         assertEquals(HttpServletResponse.SC_OK, rc);
     }
 
-    /**
-     *  Wrapper for getting the response.
-     */
-    public static ByteChunk getUrl(String path) throws IOException {
-        ByteChunk out = new ByteChunk();
-        getUrl(path, out, null);
-        return out;
-    }
-
-    public static int getUrl(String path, 
-                             ByteChunk out, 
-                             Map<String, List<String>> resHead) throws IOException {
-        URL url = new URL(path);
-        HttpURLConnection connection = 
-            (HttpURLConnection) url.openConnection();
-        connection.setReadTimeout(100000);
-        connection.connect();
-        int rc = connection.getResponseCode();
-        if (resHead != null) {
-            Map<String, List<String>> head = connection.getHeaderFields();
-            resHead.putAll(head);
-        }
-        InputStream is = connection.getInputStream();
-        BufferedInputStream bis = new BufferedInputStream(is);
-        byte[] buf = new byte[2048];
-        int rd = 0;
-        while((rd = bis.read(buf)) > 0) {
-            out.append(buf, 0, rd);
-        }
-        return rc;
-    }
 }
index 360c69f..3c69846 100644 (file)
  */
 package org.apache.catalina.startup;
 
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.tomcat.util.buf.ByteChunk;
+
 import junit.framework.TestCase;
 
 /**
@@ -83,4 +91,37 @@ public abstract class TestTomcatBase extends TestCase {
             out.print("<html><body><p>Hello World</p></body></html>");
         }
     }
+    
+
+    /**
+     *  Wrapper for getting the response.
+     */
+    public static ByteChunk getUrl(String path) throws IOException {
+        ByteChunk out = new ByteChunk();
+        getUrl(path, out, null);
+        return out;
+    }
+
+    public static int getUrl(String path, 
+                             ByteChunk out, 
+                             Map<String, List<String>> resHead) throws IOException {
+        URL url = new URL(path);
+        HttpURLConnection connection = 
+            (HttpURLConnection) url.openConnection();
+        connection.setReadTimeout(100000);
+        connection.connect();
+        int rc = connection.getResponseCode();
+        if (resHead != null) {
+            Map<String, List<String>> head = connection.getHeaderFields();
+            resHead.putAll(head);
+        }
+        InputStream is = connection.getInputStream();
+        BufferedInputStream bis = new BufferedInputStream(is);
+        byte[] buf = new byte[2048];
+        int rd = 0;
+        while((rd = bis.read(buf)) > 0) {
+            out.append(buf, 0, rd);
+        }
+        return rc;
+    }
 }