You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 12:47:39 UTC

svn commit: r386058 [32/49] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/archive/make/common/ modules/archive/src/test/java/tests/ modules/archive/src/test/java/tests/api/ modules/archive/src/test/java/tests/api/java/ modules/archive/...

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,424 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+import tests.support.Support_Configuration;
+import tests.support.resource.Support_Resources;
+
+public class URLClassLoaderTest extends junit.framework.TestCase {
+
+	class BogusClassLoader extends ClassLoader {
+		public URL getResource(String res) {
+			try {
+				return new URL("http://test/BogusClassLoader");
+			} catch (MalformedURLException e) {
+				return null;
+			}
+		}
+	}
+
+	URLClassLoader ucl;
+
+	/**
+	 * @tests java.net.URLClassLoader#URLClassLoader(java.net.URL[])
+	 */
+	public void test_Constructor$Ljava_net_URL() {
+		try {
+			// ClassLoader cl = new BogusClassLoader();
+			URL[] u = new URL[0];
+			ucl = new URLClassLoader(u);
+			assertTrue("Failed to set parent", ucl != null
+					&& ucl.getParent() == URLClassLoader.getSystemClassLoader());
+
+			URLClassLoader loader = new URLClassLoader(new URL[] { null });
+			boolean exception = false;
+			try {
+				Class.forName("test", false, loader);
+			} catch (ClassNotFoundException e) {
+				exception = true;
+			}
+			assertTrue("Should throw ClassNotFoundException", exception);
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#URLClassLoader(java.net.URL[],
+	 *        java.lang.ClassLoader)
+	 */
+	public void test_Constructor$Ljava_net_URLLjava_lang_ClassLoader() {
+		ClassLoader cl = new BogusClassLoader();
+		URL[] u = new URL[0];
+		ucl = new URLClassLoader(u, cl);
+		URL res = ucl.getResource("J");
+		assertTrue("Failed to set parent", res == null ? false : res.getFile()
+				.equals("/BogusClassLoader"));
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#findResources(java.lang.String)
+	 */
+	public void test_findResourcesLjava_lang_String() {
+		Enumeration res = null;
+		String[] resValues = { "This is a test resource file.",
+				"This is a resource from a subdir" };
+		try {
+			URL[] urls = new URL[2];
+			urls[0] = new URL(Support_Resources.getResourceURL("/"));
+			urls[1] = new URL(Support_Resources.getResourceURL("/subdir1/"));
+			ucl = new URLClassLoader(urls);
+			res = ucl.findResources("RESOURCE.TXT");
+
+		} catch (Exception e) {
+			fail("Exception during findResource : " + e.getMessage());
+		}
+		
+		if (res == null) {
+			fail("Failed to locate resources");
+		}
+
+		int i = 0;
+		while (res.hasMoreElements()) {
+			StringBuffer sb = new StringBuffer();
+			try {
+				java.io.InputStream is = ((URL) res.nextElement()).openStream();
+				int c;
+				while ((c = is.read()) != -1)
+					sb.append((char) c);
+				assertTrue("Returned incorrect resource/or in wrong order: "
+						+ sb.toString(), sb.toString().equals(resValues[i++]));
+			} catch (java.io.IOException e) {
+				fail("Exception during findResourcesTest: "
+						+ e.toString());
+			}
+		}
+		assertTrue("Incorrect number of resources returned: " + i, i == 2);
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#getURLs()
+	 */
+	public void test_getURLs() {
+		try {
+			URL[] urls = new URL[4];
+			urls[0] = new URL("http://" + Support_Configuration.HomeAddress);
+			urls[1] = new URL("http://" + Support_Configuration.TestResources
+					+ "/");
+			urls[2] = new URL("ftp://" + Support_Configuration.TestResources
+					+ "/");
+			urls[3] = new URL("jar:file:c://"
+					+ Support_Configuration.TestResources + "!/");
+			ucl = new URLClassLoader(urls);
+			URL[] ucUrls = ucl.getURLs();
+			for (int i = 0; i < urls.length; i++)
+				assertTrue("Returned incorrect URL[]", urls[i]
+						.equals(ucUrls[i]));
+		} catch (java.io.IOException e) {
+			fail("Exception during getURLS test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#newInstance(java.net.URL[])
+	 */
+	public void test_newInstance$Ljava_net_URL() {
+		// Verify that loaded class' have correct permissions
+		Class cl = null;
+		URL res = null;
+		URL[] urls = null;
+		try {
+			urls = new URL[1];
+			urls[0] = new URL(Support_Resources.getResourceURL("/UCL/UCL.jar"));
+			ucl = URLClassLoader.newInstance(urls);
+			cl = ucl.loadClass("ucl.ResClass");
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		} catch (Error e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+
+		try {
+			res = cl.getClassLoader().getResource("XX.class");
+			assertTrue("Failed to load class", cl != null);
+			assertTrue(
+					"Loaded class unable to access resource from same codeSource",
+					res != null);
+			cl = null;
+		} catch (Error e) {
+			fail("Test error : " + e.getMessage());
+		}
+		try {
+			urls[0] = new URL("jar:"
+					+ Support_Resources.getResourceURL("/UCL/UCL.jar!/"));
+			ucl = URLClassLoader.newInstance(urls);
+			cl = ucl.loadClass("ucl.ResClass");
+		} catch (Exception e) {
+			fail("Exception using explicit jar : " + e.getMessage());
+		}
+		assertTrue("Failed to load class from explicit jar URL", cl != null);
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#newInstance(java.net.URL[],
+	 *        java.lang.ClassLoader)
+	 */
+	public void test_newInstance$Ljava_net_URLLjava_lang_ClassLoader() {
+		ClassLoader cl = new BogusClassLoader();
+		URL[] u = new URL[0];
+		ucl = URLClassLoader.newInstance(u, cl);
+		URL res = ucl.getResource("J");
+		assertTrue("Failed to set parent", res == null ? false : res.getFile()
+				.equals("/BogusClassLoader"));
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#URLClassLoader(java.net.URL[],
+	 *        java.lang.ClassLoader, java.net.URLStreamHandlerFactory)
+	 */
+	public void test_Constructor$Ljava_net_URLLjava_lang_ClassLoaderLjava_net_URLStreamHandlerFactory() {
+		class TestFactory implements URLStreamHandlerFactory {
+			public URLStreamHandler createURLStreamHandler(String protocol) {
+				return null;
+			}
+		}
+		ClassLoader cl = new BogusClassLoader();
+		URL[] u = new URL[0];
+		ucl = new URLClassLoader(u, cl, new TestFactory());
+		URL res = ucl.getResource("J");
+		assertTrue("Failed to set parent", res == null ? false : res.getFile()
+				.equals("/BogusClassLoader"));
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#findClass(java.lang.String)
+	 */
+	public void test_findClassLjava_lang_String() {
+		File resources = Support_Resources.createTempFolder();
+		String resPath = resources.toString();
+		if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\')
+			resPath = resPath.substring(1);
+
+		try {
+			java.net.URL[] urls = new java.net.URL[1];
+			java.net.URLClassLoader ucl = null;
+			boolean classFound;
+			boolean exception;
+			boolean goodException;
+			Enumeration en;
+			boolean resourcesFound;
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_11.jar");
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_12.jar");
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_13.jar");
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_14.jar");
+			urls[0] = new URL("file:/" + resPath + "/JarIndex/hyts_11.jar");
+			ucl = URLClassLoader.newInstance(urls, null);
+			URL resURL = ucl.findResource("Test.txt");
+			URL reference = new URL("jar:file:/" + resPath.replace('\\', '/')
+					+ "/JarIndex/hyts_14.jar!/Test.txt");
+			assertTrue("Resource not found: " + resURL + " ref: " + reference,
+					resURL.equals(reference));
+
+			classFound = false;
+			try {
+				Class c = Class.forName("cpack.CNothing", true, ucl);
+				if (c != null)
+					classFound = true;
+			} catch (ClassNotFoundException e) {
+				classFound = false;
+			}
+			assertTrue("Class not found (1)", classFound);
+
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_21.jar");
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_22.jar");
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_23.jar");
+			urls[0] = new URL("file:/" + resPath + "/JarIndex/hyts_21.jar");
+			ucl = URLClassLoader.newInstance(urls, null);
+			en = ucl.findResources("bpack/");
+
+			try {
+				resourcesFound = true;
+				URL url1 = (URL) en.nextElement();
+				URL url2 = (URL) en.nextElement();
+				System.out.println(url1);
+				System.out.println(url2);
+				resourcesFound = resourcesFound
+						&& url1.equals(new URL("jar:file:/"
+								+ resPath.replace('\\', '/')
+								+ "/JarIndex/hyts_22.jar!/bpack/"));
+				resourcesFound = resourcesFound
+						&& url2.equals(new URL("jar:file:/"
+								+ resPath.replace('\\', '/')
+								+ "/JarIndex/hyts_23.jar!/bpack/"));
+				if (en.hasMoreElements())
+					resourcesFound = false;
+			} catch (NoSuchElementException e) {
+				resourcesFound = false;
+			}
+			assertTrue("Resources not found (1)", resourcesFound);
+
+			classFound = false;
+			try {
+				Class c = Class.forName("bpack.Homer", true, ucl);
+				if (c != null)
+					classFound = true;
+			} catch (ClassNotFoundException e) {
+				classFound = false;
+			}
+			assertTrue("Class not found (2)", classFound);
+
+			exception = false;
+			try {
+				Class.forName("bpack.Bart", true, ucl);
+			} catch (com.ibm.oti.util.InvalidJarIndexException e) {
+				exception = true;
+			} catch (ClassNotFoundException e) {
+				exception = false;
+			}
+			assertTrue("InvalidJarIndexException should be thrown", exception);
+
+			goodException = false;
+			try {
+				Class.forName("Main4", true, ucl);
+			} catch (com.ibm.oti.util.InvalidJarIndexException e) {
+				goodException = false;
+			} catch (ClassNotFoundException e) {
+				goodException = true;
+			}
+			assertTrue("ClassNotFoundException should be thrown", goodException);
+
+			Support_Resources
+					.copyFile(resources, "JarIndex", "hyts_22-new.jar");
+			urls[0] = new URL("file:/" + resPath + "/JarIndex/hyts_22-new.jar");
+			ucl = URLClassLoader.newInstance(urls, null);
+			assertTrue("Cannot find resource",
+					ucl.findResource("cpack/") != null);
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_11.jar");
+			urls[0] = new URL("file:/" + resPath + "/JarIndex/hyts_31.jar");
+			ucl = URLClassLoader.newInstance(urls, null);
+
+			exception = false;
+			try {
+				Class.forName("cpack.Mock", true, ucl);
+			} catch (com.ibm.oti.util.InvalidJarIndexException e) {
+				exception = false;
+			} catch (ClassNotFoundException e) {
+				exception = true;
+			}
+			assertTrue("InvalidJarIndexException should be thrown", exception);
+
+			// testing circular reference
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_41.jar");
+			Support_Resources.copyFile(resources, "JarIndex", "hyts_42.jar");
+			urls[0] = new URL("file:/" + resPath + "/JarIndex/hyts_41.jar");
+			ucl = URLClassLoader.newInstance(urls, null);
+			en = ucl.findResources("bpack/");
+			try {
+				resourcesFound = true;
+				resourcesFound = resourcesFound
+						&& ((URL) en.nextElement()).equals(new URL("jar:file:/"
+								+ resPath.replace('\\', '/')
+								+ "/JarIndex/hyts_42.jar!/bpack/"));
+				if (en.hasMoreElements())
+					resourcesFound = false;
+			} catch (NoSuchElementException e) {
+				resourcesFound = false;
+			}
+			assertTrue("Resources not found (2)", resourcesFound);
+		} catch (MalformedURLException e) {
+			fail("Unexpected MalformedURLException during test : " + e);
+		} catch (java.io.IOException e) {
+			fail("Unexpected IOException during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#findResource(java.lang.String)
+	 */
+	public void test_findResourceLjava_lang_String() {
+		URL res = null;
+		try {
+			URL[] urls = new URL[2];
+			urls[0] = new URL("http://" + Support_Configuration.HomeAddress);
+			urls[1] = new URL(Support_Resources.getResourceURL("/"));
+			ucl = new URLClassLoader(urls);
+			res = ucl.findResource("RESOURCE.TXT");
+		} catch (Exception e) {
+			fail("Exception during findResource : " + e.getMessage());
+		}
+		
+		if (res == null) {
+			fail("Failed to locate resource");
+		}
+		StringBuffer sb = new StringBuffer();
+		try {
+			java.io.InputStream is = res.openStream();
+
+			int c;
+			while ((c = is.read()) != -1)
+				sb.append((char) c);
+			is.close();
+		} catch (java.io.IOException e) {
+		}
+		assertTrue("Returned incorrect resource", !sb.toString().equals(
+				"This is a test resource file"));
+	}
+
+	/**
+	 * @tests java.net.URLClassLoader#getResource(java.lang.String)
+	 */
+	public void test_getResourceLjava_lang_String() {
+		try {
+			URL url1 = new URL("file:///");
+			java.net.URLClassLoader loader = new java.net.URLClassLoader(
+					new URL[] { url1 }, null);
+			long start = System.currentTimeMillis();
+			// try without the leading /
+			URL result = loader.getResource("dir1/file1");
+			long end = System.currentTimeMillis();
+			long time = end - start;
+			if (time < 100)
+				time = 100;
+
+			start = System.currentTimeMillis();
+			// try with the leading forward slash
+			result = loader.getResource("/dir1/file1");
+			end = System.currentTimeMillis();
+			long uncTime = end - start;
+			assertTrue("too long. UNC path formed? UNC time: " + uncTime
+					+ " regular time: " + time, uncTime <= (time * 4));
+		} catch (MalformedURLException e) {
+			fail("unexpected: " + e);
+		}
+	}
+
+	protected void setUp() {
+
+	}
+
+	protected void tearDown() {
+
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,983 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FilePermission;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Authenticator;
+import java.net.FileNameMap;
+import java.net.HttpURLConnection;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.PasswordAuthentication;
+import java.net.ProtocolException;
+import java.net.SocketPermission;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.Permission;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+import tests.support.Support_Configuration;
+import tests.support.Support_HttpServer;
+import tests.support.Support_HttpServerSocket;
+import tests.support.Support_HttpTests;
+import tests.support.Support_PortManager;
+import tests.support.Support_URLConnector;
+import tests.support.resource.Support_Resources;
+
+public class URLConnectionTest extends junit.framework.TestCase {
+
+	URL url;
+
+	URLConnection uc;
+
+	/**
+	 * @tests java.net.URLConnection#getAllowUserInteraction()
+	 */
+	public void test_getAllowUserInteraction() {
+		uc.setAllowUserInteraction(false);
+		assertTrue("getAllowUserInteraction should have returned false", !uc
+				.getAllowUserInteraction());
+		uc.setAllowUserInteraction(true);
+		assertTrue("getAllowUserInteraction should have returned true", uc
+				.getAllowUserInteraction());
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getContent()
+	 */
+	public void test_getContent() {
+		try {
+			byte[] ba = new byte[600];
+			((InputStream) uc.getContent()).read(ba, 0, 600);
+			String s = new String(ba);
+			assertTrue("Incorrect content returned", s.indexOf("20060107") > 0);
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getContentEncoding()
+	 */
+	public void test_getContentEncoding() {
+		// should not be known for a file
+		assertTrue("getContentEncoding failed: " + uc.getContentEncoding(), uc
+				.getContentEncoding() == null);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getContentLength()
+	 */
+	public void test_getContentLength() {
+		assertTrue("getContentLength failed: " + uc.getContentLength(), uc
+				.getContentLength() == 943);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getContentType()
+	 */
+	public void test_getContentType() {
+		// should not be known for a file
+		assertTrue("getContentType failed: " + uc.getContentType(), uc
+				.getContentType().equals("text/html"));
+
+		try {
+			File resources = Support_Resources.createTempFolder();
+			Support_Resources.copyFile(resources, null, "Harmony.GIF");
+			URL url = new URL("file:/" + resources.toString() + "/Harmony.GIF");
+			URLConnection conn = url.openConnection();
+			assertTrue("type not GIF", conn.getContentType()
+					.equals("image/gif"));
+		} catch (MalformedURLException e) {
+			fail("MalformedURLException for .gif");
+		} catch (IOException e) {
+			fail("IOException for .gif");
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getDate()
+	 */
+	public void test_getDate() {
+		// should be greater than 930000000000L which represents the past
+		if (uc.getDate() == 0) {
+			System.out
+					.println("WARNING: server does not support 'Date', in test_getDate");
+		} else {
+			assertTrue("getDate gave wrong date: " + uc.getDate(),
+					uc.getDate() > 930000000000L);
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getDefaultAllowUserInteraction()
+	 */
+	public void test_getDefaultAllowUserInteraction() {
+		boolean oldSetting = URLConnection.getDefaultAllowUserInteraction();
+		URLConnection.setDefaultAllowUserInteraction(false);
+		assertTrue("getDefaultAllowUserInteraction should have returned false",
+				!URLConnection.getDefaultAllowUserInteraction());
+		URLConnection.setDefaultAllowUserInteraction(true);
+		assertTrue("getDefaultAllowUserInteraction should have returned true",
+				URLConnection.getDefaultAllowUserInteraction());
+		URLConnection.setDefaultAllowUserInteraction(oldSetting);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getDefaultRequestProperty(java.lang.String)
+	 */
+	public void test_getDefaultRequestPropertyLjava_lang_String() {
+		try {
+			URLConnection.setDefaultRequestProperty("Shmoo", "Blah");
+			assertTrue(
+					"setDefaultRequestProperty should have returned: null, but returned: "
+							+ URLConnection.getDefaultRequestProperty("Shmoo"),
+					URLConnection.getDefaultRequestProperty("Shmoo") == null);
+			URLConnection.setDefaultRequestProperty("Shmoo", "Boom");
+			assertTrue(
+					"setDefaultRequestProperty should have returned: null, but returned: "
+							+ URLConnection.getDefaultRequestProperty("Shmoo"),
+					URLConnection.getDefaultRequestProperty("Shmoo") == null);
+			assertTrue(
+					"setDefaultRequestProperty should have returned: null, but returned: "
+							+ URLConnection.getDefaultRequestProperty("Kapow"),
+					URLConnection.getDefaultRequestProperty("Kapow") == null);
+			URLConnection.setDefaultRequestProperty("Shmoo", null);
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getDefaultUseCaches()
+	 */
+	public void test_getDefaultUseCaches() {
+		boolean oldSetting = uc.getDefaultUseCaches();
+		uc.setDefaultUseCaches(false);
+		assertTrue("getDefaultUseCaches should have returned false", !uc
+				.getDefaultUseCaches());
+		uc.setDefaultUseCaches(true);
+		assertTrue("getDefaultUseCaches should have returned true", uc
+				.getDefaultUseCaches());
+		uc.setDefaultUseCaches(oldSetting);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getDoInput()
+	 */
+	public void test_getDoInput() {
+		assertTrue("Should be set to true by default", uc.getDoInput());
+		uc.setDoInput(true);
+		assertTrue("Should have been set to true", uc.getDoInput());
+		uc.setDoInput(false);
+		assertTrue("Should have been set to false", !uc.getDoInput());
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getDoOutput()
+	 */
+	public void test_getDoOutput() {
+		assertTrue("Should be set to false by default", !uc.getDoOutput());
+		uc.setDoOutput(true);
+		assertTrue("Should have been set to true", uc.getDoOutput());
+		uc.setDoOutput(false);
+		assertTrue("Should have been set to false", !uc.getDoOutput());
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getExpiration()
+	 */
+	public void test_getExpiration() {
+		// should be unknown
+		assertTrue("getExpiration returned wrong expiration: "
+				+ uc.getExpiration(), uc.getExpiration() == 0);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getFileNameMap()
+	 */
+	public void test_getFileNameMap() {
+		uc.setFileNameMap(new FileNameMap() {
+			public String getContentTypeFor(String fileName) {
+				return "Spam!";
+			}
+		});
+		try {
+			assertTrue("Incorrect FileNameMap returned", uc.getFileNameMap()
+					.getContentTypeFor(null).equals("Spam!"));
+		} finally {
+			// unset the map so other tests don't fail
+			uc.setFileNameMap(null);
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getHeaderField(int)
+	 */
+	public void test_getHeaderFieldI() {
+		int i = 0;
+		String hf;
+		boolean foundResponse = false;
+		while ((hf = uc.getHeaderField(i++)) != null) {
+			if (hf.equals(Support_Configuration.HomeAddressSoftware))
+				foundResponse = true;
+		}
+		assertTrue("Could not find header field containing \""
+				+ Support_Configuration.HomeAddressSoftware + "\"",
+				foundResponse);
+
+		i = 0;
+		foundResponse = false;
+		while ((hf = uc.getHeaderField(i++)) != null) {
+			if (hf.equals(Support_Configuration.HomeAddressResponse))
+				foundResponse = true;
+		}
+		assertTrue("Could not find header field containing \""
+				+ Support_Configuration.HomeAddressResponse + "\"",
+				foundResponse);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#addRequestProperty(java.lang.String,java.lang.String)
+	 */
+	public void test_addRequestPropertyLjava_lang_StringLjava_lang_String() {
+		uc.setRequestProperty("prop", "yo");
+		uc.setRequestProperty("prop", "yo2");
+		assertEquals("yo2", uc.getRequestProperty("prop"));
+		Map map = uc.getRequestProperties();
+		List props = (List) uc.getRequestProperties().get("prop");
+		assertTrue(props.size() == 1);
+
+		try {
+			// the map should be unmodifiable
+			map.put("hi", "bye");
+			fail();
+		} catch (UnsupportedOperationException e) {
+		}
+		try {
+			// the list should be unmodifiable
+			props.add("hi");
+			fail();
+		} catch (UnsupportedOperationException e) {
+		}
+
+		try {
+			File resources = Support_Resources.createTempFolder();
+			Support_Resources.copyFile(resources, null, "hyts_att.jar");
+			URL fUrl1 = new URL("jar:file:" + resources.getPath()
+					+ "/hyts_att.jar!/");
+			JarURLConnection con1 = (JarURLConnection) fUrl1.openConnection();
+			map = con1.getRequestProperties();
+			assertNotNull(map);
+			assertTrue(map.size() == 0);
+			try {
+				// the map should be unmodifiable
+				map.put("hi", "bye");
+				fail();
+			} catch (UnsupportedOperationException e) {
+			}
+		} catch (IOException e) {
+			fail();
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getHeaderFields()
+	 */
+	public void test_getHeaderFields() {
+		try {
+			uc.getInputStream();
+		} catch (IOException e) {
+			fail();
+		}
+
+		Map headers = uc.getHeaderFields();
+		assertNotNull(headers);
+
+		// content-length should always appear
+		List list = (List) headers.get("Content-Length");
+		if (list == null) {
+			list = (List) headers.get("content-length");
+		}
+		assertNotNull(list);
+		String contentLength = (String) list.get(0);
+		assertNotNull(contentLength);
+
+		// there should be at least 2 headers
+		assertTrue(headers.size() > 1);
+		try {
+			File resources = Support_Resources.createTempFolder();
+			Support_Resources.copyFile(resources, null, "hyts_att.jar");
+			URL fUrl1 = new URL("jar:file:" + resources.getPath()
+					+ "/hyts_att.jar!/");
+			JarURLConnection con1 = (JarURLConnection) fUrl1.openConnection();
+			headers = con1.getHeaderFields();
+			assertNotNull(headers);
+			assertTrue(headers.size() == 0);
+			try {
+				// the map should be unmodifiable
+				headers.put("hi", "bye");
+				fail();
+			} catch (UnsupportedOperationException e) {
+			}
+		} catch (IOException e) {
+			fail();
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getRequestProperties()
+	 */
+	public void test_getRequestProperties() {
+
+		uc.setRequestProperty("whatever", "you like");
+		Map headers = uc.getRequestProperties();
+
+		// content-length should always appear
+		List header = (List) headers.get("whatever");
+		assertNotNull(header);
+
+		assertEquals(header.get(0), "you like");
+
+		assertTrue(headers.size() >= 1);
+
+		try {
+			// the map should be unmodifiable
+			headers.put("hi", "bye");
+			fail();
+		} catch (UnsupportedOperationException e) {
+		}
+		try {
+			// the list should be unmodifiable
+			header.add("hi");
+			fail();
+		} catch (UnsupportedOperationException e) {
+		}
+
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getHeaderField(java.lang.String)
+	 */
+	public void test_getHeaderFieldLjava_lang_String() {
+		String hf;
+		hf = uc.getHeaderField("Content-Encoding");
+		if (hf != null) {
+			assertTrue(
+					"Wrong value returned for header field 'Content-Encoding': "
+							+ hf, hf == null);
+		}
+		hf = uc.getHeaderField("Content-Length");
+		if (hf != null) {
+			assertTrue(
+					"Wrong value returned for header field 'Content-Length': "
+							+ hf, hf.equals("943"));
+		}
+		hf = uc.getHeaderField("Content-Type");
+		if (hf != null) {
+			assertTrue("Wrong value returned for header field 'Content-Type': "
+					+ hf, hf.equals("text/html"));
+		}
+		hf = uc.getHeaderField("content-type");
+		if (hf != null) {
+			assertTrue("Wrong value returned for header field 'content-type': "
+					+ hf, hf.equals("text/html"));
+		}
+		hf = uc.getHeaderField("Date");
+		if (hf != null) {
+			assertTrue("Wrong value returned for header field 'Date': " + hf,
+					Integer.parseInt(hf.substring(hf.length() - 17,
+							hf.length() - 13)) >= 1999);
+		}
+		hf = uc.getHeaderField("Expires");
+		if (hf != null) {
+			assertTrue(
+					"Wrong value returned for header field 'Expires': " + hf,
+					hf == null);
+		}
+		hf = uc.getHeaderField("SERVER");
+		if (hf != null) {
+			assertTrue("Wrong value returned for header field 'SERVER': " + hf
+					+ " (expected " + Support_Configuration.HomeAddressSoftware
+					+ ")", hf.equals(Support_Configuration.HomeAddressSoftware));
+		}
+		hf = uc.getHeaderField("Last-Modified");
+		if (hf != null) {
+			assertTrue(
+					"Wrong value returned for header field 'Last-Modified': "
+							+ hf,
+					hf
+							.equals(Support_Configuration.URLConnectionLastModifiedString));
+		}
+		hf = uc.getHeaderField("accept-ranges");
+		if (hf != null) {
+			assertTrue(
+					"Wrong value returned for header field 'accept-ranges': "
+							+ hf, hf.equals("bytes"));
+		}
+		hf = uc.getHeaderField("DoesNotExist");
+		if (hf != null) {
+			assertTrue("Wrong value returned for header field 'DoesNotExist': "
+					+ hf, hf == null);
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getHeaderFieldDate(java.lang.String, long)
+	 */
+	public void test_getHeaderFieldDateLjava_lang_StringJ() {
+
+		if (uc.getHeaderFieldDate("Date", 22L) == 22L) {
+			System.out
+					.println("WARNING: Server does not support 'Date', test_getHeaderFieldDateLjava_lang_StringJ not run");
+			return;
+		}
+		assertTrue("Wrong value returned: "
+				+ uc.getHeaderFieldDate("Date", 22L), uc.getHeaderFieldDate(
+				"Date", 22L) > 930000000000L);
+
+		try {
+			URL url = new URL(Support_Resources.getResourceURL("/RESOURCE.TXT"));
+			URLConnection connection = url.openConnection();
+			long time = connection.getHeaderFieldDate("Last-Modified", 0);
+			assertTrue("Wrong date: " + time,
+					time == Support_Configuration.URLConnectionDate);
+		} catch (MalformedURLException e) {
+			fail("MalformedURLException : " + e.getMessage());
+		} catch (IOException e) {
+			fail("IOException : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getHeaderFieldKey(int)
+	 */
+	public void test_getHeaderFieldKeyI() {
+		String hf;
+		boolean foundResponse = false;
+		for (int i = 0; i < 100; i++) {
+			hf = uc.getHeaderFieldKey(i);
+			if (hf != null && hf.toLowerCase().equals("content-type"))
+				foundResponse = true;
+		}
+		assertTrue(
+				"Could not find header field key containing \"content-type\"",
+				foundResponse);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getIfModifiedSince()
+	 */
+	public void test_getIfModifiedSince() {
+		uc.setIfModifiedSince(200);
+		assertTrue("Returned wrong ifModifiedSince value", uc
+				.getIfModifiedSince() == 200);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getInputStream()
+	 */
+	public void test_getInputStream() {
+		try {
+			InputStream is = uc.getInputStream();
+			byte[] ba = new byte[600];
+			is.read(ba, 0, 600);
+			is.close();
+			String s = new String(ba);
+			assertTrue("Incorrect input stream read", s.indexOf("20060107") > 0);
+
+			boolean exception = false;
+			try {
+				is.available();
+			} catch (IOException e) {
+				exception = true;
+			}
+			assertTrue("available() after close() should cause IOException",
+					exception);
+		} catch (Exception e) {
+			fail("Exception during test1 : " + e.getMessage());
+		}
+
+		try {
+			// open an non-existent file
+			URL url = new URL(Support_Resources.getResourceURL("/fred-zz6.txt"));
+			InputStream is = url.openStream();
+			assertTrue("available() less than 0", is.available() >= 0);
+			is.close();
+			fail("Error: data returned on opening a non-existent file.");
+		} catch (FileNotFoundException e) {
+		} catch (Exception e) {
+			fail("Exception during test2: " + e);
+		}
+
+		// create a serversocket
+		Support_HttpServerSocket serversocket = new Support_HttpServerSocket();
+
+		// create a client connector
+		Support_URLConnector client = new Support_URLConnector();
+
+		// pass both to the HttpTest
+		Support_HttpTests test = new Support_HttpTests(serversocket, client);
+
+		// run various tests common to both HttpConnections and
+		// HttpURLConnections
+		test.runTests(this);
+
+		// Authentication test is separate from other tests because it is only
+		// in HttpURLConnection and not supported in HttpConnection
+
+		serversocket = new Support_HttpServerSocket();
+		Support_HttpServer server = new Support_HttpServer(serversocket, this);
+		int p = Support_PortManager.getNextPort();
+		server.startServer(p);
+
+		// it is the Support_HttpServer's responsibility to close this
+		// serversocket
+		serversocket = null;
+
+		final String authTestUrl = "http://localhost:" + server.getPort()
+				+ Support_HttpServer.AUTHTEST;
+		InputStream is;
+
+		// Authentication test
+		try {
+			// set up a very simple authenticator
+			Authenticator.setDefault(new Authenticator() {
+				public PasswordAuthentication getPasswordAuthentication() {
+					return new PasswordAuthentication("test", "password"
+							.toCharArray());
+				}
+			});
+			try {
+				client.open(authTestUrl);
+				is = client.getInputStream();
+				int c = is.read();
+				while (c > 0)
+					c = is.read();
+				c = is.read();
+				is.close();
+			} catch (FileNotFoundException e) {
+				fail("Error performing authentication test: " + e);
+			}
+		} catch (Exception e) {
+			fail("Exception during test3: " + e);
+			e.printStackTrace();
+		}
+
+		final String invalidLocation = "/missingFile.htm";
+		final String redirectTestUrl = "http://localhost:" + server.getPort()
+				+ Support_HttpServer.REDIRECTTEST;
+
+		// test redirecting to a non-existent URL on the same host
+		try {
+			// append the response code for the server to return
+
+			client.open(redirectTestUrl + "/" + Support_HttpServer.MOVED_PERM
+					+ "-" + invalidLocation);
+			is = client.getInputStream();
+
+			int c = is.read();
+			while (c > 0)
+				c = is.read();
+			c = is.read();
+			is.close();
+			fail("Incorrect data returned on redirect to non-existent file.");
+		} catch (FileNotFoundException e) {
+		} catch (Exception e) {
+
+			e.printStackTrace();
+			fail("Exception during test4: " + e);
+		}
+		server.stopServer();
+
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getLastModified()
+	 */
+	public void test_getLastModified() {
+		if (uc.getLastModified() == 0) {
+			System.out
+					.println("WARNING: Server does not support 'Last-Modified', test_getLastModified() not run");
+			return;
+		}
+		assertTrue(
+				"Returned wrong getLastModified value.  Wanted: "
+						+ Support_Configuration.URLConnectionLastModified
+						+ " got: " + uc.getLastModified(),
+				uc.getLastModified() == Support_Configuration.URLConnectionLastModified);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getOutputStream()
+	 */
+	public void test_getOutputStream() {
+		boolean exception = false;
+		URL test;
+		java.net.URLConnection conn2 = null;
+		try {
+			test = new URL("http://" + Support_Configuration.HomeAddress
+					+ "/cgi-bin/test.pl");
+			conn2 = (java.net.URLConnection) test.openConnection();
+		} catch (IOException e) {
+			fail("Unexpected I/O exception: " + e);
+		}
+
+		try {
+			conn2.getOutputStream();
+		} catch (java.net.ProtocolException e) {
+			// correct
+			exception = true;
+		} catch (IOException e) {
+			fail("Wrong kind of exception thrown : " + e);
+		}
+		assertTrue("Failed to throw ProtocolException", exception);
+
+		try {
+			conn2.setDoOutput(true);
+			conn2.getOutputStream();
+			conn2.connect();
+			conn2.getOutputStream();
+		} catch (IOException e) {
+			fail("Unexpected IOException : " + e.getMessage());
+		}
+
+		exception = false;
+		try {
+			conn2.getInputStream();
+			conn2.getOutputStream();
+		} catch (ProtocolException e) {
+			exception = true;
+		} catch (IOException e) {
+			e.printStackTrace();
+			fail("Wrong exception thrown2: " + e);
+		}
+		assertTrue("Failed to throw ProtocolException2", exception);
+
+		try {
+			URL u = new URL("http://" + Support_Configuration.HomeAddress
+					+ "/cgi-bin/test.pl");
+			java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
+					.openConnection();
+			conn.setDoOutput(true);
+			conn.setRequestMethod("POST");
+			OutputStream out = conn.getOutputStream();
+			String posted = "this is a test";
+			out.write(posted.getBytes());
+			out.close();
+			conn.getResponseCode();
+			InputStream is = conn.getInputStream();
+			String response = "";
+			byte[] b = new byte[1024];
+			int count = 0;
+			while ((count = is.read(b)) > 0)
+				response += new String(b, 0, count);
+			assertTrue("Response to POST method invalid 1", response
+					.equals(posted));
+		} catch (Exception e) {
+			fail("Unexpected exception 1 : " + e.getMessage());
+		}
+
+		try {
+			String posted = "just a test";
+			URL u = new URL("http://" + Support_Configuration.HomeAddress
+					+ "/cgi-bin/test.pl");
+			java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
+					.openConnection();
+			conn.setDoOutput(true);
+			conn.setRequestMethod("POST");
+			conn.setRequestProperty("Content-length", String.valueOf(posted
+					.length()));
+			OutputStream out = conn.getOutputStream();
+			out.write(posted.getBytes());
+			out.close();
+			conn.getResponseCode();
+			InputStream is = conn.getInputStream();
+			String response = "";
+			byte[] b = new byte[1024];
+			int count = 0;
+			while ((count = is.read(b)) > 0)
+				response += new String(b, 0, count);
+			assertTrue("Response to POST method invalid 2", response
+					.equals(posted));
+		} catch (Exception e) {
+			fail("Unexpected exception 2 : " + e.getMessage());
+		}
+
+		try {
+			String posted = "just another test";
+			URL u = new URL("http://" + Support_Configuration.HomeAddress
+					+ "/cgi-bin/test.pl");
+			java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
+					.openConnection();
+			conn.setDoOutput(true);
+			conn.setRequestMethod("POST");
+			conn.setRequestProperty("Content-length", String.valueOf(posted
+					.length()));
+			OutputStream out = conn.getOutputStream();
+			out.write(posted.getBytes());
+			// out.close();
+			conn.getResponseCode();
+			InputStream is = conn.getInputStream();
+			String response = "";
+			byte[] b = new byte[1024];
+			int count = 0;
+			while ((count = is.read(b)) > 0)
+				response += new String(b, 0, count);
+			assertTrue("Response to POST method invalid 3", response
+					.equals(posted));
+		} catch (Exception e) {
+			fail("Unexpected exception 3 : " + e.getMessage());
+		}
+
+		try {
+			URL u = new URL("http://" + Support_Configuration.HomeAddress
+					+ "/cgi-bin/test.pl");
+			java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
+					.openConnection();
+			conn.setDoOutput(true);
+			conn.setRequestMethod("POST");
+			int result = conn.getResponseCode();
+			assertTrue("Unexpected response code: " + result, result == 200);
+		} catch (Exception e) {
+			fail("Unexpected exception 4 : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getPermission()
+	 */
+	public void test_getPermission() {
+		try {
+			java.security.Permission p = uc.getPermission();
+			assertTrue("Permission of wrong type: " + p.toString(),
+					p instanceof java.net.SocketPermission);
+			assertTrue("Permission has wrong name: " + p.getName(), p.getName()
+					.indexOf(Support_Configuration.HomeAddress + ":80") >= 0);
+
+			URL fileUrl = new URL("file:myfile");
+			Permission perm = new FilePermission("myfile", "read");
+			Permission result = fileUrl.openConnection().getPermission();
+			assertTrue("Wrong file: permission 1:" + perm + " , " + result,
+					result.equals(perm));
+
+			fileUrl = new URL("file:/myfile/");
+			perm = new FilePermission("/myfile", "read");
+			result = fileUrl.openConnection().getPermission();
+			assertTrue("Wrong file: permission 2:" + perm + " , " + result,
+					result.equals(perm));
+
+			fileUrl = new URL("file://host/volume/file");
+			perm = new FilePermission("//host/volume/file", "read");
+			result = fileUrl.openConnection().getPermission();
+			assertTrue("Wrong file: permission 3:" + perm + " , " + result,
+					result.equals(perm));
+
+			URL httpUrl = new URL("http://home/myfile/");
+			assertTrue("Wrong http: permission", httpUrl.openConnection()
+					.getPermission().equals(
+							new SocketPermission("home:80", "connect")));
+			httpUrl = new URL("http://home2:8080/myfile/");
+			assertTrue("Wrong http: permission", httpUrl.openConnection()
+					.getPermission().equals(
+							new SocketPermission("home2:8080", "connect")));
+			URL ftpUrl = new URL("ftp://home/myfile/");
+			assertTrue("Wrong ftp: permission", ftpUrl.openConnection()
+					.getPermission().equals(
+							new SocketPermission("home:21", "connect")));
+			ftpUrl = new URL("ftp://home2:22/myfile/");
+			assertTrue("Wrong ftp: permission", ftpUrl.openConnection()
+					.getPermission().equals(
+							new SocketPermission("home2:22", "connect")));
+
+			URL jarUrl = new URL("jar:file:myfile!/");
+			perm = new FilePermission("myfile", "read");
+			result = jarUrl.openConnection().getPermission();
+			assertTrue("Wrong jar: permission:" + perm + " , " + result, result
+					.equals(new FilePermission("myfile", "read")));
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getRequestProperty(java.lang.String)
+	 */
+	public void test_getRequestPropertyLjava_lang_String() {
+		uc.setRequestProperty("Yo", "yo");
+		assertTrue("Wrong property returned: " + uc.getRequestProperty("Yo"),
+				uc.getRequestProperty("Yo").equals("yo"));
+		assertTrue("Wrong property returned: " + uc.getRequestProperty("No"),
+				uc.getRequestProperty("No") == null);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getURL()
+	 */
+	public void test_getURL() {
+		assertTrue("Incorrect URL returned", uc.getURL().equals(url));
+	}
+
+	/**
+	 * @tests java.net.URLConnection#getUseCaches()
+	 */
+	public void test_getUseCaches() {
+		uc.setUseCaches(false);
+		assertTrue("getUseCaches should have returned false", !uc
+				.getUseCaches());
+		uc.setUseCaches(true);
+		assertTrue("getUseCaches should have returned true", uc.getUseCaches());
+	}
+
+	/**
+	 * @tests java.net.URLConnection#guessContentTypeFromStream(java.io.InputStream)
+	 */
+	public void test_guessContentTypeFromStreamLjava_io_InputStream() {
+		try {
+			InputStream in = uc.getInputStream();
+			byte[] bytes = new byte[in.available()];
+			in.read(bytes, 0, bytes.length);
+			in.close();
+			assertTrue("Should have returned text/html",
+					URLConnection.guessContentTypeFromStream(
+							new ByteArrayInputStream(bytes))
+							.equals("text/html"));
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setAllowUserInteraction(boolean)
+	 */
+	public void test_setAllowUserInteractionZ() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setDefaultAllowUserInteraction(boolean)
+	 */
+	public void test_setDefaultAllowUserInteractionZ() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setDefaultRequestProperty(java.lang.String,
+	 *        java.lang.String)
+	 */
+	public void test_setDefaultRequestPropertyLjava_lang_StringLjava_lang_String() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setDefaultUseCaches(boolean)
+	 */
+	public void test_setDefaultUseCachesZ() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setDoInput(boolean)
+	 */
+	public void test_setDoInputZ() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setDoOutput(boolean)
+	 */
+	public void test_setDoOutputZ() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setFileNameMap(java.net.FileNameMap)
+	 */
+	public void test_setFileNameMapLjava_net_FileNameMap() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setIfModifiedSince(long)
+	 */
+	public void test_setIfModifiedSinceJ() {
+		try {
+			URL url = new URL("http://localhost:8080/");
+			URLConnection connection = url.openConnection();
+			Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
+			cal.clear();
+			cal.set(2000, Calendar.MARCH, 5);
+			connection.setIfModifiedSince(cal.getTime().getTime());
+			assertTrue("Wrong date set", connection.getRequestProperty(
+					"If-Modified-Since")
+					.equals("Sun, 05 Mar 2000 00:00:00 GMT"));
+		} catch (MalformedURLException e) {
+			fail("MalformedURLException : " + e.getMessage());
+		} catch (IOException e) {
+			fail("IOException : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setRequestProperty(java.lang.String,
+	 *        java.lang.String)
+	 */
+	public void test_setRequestPropertyLjava_lang_StringLjava_lang_String() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#setUseCaches(boolean)
+	 */
+	public void test_setUseCachesZ() {
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URLConnection#toString()
+	 */
+	public void test_toString() {
+		assertTrue("Wrong toString: " + uc.toString(), uc.toString().indexOf(
+				"URLConnectionTest/Harmony.html") > 0);
+	}
+
+	protected void setUp() {
+		try {
+			url = new URL(Support_Resources
+					.getResourceURL("/URLConnectionTest/Harmony.html"));
+			uc = url.openConnection();
+		} catch (Exception e) {
+			fail("Exception during setup : " + e.getMessage());
+		}
+	}
+
+	protected void tearDown() {
+		((HttpURLConnection) uc).disconnect();
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,71 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.net.URLDecoder;
+import java.net.URLEncoder;
+
+import tests.support.Support_Configuration;
+
+public class URLDecoderTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.net.URLDecoder#URLDecoder()
+	 */
+	public void test_Constructor() {
+		try {
+			URLDecoder ud = new URLDecoder();
+			assertTrue("Constructor failed.", ud != null);
+		} catch (Exception e) {
+			fail("Constructor failed : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URLDecoder#decode(java.lang.String)
+	 */
+	public void test_decodeLjava_lang_String() {
+		// Test for method java.lang.String
+		// java.net.URLDecoder.decode(java.lang.String)
+		final String URL = "http://" + Support_Configuration.HomeAddress;
+		final String URL2 = "telnet://justWantToHaveFun.com:400";
+		final String URL3 = "file://myServer.org/a file with spaces.jpg";
+		try {
+			assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
+					URLEncoder.encode(URL)).equals(URL));
+			assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
+					URLEncoder.encode(URL2)).equals(URL2));
+			assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
+					URLEncoder.encode(URL3)).equals(URL3));
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,59 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.net.URLDecoder;
+import java.net.URLEncoder;
+
+import tests.support.Support_Configuration;
+
+public class URLEncoderTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.net.URLEncoder#encode(java.lang.String)
+	 */
+	public void test_encodeLjava_lang_String() {
+		// Test for method java.lang.String
+		// java.net.URLEncoder.encode(java.lang.String)
+		final String URL = "http://" + Support_Configuration.HomeAddress;
+		final String URL2 = "telnet://justWantToHaveFun.com:400";
+		final String URL3 = "file://myServer.org/a file with spaces.jpg";
+		try {
+			assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
+					URLEncoder.encode(URL)).equals(URL));
+			assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
+					URLEncoder.encode(URL2)).equals(URL2));
+			assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
+					URLEncoder.encode(URL3)).equals(URL3));
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}