harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r518929 - in /harmony/enhanced/classlib/trunk/modules/luni: build.xml make/exclude.common src/test/java/tests/api/java/net/ExcludedProxyTest.java src/test/java/tests/api/java/net/HttpURLConnectionTest.java
Date Fri, 16 Mar 2007 10:33:39 GMT
Author: liangyx
Date: Fri Mar 16 03:33:32 2007
New Revision: 518929

URL: http://svn.apache.org/viewvc?view=rev&rev=518929
Log:
Apply patch for HARMONY-2097([classlib][luni] rewrite tests/api/java/net/HttpURLConnectionTest.java
which was excluded)

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ExcludedProxyTest.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/build.xml
    harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/build.xml?view=diff&rev=518929&r1=518928&r2=518929
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/build.xml (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/build.xml Fri Mar 16 03:33:32 2007
@@ -282,7 +282,9 @@
                     <pathelement path="${hy.luni.bin.test}"/>
                     <pathelement path="${hy.luni.src.test.resources}"/>
                     <pathelement path="../../build/tests"/>
-                    <pathelement path="${hy.hdk}/build/test/support.jar" />
+		    <fileset dir="${hy.hdk}/build/test/">
+		        <include name="*.jar" />
+		    </fileset>
                 </classpath>
                 <!-- Required by various tests that set security manager etc -->
                 <jvmarg value="-Djava.security.policy=../../support/src/test/resources/config/testing.policy"
/>

Modified: harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common?view=diff&rev=518929&r1=518928&r2=518929
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common Fri Mar 16 03:33:32 2007
@@ -1,6 +1,6 @@
-tests/api/java/net/HttpURLConnectionTest.java
 tests/api/java/net/MulticastSocketTest.java
 tests/api/java/net/SocketImplTest.java
 tests/api/java/net/URLClassLoaderTest.java
 tests/api/java/net/URLConnectionTest.java
 tests/api/java/net/URLTest.java
+tests/api/java/net/ExcludedProxyTest.java

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ExcludedProxyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ExcludedProxyTest.java?view=auto&rev=518929
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ExcludedProxyTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ExcludedProxyTest.java
Fri Mar 16 03:33:32 2007
@@ -0,0 +1,110 @@
+/*
+ *  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 tests.api.java.net;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import tests.support.Support_Configuration;
+import junit.framework.TestCase;
+
+/*
+ * This test is designed for collecting all the testcases which needs a proxy
+ * server. They will be moved to corresponding test class when ProxyHandler of
+ * Jetty is ready in the future.
+ * 
+ */
+
+public class ExcludedProxyTest extends TestCase {
+    /**
+     * @tests java.net.HttpURLConnection#usingProxy()
+     */
+    public void test_usingProxy() throws Exception {
+        try {
+            System.setProperty("http.proxyHost",
+                    Support_Configuration.ProxyServerTestHost);
+
+            URL u1 = new URL("http://" + Support_Configuration.HomeAddress);
+            URLConnection conn1 = u1.openConnection();
+            conn1.getInputStream();
+
+            boolean exception = false;
+            try {
+                System.setProperty("http.proxyPort", "81");
+                URL u3 = new URL("http://"
+                        + Support_Configuration.InetTestAddress);
+                URLConnection conn3 = u3.openConnection();
+                conn3.getInputStream();
+                fail("Should throw IOException");
+            } catch (IOException e) {
+                // expected
+            }
+
+            System.setProperty("http.proxyPort", "80");
+
+            URL u2 = new URL("http://"
+                    + Support_Configuration.ProxyServerTestHost
+                    + "/cgi-bin/test.pl");
+            java.net.HttpURLConnection conn2 = (java.net.HttpURLConnection) u2
+                    .openConnection();
+            conn2.setDoOutput(true);
+            conn2.setRequestMethod("POST");
+            OutputStream out2 = conn2.getOutputStream();
+            String posted2 = "this is a test";
+            out2.write(posted2.getBytes());
+            out2.close();
+            conn2.getResponseCode();
+            InputStream is2 = conn2.getInputStream();
+            String response2 = "";
+            byte[] b2 = new byte[1024];
+            int count2 = 0;
+            while ((count2 = is2.read(b2)) > 0)
+                response2 += new String(b2, 0, count2);
+            assertTrue("Response to POST method invalid", response2
+                    .equals(posted2));
+
+            String posted4 = "just a test";
+            URL u4 = new URL("http://"
+                    + Support_Configuration.ProxyServerTestHost
+                    + "/cgi-bin/test.pl");
+            java.net.HttpURLConnection conn4 = (java.net.HttpURLConnection) u4
+                    .openConnection();
+            conn4.setDoOutput(true);
+            conn4.setRequestMethod("POST");
+            conn4.setRequestProperty("Content-length", String.valueOf(posted4
+                    .length()));
+            OutputStream out = conn4.getOutputStream();
+            out.write(posted4.getBytes());
+            out.close();
+            conn4.getResponseCode();
+            InputStream is = conn4.getInputStream();
+            String response = "";
+            byte[] b4 = new byte[1024];
+            int count = 0;
+            while ((count = is.read(b4)) > 0)
+                response += new String(b4, 0, count);
+            assertTrue("Response to POST method invalid", response
+                    .equals(posted4));
+        } finally {
+            System.setProperties(null);
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ExcludedProxyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java?view=diff&rev=518929&r1=518928&r2=518929
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java
Fri Mar 16 03:33:32 2007
@@ -22,22 +22,19 @@
 import java.io.OutputStream;
 import java.net.CacheRequest;
 import java.net.CacheResponse;
-import java.net.ConnectException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.ResponseCache;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
-import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 
 import tests.support.Support_Configuration;
-import tests.support.resource.Support_Resources;
+import tests.support.Support_Jetty;
 
 public class HttpURLConnectionTest extends junit.framework.TestCase {
 
@@ -56,6 +53,17 @@
     private Map<String, List<String>> mockHeaderMap;
 
     private InputStream mockIs = new MockInputStream();
+    
+    private static int port;
+
+    static {
+        // run-once set up
+        try {
+            port = Support_Jetty.startDefaultHttpServer();
+        } catch (Exception e) {
+            fail("Exception during setup jetty : " + e.getMessage());
+        }
+    }
 
     /**
      * @tests java.net.HttpURLConnection#getResponseCode()
@@ -193,85 +201,9 @@
     }
 
     /**
-     * @tests java.net.HttpURLConnection#usingProxy()
-     */
-    public void test_usingProxy() throws Exception {
-        try {
-            System.setProperty("http.proxyHost",
-                    Support_Configuration.ProxyServerTestHost);
-
-            URL u1 = new URL("http://" + Support_Configuration.HomeAddress);
-            URLConnection conn1 = u1.openConnection();
-            conn1.getInputStream();
-
-            boolean exception = false;
-            try {
-                System.setProperty("http.proxyPort", "81");
-                URL u3 = new URL("http://"
-                        + Support_Configuration.InetTestAddress);
-                URLConnection conn3 = u3.openConnection();
-                conn3.getInputStream();
-                fail("Should throw IOException");
-            } catch (IOException e) {
-                //expected
-            }
-            
-            System.setProperty("http.proxyPort", "80");
-
-            URL u2 = new URL("http://"
-                    + Support_Configuration.ProxyServerTestHost
-                    + "/cgi-bin/test.pl");
-            java.net.HttpURLConnection conn2 = (java.net.HttpURLConnection) u2
-                    .openConnection();
-            conn2.setDoOutput(true);
-            conn2.setRequestMethod("POST");
-            OutputStream out2 = conn2.getOutputStream();
-            String posted2 = "this is a test";
-            out2.write(posted2.getBytes());
-            out2.close();
-            conn2.getResponseCode();
-            InputStream is2 = conn2.getInputStream();
-            String response2 = "";
-            byte[] b2 = new byte[1024];
-            int count2 = 0;
-            while ((count2 = is2.read(b2)) > 0)
-                response2 += new String(b2, 0, count2);
-            assertTrue("Response to POST method invalid", response2
-                    .equals(posted2));
-
-            String posted4 = "just a test";
-            URL u4 = new URL("http://"
-                    + Support_Configuration.ProxyServerTestHost
-                    + "/cgi-bin/test.pl");
-            java.net.HttpURLConnection conn4 = (java.net.HttpURLConnection) u4
-                    .openConnection();
-            conn4.setDoOutput(true);
-            conn4.setRequestMethod("POST");
-            conn4.setRequestProperty("Content-length", String.valueOf(posted4
-                    .length()));
-            OutputStream out = conn4.getOutputStream();
-            out.write(posted4.getBytes());
-            out.close();
-            conn4.getResponseCode();
-            InputStream is = conn4.getInputStream();
-            String response = "";
-            byte[] b4 = new byte[1024];
-            int count = 0;
-            while ((count = is.read(b4)) > 0)
-                response += new String(b4, 0, count);
-            assertTrue("Response to POST method invalid", response
-                    .equals(posted4));
-        } finally {
-            System.setProperties(null);
-        }
-    }
-
-    /**
      * @tests java.net.HttpURLConnection#setFixedLengthStreamingMode_I()
      */
     public void test_setFixedLengthStreamingModeI() throws Exception {
-        url = new URL("http://" + Support_Configuration.InetTestAddress);
-        uc = (HttpURLConnection) url.openConnection();
         try {
             uc.setFixedLengthStreamingMode(-1);
             fail("should throw IllegalArgumentException");
@@ -313,8 +245,6 @@
      * @tests java.net.HttpURLConnection#setChunkedStreamingMode_I()
      */
     public void test_setChunkedStreamingModeI() throws Exception {
-        url = new URL("http://" + Support_Configuration.InetTestAddress);
-        uc = (HttpURLConnection) url.openConnection();
         uc.setChunkedStreamingMode(0);
         uc.setChunkedStreamingMode(-1);
         uc.setChunkedStreamingMode(-2);
@@ -360,8 +290,7 @@
      */
     public void test_setFixedLengthStreamingModeI_effect() throws Exception {
         String posted = "just a test";
-        URL u = new URL("http://" + Support_Configuration.InetTestAddress);
-        java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
+        java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
                 .openConnection();
         conn.setDoOutput(true);
         conn.setRequestMethod("POST");
@@ -393,8 +322,7 @@
         String posted = "just a test";
         // for test, use half length of the string
         int chunkSize = posted.length() / 2;
-        URL u = new URL("http://" + Support_Configuration.InetTestAddress);
-        java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
+        java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
                 .openConnection();
         conn.setDoOutput(true);
         conn.setRequestMethod("POST");
@@ -414,8 +342,6 @@
     }
 
     public void test_getOutputStream_afterConnection() throws Exception {
-        URLConnection uc = new URL("http://"
-                + Support_Configuration.InetTestAddress).openConnection();
         uc.setDoOutput(true);
         uc.connect();
         assertNotNull(uc.getOutputStream());
@@ -430,8 +356,7 @@
         // set cache before URLConnection created, or it does not take effect
         ResponseCache rc = new MockNonCachedResponseCache();
         ResponseCache.setDefault(rc);
-        URLConnection uc = new URL("http://"
-                + Support_Configuration.InetTestAddress).openConnection();
+        uc = (HttpURLConnection) url.openConnection();
         assertFalse(isGetCalled);
         uc.setUseCaches(true);
         uc.setDoOutput(true);
@@ -454,8 +379,7 @@
         ResponseCache rc = new MockNonCachedResponseCache();
         ResponseCache.setDefault(rc);
         uc.setUseCaches(true);
-        URLConnection uc = new URL("http://"
-                + Support_Configuration.InetTestAddress).openConnection();
+        URLConnection uc = url.openConnection();
         uc.setDoOutput(true);
         assertFalse(isGetCalled);
         uc.connect();
@@ -476,8 +400,7 @@
         // set cache before URLConnection created, or it does not take effect
         ResponseCache rc = new MockNonCachedResponseCache();
         ResponseCache.setDefault(rc);
-        URLConnection uc = new URL("http://"
-                + Support_Configuration.InetTestAddress).openConnection();
+        uc = (HttpURLConnection) url.openConnection();
         assertFalse(isGetCalled);
         uc.setDoOutput(true);
         uc.setUseCaches(true);
@@ -508,8 +431,7 @@
         // set cache before URLConnection created, or it does not take effect
         ResponseCache rc = new MockNonCachedResponseCache();
         ResponseCache.setDefault(rc);
-        URLConnection uc = new URL("http://"
-                + Support_Configuration.InetTestAddress).openConnection();
+        URLConnection uc = url.openConnection();
         assertFalse(isGetCalled);
         uc.setDoOutput(true);
         uc.setUseCaches(true);
@@ -528,8 +450,7 @@
      */
     public void test_UseCache_HttpURLConnection_NonCached() throws IOException {
         ResponseCache.setDefault(new MockNonCachedResponseCache());
-        URL u = new URL("http://" + Support_Configuration.InetTestAddress);
-        HttpURLConnection uc = (HttpURLConnection) u.openConnection();
+        uc = (HttpURLConnection) url.openConnection();
 
         // default useCaches is true
         assertTrue(uc.getUseCaches());
@@ -637,8 +558,7 @@
     public void test_UseCache_HttpURLConnection_NoCached_GetOutputStream()
             throws Exception {
         ResponseCache.setDefault(new MockNonCachedResponseCache());
-        URL u = new URL("http://" + Support_Configuration.InetTestAddress);
-        HttpURLConnection uc = (HttpURLConnection) u.openConnection();
+        uc = (HttpURLConnection) url.openConnection();
         uc.setChunkedStreamingMode(10);
         uc.setDoOutput(true);
         uc.getOutputStream();
@@ -769,8 +689,7 @@
 
     protected void setUp() {
         try {
-            url = new URL(Support_Resources
-                    .getResourceURL("/URLConnectionTest/Harmony.html"));
+            url = new URL("http://localhost:"+port+"/");
             uc = (HttpURLConnection) url.openConnection();
         } catch (Exception e) {
             fail("Exception during setup : " + e.getMessage());



Mime
View raw message