harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r530019 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URL.java test/java/tests/api/java/net/URLConnectionTest.java test/java/tests/api/java/net/URLTest.java
Date Wed, 18 Apr 2007 13:42:49 GMT
Author: ayza
Date: Wed Apr 18 06:42:48 2007
New Revision: 530019

URL: http://svn.apache.org/viewvc?view=rev&rev=530019
Log:
Applying modified version of the patch for HARMONY-3672 ([classlib][luni] Delete a unused
method of java.net.URL)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java?view=diff&rev=530019&r1=530018&r2=530019
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java Wed Apr 18
06:42:48 2007
@@ -921,10 +921,6 @@
         this.query = query;
     }
 
-    URLStreamHandler getStreamHandler() {
-        return strmHandler;
-    }
-
     /**
      * Returns the default port for this URL as defined by the URLStreamHandler.
      * 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java?view=diff&rev=530019&r1=530018&r2=530019
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
Wed Apr 18 06:42:48 2007
@@ -38,6 +38,8 @@
 import java.security.Permission;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.TimeZone;
@@ -89,6 +91,34 @@
         String s = new String(ba);
         assertTrue("Incorrect content returned", s.indexOf("Hello OneHandler") > 0);
 	}
+    
+    /**
+     * @tests java.net.URLConnection#getContent(Class[])
+     */
+    public void test_getContent_LjavalangClass() throws IOException {
+        byte[] ba = new byte[600];
+
+        try{
+            ((InputStream) uc.getContent(null)).read(ba, 0, 600);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e){
+            // expected
+        }
+
+        try{
+            ((InputStream) uc.getContent(new Class[]{})).read(ba, 0, 600);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e){
+            // expected
+        }
+
+        try{
+            ((InputStream) uc.getContent(new Class[]{Class.class})).read(ba, 0, 600);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e){
+            // expected
+        }
+    }
 
 	/**
 	 * @tests java.net.URLConnection#getContentEncoding()
@@ -381,7 +411,6 @@
 	 * @tests java.net.URLConnection#getRequestProperties()
 	 */
 	public void test_getRequestProperties() {
-
 		uc.setRequestProperty("whatever", "you like");
 		Map headers = uc.getRequestProperties();
 
@@ -864,6 +893,7 @@
 	public void test_guessContentTypeFromStreamLjava_io_InputStream() throws IOException {
         InputStream in = uc.getInputStream();
         byte[] bytes = new byte[in.available()];
+
         in.read(bytes, 0, bytes.length);
         in.close();
         // RI fails and it's a non-bug difference.
@@ -871,6 +901,13 @@
                 URLConnection
                         .guessContentTypeFromStream(new ByteArrayInputStream(
                                 bytes)));
+
+        try {
+            URLConnection.guessContentTypeFromStream(null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e){
+            // expected
+        }
     }
 
 	/**
@@ -939,10 +976,14 @@
 	}
 
 	/**
+	 * @throws IOException 
 	 * @tests java.net.URLConnection#setFileNameMap(java.net.FileNameMap)
 	 */
-	public void test_setFileNameMapLjava_net_FileNameMap() {
-		assertTrue("Used to test", true);
+	public void test_setFileNameMapLjava_net_FileNameMap() throws IOException {
+        // nothing happens if set null
+        URLConnection.setFileNameMap(null);
+        // take no effect
+        assertNotNull(URLConnection.getFileNameMap());
 	}
 
 	/**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java?view=diff&rev=530019&r1=530018&r2=530019
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
Wed Apr 18 06:42:48 2007
@@ -21,6 +21,8 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.MalformedURLException;
 import java.net.Proxy;
 import java.net.ProxySelector;
@@ -30,6 +32,7 @@
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.net.URLStreamHandlerFactory;
+import java.net.Proxy.Type;
 import java.security.Permission;
 import java.util.ArrayList;
 import java.util.List;
@@ -836,7 +839,8 @@
 		File resources = Support_Resources.createTempFolder();
 		try {
 			Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
-			u = new URL("file:/" + resources.toString() + "/hyts_htmltest.html");
+            u = new URL("file", "", resources.getAbsolutePath() + 
+                    "/hyts_htmltest.html");
 			u.openConnection();
 			is = (InputStream) u.getContent();
 			is.read(ba = new byte[4096]);
@@ -851,12 +855,36 @@
 		} finally {
 			// Support_Resources.deleteTempFolder(resources);
 		}
-
 	}
 
+    /**
+     * @tests java.net.URL#getContent(class[])
+     */
+    public void test_getContent_LJavaLangClass() throws Exception{
+        byte[] ba;
+        InputStream is;
+        String s;
+
+        File resources = Support_Resources.createTempFolder();
+
+        Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
+        u = new URL("file", "", resources.getAbsolutePath() + 
+                "/hyts_htmltest.html");
+        u.openConnection();
+
+        is = (InputStream) u.getContent(new Class[]{Object.class});
+        is.read(ba = new byte[4096]);
+        s = new String(ba);
+        assertTrue("Incorrect content " + u
+                + " does not contain: \" A Seemingly Non Important String \"",
+                s.indexOf("A Seemingly Non Important String") >= 0);
+
+
+    }
+    
 	/**
-	 * @tests java.net.URL#openStream()
-	 */
+     * @tests java.net.URL#openStream()
+     */
 	public void test_openStream() throws Exception {
         // Regression test for Harmony-1700
         URL BASE = URLTest.class.getClassLoader().getResource(
@@ -875,7 +903,8 @@
 		File resources = Support_Resources.createTempFolder();
 		try {
 			Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
-			u = new URL("file:/" + resources.toString() + "/hyts_htmltest.html");
+            u = new URL("file", "", resources.getAbsolutePath() + 
+                    "/hyts_htmltest.html");
 			// HTTP connection
 			InputStream is1 = u.openStream();
 			assertTrue("Unable to read from stream", is1.read() != 0);
@@ -1039,10 +1068,21 @@
 			fail("Threw exception : " + e.getMessage());
 		}
 	}
+    
+    /**
+     * @throws MalformedURLException
+     * @tests java.net.URL#getDefaultPort()
+     */
+    public void test_getDefaultPort() throws MalformedURLException {
+        u = new URL("http://member12.c++.com:9999");
+        assertEquals(80, u.getDefaultPort());
+        u = new URL("ftp://member12.c++.com:9999/");
+        assertEquals(21, u.getDefaultPort());
+    }
 
 	/**
-	 * @tests java.net.URL#getProtocol()
-	 */
+     * @tests java.net.URL#getProtocol()
+     */
 	public void test_getProtocol() {
 		// Test for method java.lang.String java.net.URL.getProtocol()
 		try {
@@ -1148,6 +1188,30 @@
 
 		}
 	}
+    
+     
+    
+    /**
+     * @throws IOException 
+     * @tests java.net.URL#openConnection(Proxy)
+     */
+    public void test_openConnection_proxy_SelectorCalled()
+            throws IOException {
+        URL httpUrl = new URL("http://"
+                + Support_Configuration.ProxyServerTestHost
+                + "/cgi-bin/test.pl");
+
+        try {
+            httpUrl.openConnection(null);
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e){
+            // expected
+        }
+
+        URLConnection uc = httpUrl.openConnection(new Proxy(Type.SOCKS,
+                new InetSocketAddress(InetAddress.getLocalHost(), 80)));
+        assertEquals(uc.getURL(), httpUrl);
+    }
 
     /**
      * @tests java.net.URL#openConnection()
@@ -1175,6 +1239,37 @@
             } catch (Throwable e) {
                 return null;
             }
+        }
+        
+        public URLConnection openConnection(URL arg0, Proxy proxy) throws IOException {
+            return super.openConnection(u, proxy);
+        }
+    }
+    
+    /**
+     * Check UnsupportedOperationException in openConnection(URL arg0, Proxy proxy)
+     */
+    public void test_openConnection_URL_Proxy() throws Exception {
+        // Regression for HARMONY-1131
+        TestURLStreamHandler lh = new TestURLStreamHandler();
+        URL httpUrl = new URL("http://"
+                + Support_Configuration.ProxyServerTestHost
+                + "/cgi-bin/test.pl");
+        Proxy proxy = new Proxy(Type.SOCKS,
+                new InetSocketAddress(InetAddress.getLocalHost(), 80));
+
+        try {
+            lh.openConnection(null , null);
+            fail("UnsupportedOperationException expected, but nothing was thrown!");
+        } catch (UnsupportedOperationException e) {
+            // Expected
+        }
+
+        try {
+            lh.openConnection(httpUrl , proxy);
+            fail("UnsupportedOperationException expected, but nothing was thrown!");
+        } catch (UnsupportedOperationException e) {
+            // Expected
         }
     }
     



Mime
View raw message