Remove Jetty dependency from 3 of 4 tests.
I still need to come up with a strategy for URLClassLoaderTest.
Change-Id: Ic955fbf89f1fef11881c84e4fdc2e453a082cf67
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
deleted file mode 100644
index 82221b3..0000000
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
+++ /dev/null
@@ -1,855 +0,0 @@
-/*
- * 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.harmony.luni.tests.java.net;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.CacheRequest;
-import java.net.CacheResponse;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.ProtocolException;
-import java.net.ResponseCache;
-import java.net.SocketPermission;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.Permission;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import tests.support.Support_Configuration;
-import tests.support.Support_Jetty;
-
-public class HttpURLConnectionTest extends junit.framework.TestCase {
-
- URL url;
-
- HttpURLConnection uc;
-
- private boolean isGetCalled;
-
- private boolean isPutCalled;
-
- private boolean isCacheWriteCalled;
-
- private boolean isAbortCalled;
-
- 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()
- */
- public void test_getResponseCode() {
- try {
- assertEquals("Wrong response", 200, uc.getResponseCode());
- } catch (IOException e) {
- fail("Unexpected exception : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.net.HttpURLConnection#getResponseMessage()
- */
- public void test_getResponseMessage() {
- try {
- assertTrue("Wrong response: " + uc.getResponseMessage(), uc
- .getResponseMessage().equals("OK"));
- } catch (IOException e) {
- fail("Unexpected exception : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.net.HttpURLConnection#getHeaderFields()
- */
- public void test_getHeaderFields() {
- try {
- uc.getInputStream();
- } catch (IOException e) {
- fail();
- }
- Map headers = uc.getHeaderFields();
- List list = (List) headers.get("Content-Length");
- if (list == null) {
- list = (List) headers.get("content-length");
- }
- assertNotNull(list);
-
- // content-length should always appear
- String contentLength = (String) list.get(0);
- assertNotNull(contentLength);
-
- // there should be at least 2 headers
- assertTrue(headers.size() > 1);
-
- try {
- // the map should be unmodifiable
- headers.put("hi", "bye");
- fail();
- } catch (UnsupportedOperationException e) {
- }
-
- try {
- // the list should be unmodifiable
- list.set(0, "whatever");
- fail();
- } catch (UnsupportedOperationException e) {
- }
- }
-
- /**
- * @tests java.net.HttpURLConnection#getRequestProperties()
- */
- public void test_getRequestProperties() {
- uc.setRequestProperty("whatever", "you like");
- Map headers = uc.getRequestProperties();
-
- List newHeader = (List) headers.get("whatever");
- assertNotNull(newHeader);
-
- assertEquals("you like", newHeader.get(0));
-
- try {
- // the map should be unmodifiable
- headers.put("hi", "bye");
- fail();
- } catch (UnsupportedOperationException e) {
- }
- }
-
- /**
- * @tests java.net.HttpURLConnection#getRequestProperty(String)
- */
- public void test_getRequestPropertyLjava_lang_String_BeforeConnected()
- throws MalformedURLException, IOException {
- uc.setRequestProperty("whatever", "you like"); //$NON-NLS-1$//$NON-NLS-2$
- String res = uc.getRequestProperty("whatever"); //$NON-NLS-1$
- assertEquals("you like", res); //$NON-NLS-1$
-
- uc.setRequestProperty("", "you like"); //$NON-NLS-1$//$NON-NLS-2$
- res = uc.getRequestProperty(""); //$NON-NLS-1$
- assertEquals("you like", res); //$NON-NLS-1$
-
- uc.setRequestProperty("", null); //$NON-NLS-1$
- res = uc.getRequestProperty(""); //$NON-NLS-1$
- assertEquals(null, res);
- try {
- uc.setRequestProperty(null, "you like"); //$NON-NLS-1$
- fail("Should throw NullPointerException"); //$NON-NLS-1$
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.net.HttpURLConnection#getRequestProperty(String)
- */
- public void test_getRequestPropertyLjava_lang_String_AfterConnected()
- throws IOException {
- uc.connect();
- try {
- uc.setRequestProperty("whatever", "you like"); //$NON-NLS-1$//$NON-NLS-2$
- fail("Should throw IllegalStateException"); //$NON-NLS-1$
- } catch (IllegalStateException e) {
- // expected
- }
- try {
- uc.setRequestProperty(null, "you like"); //$NON-NLS-1$
- fail("Should throw IllegalStateException"); //$NON-NLS-1$
- } catch (IllegalStateException e) {
- // expected
- }
- String res = uc.getRequestProperty("whatever"); //$NON-NLS-1$
- assertEquals(null, res);
- res = uc.getRequestProperty(null);
- assertEquals(null, res);
- try {
- uc.getRequestProperties();
- fail("Should throw IllegalStateException"); //$NON-NLS-1$
- } catch (IllegalStateException e) {
- // expected
- }
- }
-
- /**
- * @tests java.net.HttpURLConnection#setFixedLengthStreamingMode_I()
- */
- public void test_setFixedLengthStreamingModeI() throws Exception {
- try {
- uc.setFixedLengthStreamingMode(-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // correct
- }
- uc.setFixedLengthStreamingMode(0);
- uc.setFixedLengthStreamingMode(1);
- try {
- uc.setChunkedStreamingMode(1);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // correct
- }
- uc.connect();
- try {
- uc.setFixedLengthStreamingMode(-1);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // correct
- }
- try {
- uc.setChunkedStreamingMode(-1);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // correct
- }
- MockHttpConnection mock = new MockHttpConnection(url);
- assertEquals(-1, mock.getFixedLength());
- mock.setFixedLengthStreamingMode(0);
- assertEquals(0, mock.getFixedLength());
- mock.setFixedLengthStreamingMode(1);
- assertEquals(1, mock.getFixedLength());
- mock.setFixedLengthStreamingMode(0);
- assertEquals(0, mock.getFixedLength());
- }
-
- /**
- * @tests java.net.HttpURLConnection#setChunkedStreamingMode_I()
- */
- public void test_setChunkedStreamingModeI() throws Exception {
- uc.setChunkedStreamingMode(0);
- uc.setChunkedStreamingMode(-1);
- uc.setChunkedStreamingMode(-2);
-
- try {
- uc.setFixedLengthStreamingMode(-1);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // correct
- }
- try {
- uc.setFixedLengthStreamingMode(1);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // correct
- }
- uc.connect();
- try {
- uc.setFixedLengthStreamingMode(-1);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // correct
- }
- try {
- uc.setChunkedStreamingMode(1);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // correct
- }
- MockHttpConnection mock = new MockHttpConnection(url);
- assertEquals(-1, mock.getChunkLength());
- mock.setChunkedStreamingMode(-1);
- int defaultChunk = mock.getChunkLength();
- assertTrue(defaultChunk > 0);
- mock.setChunkedStreamingMode(0);
- assertEquals(mock.getChunkLength(), defaultChunk);
- mock.setChunkedStreamingMode(1);
- assertEquals(1, mock.getChunkLength());
- }
-
- /**
- * @tests java.net.HttpURLConnection#setFixedLengthStreamingMode_I()
- */
- public void test_setFixedLengthStreamingModeI_effect() throws Exception {
- String posted = "just a test";
- java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
- .openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setFixedLengthStreamingMode(posted.length() - 1);
- assertNull(conn.getRequestProperty("Content-length"));
- conn.setRequestProperty("Content-length", String.valueOf(posted
- .length()));
- assertEquals(String.valueOf(posted.length()), conn
- .getRequestProperty("Content-length"));
- OutputStream out = conn.getOutputStream();
- try {
- out.write(posted.getBytes());
- fail("should throw IOException");
- } catch (IOException e) {
- // correct, too many bytes written
- }
- try {
- out.close();
- fail("should throw IOException");
- } catch (IOException e) {
- // correct, too many bytes written
- }
- }
-
- /**
- * When an OutputStream of HtttpURLConnection is closed with below
- * situation: fixed-length mod is disable and the content-length of the
- * HtttpURLConnection is larger than 0, it should not throw IOExeption which
- * indicates there are more bytes need be written into the underlying
- * Socket.
- *
- * @throws IOException
- */
- public void test_closeWithFixedLengthDisableMod() throws IOException {
- String posted = "just a test";
- java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
- .openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-Length", "" + (888));
-
- OutputStream out = conn.getOutputStream();
- out.write(posted.getBytes());
- //should not throw IOExeption
- out.close();
- }
-
- /**
- * When write bytes to HttpOutputSteam, only if fixed mode is true and the write number of bytes is
- * greater than the limit of HttpOutputStream, the write method will throw IOException
- * @throws IOException
- */
- public void test_writeWithFixedLengthDisableMode() throws IOException {
- String bigString = "big String:/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java b/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java";
-
- java.net.HttpURLConnection httpURLConnection = (HttpURLConnection) url
- .openConnection();
-
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setRequestProperty("Content-Length", "" + (168));
-
- OutputStream out = httpURLConnection.getOutputStream();
- //should not throw IOExeption
- out.write(bigString.getBytes());
- }
-
- /**
- * @tests java.net.HttpURLConnection#setChunkedStreamingMode_I()
- */
- public void test_setChunkedStreamingModeI_effect() throws Exception {
- String posted = "just a test";
- // for test, use half length of the string
- int chunkSize = posted.length() / 2;
- java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
- .openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setChunkedStreamingMode(chunkSize);
- assertNull(conn.getRequestProperty("Transfer-Encoding"));
- // does not take effect
- conn.setRequestProperty("Content-length", String.valueOf(posted
- .length() - 1));
- assertEquals(conn.getRequestProperty("Content-length"), String
- .valueOf(posted.length() - 1));
- OutputStream out = conn.getOutputStream();
- // no error occurs
- out.write(posted.getBytes());
- out.close();
- // no assert here, pass if no exception thrown
- assertTrue(conn.getResponseCode() > 0);
- }
-
- public void test_getOutputStream_afterConnection() throws Exception {
- uc.setDoOutput(true);
- uc.connect();
- assertNotNull(uc.getOutputStream());
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using GetInputStream() and Connect()
- */
- public void test_UseCache_HttpURLConnection_Connect_GetInputStream()
- throws Exception {
- // set cache before URLConnection created, or it does not take effect
- ResponseCache rc = new MockNonCachedResponseCache();
- ResponseCache.setDefault(rc);
- uc = (HttpURLConnection) url.openConnection();
- assertFalse(isGetCalled);
- uc.setUseCaches(true);
- uc.setDoOutput(true);
- uc.connect();
- assertTrue(isGetCalled);
- assertFalse(isPutCalled);
- InputStream is = uc.getInputStream();
- assertTrue(isPutCalled);
- is.close();
- ((HttpURLConnection) uc).disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using GetOutputStream() and Connect()
- */
- public void test_UseCache_HttpURLConnection_Connect_GetOutputStream()
- throws Exception {
- // set cache before URLConnection created, or it does not take effect
- ResponseCache rc = new MockNonCachedResponseCache();
- ResponseCache.setDefault(rc);
- uc.setUseCaches(true);
- URLConnection uc = url.openConnection();
- uc.setDoOutput(true);
- assertFalse(isGetCalled);
- uc.connect();
- assertTrue(isGetCalled);
- assertFalse(isPutCalled);
- OutputStream os = uc.getOutputStream();
- assertFalse(isPutCalled);
- os.close();
- ((HttpURLConnection) uc).disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using GetOutputStream()
- */
- public void test_UseCache_HttpURLConnection_GetOutputStream()
- throws Exception {
- // set cache before URLConnection created, or it does not take effect
- ResponseCache rc = new MockNonCachedResponseCache();
- ResponseCache.setDefault(rc);
- uc = (HttpURLConnection) url.openConnection();
- assertFalse(isGetCalled);
- uc.setDoOutput(true);
- uc.setUseCaches(true);
- OutputStream os = uc.getOutputStream();
- assertTrue(isGetCalled);
- assertFalse(isPutCalled);
- os.write(1);
- os.flush();
- os.close();
- ((HttpURLConnection) uc).getResponseCode();
- assertTrue(isGetCalled);
- assertTrue(isPutCalled);
- isGetCalled = false;
- isPutCalled = false;
- InputStream is = uc.getInputStream();
- assertFalse(isGetCalled);
- assertFalse(isPutCalled);
- is.close();
- ((HttpURLConnection) uc).disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using GetInputStream()
- */
- public void test_UseCache_HttpURLConnection_GetInputStream()
- throws Exception {
- // set cache before URLConnection created, or it does not take effect
- ResponseCache rc = new MockNonCachedResponseCache();
- ResponseCache.setDefault(rc);
- URLConnection uc = url.openConnection();
- assertFalse(isGetCalled);
- uc.setDoOutput(true);
- uc.setUseCaches(true);
- InputStream is = uc.getInputStream();
- assertTrue(isGetCalled);
- assertTrue(isPutCalled);
- ((HttpURLConnection) uc).getResponseCode();
- is.close();
- ((HttpURLConnection) uc).disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using a MockResponseCache returns cache of
- * null
- */
- public void test_UseCache_HttpURLConnection_NonCached() throws IOException {
- ResponseCache.setDefault(new MockNonCachedResponseCache());
- uc = (HttpURLConnection) url.openConnection();
-
- // default useCaches is true
- assertTrue(uc.getUseCaches());
-
- // make sure ResponseCache.get/put is called
- isGetCalled = false;
- isPutCalled = false;
- InputStream is = uc.getInputStream();
- assertFalse(is instanceof MockInputStream);
- assertTrue(isGetCalled);
- assertTrue(isPutCalled);
-
- // make sure protocol handler has tried to write to cache.
- isCacheWriteCalled = false;
- is.read();
- assertTrue(isCacheWriteCalled);
-
- // make sure protocol handler has tried to write to cache.
- isCacheWriteCalled = false;
- byte[] buf = new byte[1];
- is.read(buf);
- assertTrue(isCacheWriteCalled);
-
- // make sure protocol handler has tried to write to cache.
- isCacheWriteCalled = false;
- buf = new byte[1];
- is.read(buf, 0, 1);
- assertTrue(isCacheWriteCalled);
-
- // make sure protocol handler has tried to call abort.
- isAbortCalled = false;
- is.close();
- assertTrue(isAbortCalled);
- uc.disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using a MockResponseCache returns a mock
- * cache
- */
- public void test_UseCache_HttpURLConnection_Cached() throws IOException {
- ResponseCache.setDefault(new MockCachedResponseCache());
- URL u = new URL("http://" + Support_Configuration.InetTestAddress);
- HttpURLConnection uc = (HttpURLConnection) u.openConnection();
-
- // default useCaches is true
- assertTrue(uc.getUseCaches());
-
- // make sure ResponseCache.get/put is called
- isGetCalled = false;
- isPutCalled = false;
- InputStream is = uc.getInputStream();
- assertTrue(is instanceof MockInputStream);
- assertTrue(isGetCalled);
-
- // make sure protocol handler doesn't try to write to cache, since
- // it has been in cache already.
- isCacheWriteCalled = false;
- is.read();
- assertFalse(isCacheWriteCalled);
-
- // make sure protocol handler doesn't try to write to cache, since
- // it has been in cache already.
- isCacheWriteCalled = false;
- byte[] buf = new byte[1];
- is.read(buf);
- assertFalse(isCacheWriteCalled);
-
- // make sure protocol handler doesn't try to write to cache, since
- // it has been in cache already.
- isCacheWriteCalled = false;
- buf = new byte[1];
- is.read(buf, 0, 1);
- assertFalse(isCacheWriteCalled);
-
- // make sure abort is not called since no write is performed
- isAbortCalled = false;
- is.close();
- assertFalse(isAbortCalled);
- uc.disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using getHeaderFields()
- */
- public void test_UseCache_HttpURLConnection_getHeaderFields()
- throws IOException {
- ResponseCache.setDefault(new MockCachedResponseCache());
- URL u = new URL("http://" + Support_Configuration.InetTestAddress);
- HttpURLConnection uc = (HttpURLConnection) u.openConnection();
- Map<String, List<String>> headerMap = uc.getHeaderFields();
- assertTrue(isGetCalled);
- assertFalse(isPutCalled);
- assertEquals(mockHeaderMap, headerMap);
- assertEquals(uc.getInputStream(), mockIs);
-
- // REGRESSION for HARMONY-6542 item 1 in descriptions.txt attachement
- assertEquals("value1", uc.getHeaderField(0));
- assertEquals("value2", uc.getHeaderField(1));
- assertEquals("value1", uc.getHeaderField(2));
- assertEquals("value2", uc.getHeaderField(3));
- assertNull(uc.getHeaderField(4));
-
- uc.disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#setUseCaches() and its real implementation
- * in HttpURLConnection using GetOutputStream()
- */
- public void test_UseCache_HttpURLConnection_NoCached_GetOutputStream()
- throws Exception {
- ResponseCache.setDefault(new MockNonCachedResponseCache());
- uc = (HttpURLConnection) url.openConnection();
- uc.setChunkedStreamingMode(10);
- uc.setDoOutput(true);
- uc.getOutputStream();
- assertTrue(isGetCalled);
- assertFalse(isPutCalled);
- assertFalse(isAbortCalled);
- uc.disconnect();
- }
-
- /**
- * @tests java.net.URLConnection#getErrorStream()
- */
- public void test_getErrorStream() throws Exception {
- uc.setDoOutput(true);
- uc.connect();
- assertEquals(200, uc.getResponseCode());
- // no error stream
- assertNull(uc.getErrorStream());
- uc.disconnect();
- assertNull(uc.getErrorStream());
- }
-
- /**
- * @tests {@link java.net.HttpURLConnection#setFollowRedirects(boolean)}
- * @tests {@link java.net.HttpURLConnection#getFollowRedirects()}
- */
- public void test_followRedirects() {
- assertTrue("The default value of followRedirects is not true",
- HttpURLConnection.getFollowRedirects());
-
- HttpURLConnection.setFollowRedirects(false);
- assertFalse(HttpURLConnection.getFollowRedirects());
-
- HttpURLConnection.setFollowRedirects(true);
- assertTrue(HttpURLConnection.getFollowRedirects());
- }
-
- /**
- * @throws ProtocolException
- * @tests {@link java.net.HttpURLConnection#setRequestMethod(String)}
- * @tests {@link java.net.HttpURLConnection#getRequestMethod()}
- */
- public void test_requestMethod() throws MalformedURLException, ProtocolException{
- URL url = new URL("http://harmony.apache.org/");
-
- HttpURLConnection con = new MyHttpURLConnection(url);
- assertEquals("The default value of requestMethod is not \"GET\"", "GET",
- con.getRequestMethod());
-
- String[] methods = { "GET", "DELETE", "HEAD", "OPTIONS", "POST", "PUT",
- "TRACE" };
- // Nomal set. Should not throw ProtocolException
- for (String method : methods) {
- con.setRequestMethod(method);
- assertEquals("The value of requestMethod is not " + method, method,
- con.getRequestMethod());
- }
-
- try {
- con.setRequestMethod("Wrong method");
- fail("Should throw ProtocolException");
- } catch (ProtocolException e) {
- // Expected
- }
- }
-
- private static class MyHttpURLConnection extends HttpURLConnection {
-
- protected MyHttpURLConnection(URL url) {
- super(url);
- }
-
- @Override
- public void disconnect() {
- // do nothing
- }
-
- @Override
- public boolean usingProxy() {
- return false;
- }
-
- @Override
- public void connect() throws IOException {
- // do nothing
- }
- }
-
- /**
- * @tests java.net.URLConnection#getPermission()
- */
- public void test_Permission() throws Exception {
- uc.connect();
- Permission permission = uc.getPermission();
- assertNotNull(permission);
- permission.implies(new SocketPermission("localhost","connect"));
- }
-
- class MockNonCachedResponseCache extends ResponseCache {
-
- public CacheResponse get(URI arg0, String arg1, Map arg2)
- throws IOException {
- isGetCalled = true;
- return null;
- }
-
- public CacheRequest put(URI arg0, URLConnection arg1)
- throws IOException {
- isPutCalled = true;
- return new MockCacheRequest();
- }
- }
-
- class MockCachedResponseCache extends ResponseCache {
-
- public CacheResponse get(URI arg0, String arg1, Map arg2)
- throws IOException {
- if (null == arg0 || null == arg1 || null == arg2) {
- throw new NullPointerException();
- }
- isGetCalled = true;
- return new MockCacheResponse();
- }
-
- public CacheRequest put(URI arg0, URLConnection arg1)
- throws IOException {
- if (null == arg0 || null == arg1) {
- throw new NullPointerException();
- }
- isPutCalled = true;
- return new MockCacheRequest();
- }
- }
-
- class MockCacheRequest extends CacheRequest {
-
- public OutputStream getBody() throws IOException {
- isCacheWriteCalled = true;
- return new MockOutputStream();
- }
-
- public void abort() {
- isAbortCalled = true;
- }
-
- }
-
- class MockCacheResponse extends CacheResponse {
-
- public Map<String, List<String>> getHeaders() throws IOException {
- return mockHeaderMap;
- }
-
- public InputStream getBody() throws IOException {
- return mockIs;
- }
- }
-
- class MockInputStream extends InputStream {
-
- public int read() throws IOException {
- return 1;
- }
-
- public int read(byte[] arg0, int arg1, int arg2) throws IOException {
- return 1;
- }
-
- public int read(byte[] arg0) throws IOException {
- return 1;
- }
-
- }
-
- class MockOutputStream extends OutputStream {
-
- public void write(int b) throws IOException {
- isCacheWriteCalled = true;
- }
-
- public void write(byte[] b, int off, int len) throws IOException {
- isCacheWriteCalled = true;
- }
-
- public void write(byte[] b) throws IOException {
- isCacheWriteCalled = true;
- }
- }
-
- class MockHttpConnection extends HttpURLConnection {
-
- protected MockHttpConnection(URL url) {
- super(url);
- }
-
- public void disconnect() {
- // do nothing
- }
-
- public boolean usingProxy() {
- return false;
- }
-
- public void connect() throws IOException {
- // do nothing
- }
-
- public int getChunkLength() {
- return super.chunkLength;
- }
-
- public int getFixedLength() {
- return super.fixedContentLength;
- }
-
- }
-
- protected void setUp() {
- try {
- url = new URL("http://localhost:"+port+"/");
- uc = (HttpURLConnection) url.openConnection();
- } catch (Exception e) {
- fail("Exception during setup : " + e.getMessage());
- }
- mockHeaderMap = new Hashtable<String, List<String>>();
- List<String> valueList = new ArrayList<String>();
- valueList.add("value1");
- valueList.add("value2");
- mockHeaderMap.put("field1", valueList);
- mockHeaderMap.put("field2", valueList);
- isGetCalled = false;
- isPutCalled = false;
- isCacheWriteCalled = false;
- }
-
- protected void tearDown() {
- uc.disconnect();
- ResponseCache.setDefault(null);
- }
-}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
index b534221..64d314b 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
@@ -20,39 +20,26 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
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.net.URLStreamHandler;
import java.security.Permission;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
-import java.util.Collections;
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_Jetty;
-import tests.support.Support_PortManager;
-import tests.support.Support_URLConnector;
import tests.support.resource.Support_Resources;
public class URLConnectionTest extends junit.framework.TestCase {
@@ -90,8 +77,6 @@
}
}
- private static int port;
-
static String getContentType(String fileName) throws IOException {
String resourceName = "org/apache/harmony/luni/tests/" + fileName;
URL url = ClassLoader.getSystemClassLoader().getResource(resourceName);
@@ -100,13 +85,11 @@
}
URL url;
-
URLConnection uc;
protected void setUp() throws Exception {
- url = new URL("http://localhost:" + port + "/");
- uc = (HttpURLConnection) url.openConnection();
- port = Support_Jetty.startDefaultHttpServer();
+ url = new URL("http://localhost/");
+ uc = url.openConnection();
}
protected void tearDown() {
@@ -167,105 +150,6 @@
}
/**
- * Regression test for HARMONY-6452
- */
- public void test_RequestProperty_case_insensitivity()
- throws MalformedURLException, IOException {
-
- URLConnection u =
- (URLConnection)(new URL("http://example.org/").openConnection());
- u.setRequestProperty("KEY", "upper");
- u.setRequestProperty("key", "lower");
- assertEquals("set for \"KEY\" is overwritten by set for \"key\"",
- "lower", u.getRequestProperty("KEY"));
- assertEquals("value can be retrieved by either key case",
- "lower", u.getRequestProperty("key"));
- assertEquals("value can be retrieved by arbitrary key case",
- "lower", u.getRequestProperty("kEy"));
-
- Map<String, List<String>> props = u.getRequestProperties();
- List<String> values = props.get("KEY");
- assertNotNull("first key does have an entry", values);
- assertNull("second key does not have an entry", props.get("key"));
-
- assertEquals("returned value list is correct size", 1, values.size());
- assertTrue("returned value list contains expected value",
- values.contains("lower"));
-
-
- // repeat the above with the case of keys reversed to confirm
- // that first key is significant one
- u = (URLConnection)(new URL("http://example.org/").openConnection());
- u.setRequestProperty("key", "lower");
- u.setRequestProperty("KEY", "upper");
- assertEquals("set for \"key\" is overwritten by set for \"KEY\"",
- "upper", u.getRequestProperty("KEY"));
- assertEquals("value can be retrieved by either key case",
- "upper", u.getRequestProperty("key"));
- assertEquals("value can be retrieved by arbitrary key case",
- "upper", u.getRequestProperty("kEy"));
-
- props = u.getRequestProperties();
- values = props.get("key");
- assertNotNull("first key does have an entry", values);
- assertNull("second key does not have an entry", props.get("KEY"));
-
- assertEquals("returned value list is correct size", 1, values.size());
- assertTrue("returned value list contains expected value",
- values.contains("upper"));
-
-
- // repeat the first test with set and add methods
- u = (URLConnection)(new URL("http://example.org/").openConnection());
- u.setRequestProperty("KEY", "value1");
- u.addRequestProperty("key", "value2");
- assertEquals("value for \"KEY\" is the last one added",
- "value2", u.getRequestProperty("KEY"));
- assertEquals("value can be retrieved by either key case",
- "value2", u.getRequestProperty("key"));
- assertEquals("value can be retrieved by arbitrary key case",
- "value2", u.getRequestProperty("kEy"));
-
- props = u.getRequestProperties();
- values = props.get("KEY");
- assertNotNull("first key does have an entry", values);
- assertNull("second key does not have an entry", props.get("key"));
-
- assertEquals("returned value list is correct size", 2, values.size());
- assertTrue("returned value list contains first value",
- values.contains("value1"));
- assertTrue("returned value list contains second value",
- values.contains("value2"));
-
-
- // repeat the previous test with only add methods
- u = (URLConnection)(new URL("http://example.org/").openConnection());
- u.addRequestProperty("KEY", "value1");
- u.addRequestProperty("key", "value2");
- u.addRequestProperty("Key", "value3");
- assertEquals("value for \"KEY\" is the last one added",
- "value3", u.getRequestProperty("KEY"));
- assertEquals("value can be retrieved by another key case",
- "value3", u.getRequestProperty("key"));
- assertEquals("value can be retrieved by arbitrary key case",
- "value3", u.getRequestProperty("kEy"));
-
- props = u.getRequestProperties();
- values = props.get("KEY");
- assertNotNull("first key does have an entry", values);
- assertNull("second key does not have an entry", props.get("key"));
- assertNull("third key does not have an entry", props.get("Key"));
-
- assertEquals("returned value list is correct size", 3, values.size());
- assertTrue("returned value list contains first value",
- values.contains("value1"));
- assertTrue("returned value list contains second value",
- values.contains("value2"));
- assertTrue("returned value list contains second value",
- values.contains("value3"));
- }
-
- /**
* @tests java.net.URLConnection#addRequestProperty(java.lang.String,java.lang.String)
*/
public void test_addRequestPropertyLjava_lang_StringLjava_lang_String()
@@ -323,46 +207,6 @@
}
/**
- * @tests java.net.URLConnection#getContent()
- */
- public void test_getContent() throws Exception {
- byte[] ba = new byte[600];
- ((InputStream) uc.getContent()).read(ba, 0, 600);
- String s = new String(ba, 0, ba.length, "UTF-8");
- 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()
*/
public void test_getContentEncoding() {
@@ -372,29 +216,6 @@
}
/**
- * @tests java.net.URLConnection#getContentLength()
- */
- public void test_getContentLength() throws IOException {
- assertEquals("getContentLength failed: " + uc.getContentLength(), 25,
- uc.getContentLength());
- }
-
- /**
- * @tests java.net.URLConnection#getContentType()
- */
- public void test_getContentType() throws IOException {
- // should not be known for a file
- assertTrue("getContentType failed: " + uc.getContentType(), uc
- .getContentType().contains("text/html"));
-
- 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();
- assertEquals("type not GIF", "image/gif", conn.getContentType());
- }
-
- /**
* @tests java.net.URLConnection#getContentType()
*/
public void test_getContentType_regression() throws IOException {
@@ -566,52 +387,6 @@
}
/**
- * @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#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;
- break;
- }
- }
- assertTrue(
- "Could not find header field key containing \"content-type\"",
- foundResponse);
- }
-
- /**
* @tests java.net.URLConnection#getHeaderField(java.lang.String)
*/
public void test_getHeaderFieldLjava_lang_String() {
@@ -678,47 +453,6 @@
}
/**
- * @tests java.net.URLConnection#getHeaderFields()
- */
- public void test_getHeaderFields() throws IOException {
- try {
- uc.getInputStream();
- } catch (IOException e) {
- fail();
- }
-
- Map<String, List<String>> headers = uc.getHeaderFields();
- assertNotNull(headers);
-
- // content-length should always appear
- List<String> list = headers.get("Content-Length");
- if (list == null) {
- 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);
- 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);
- assertEquals(0, headers.size());
- try {
- // the map should be unmodifiable
- headers.put("hi", Arrays.asList(new String[] { "bye" }));
- fail("The map should be unmodifiable");
- } catch (UnsupportedOperationException e) {
- // Expected
- }
- }
-
- /**
* @tests java.net.URLConnection#getIfModifiedSince()
*/
public void test_getIfModifiedSince() {
@@ -728,98 +462,6 @@
}
/**
- * @tests java.net.URLConnection#getInputStream()
- */
- public void test_getInputStream() throws IOException {
- InputStream is = uc.getInputStream();
- byte[] ba = new byte[600];
- is.read(ba, 0, 600);
- is.close();
- String s = new String(ba, 0, ba.length, "UTF-8");
- assertTrue("Incorrect input stream read",
- s.indexOf("Hello OneHandler") > 0);
-
- // open an non-existent file
- URL url = new URL("http://localhost:" + port + "/fred-zz6.txt");
- is = url.openStream();
- assertTrue("available() less than 0", is.available() >= 0);
- is.close();
-
- // create a server socket
- 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;
-
- // Authentication test
- // 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);
- }
-
- 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) {
- }
- server.stopServer();
-
- }
-
- /**
* @tests java.net.URLConnection#getLastModified()
*/
public void test_getLastModified() {
@@ -836,112 +478,6 @@
}
/**
- * @tests java.net.URLConnection#getOutputStream()
- */
- public void test_getOutputStream() throws Exception {
- int port = Support_Jetty.startDefaultServlet();
- try {
- boolean exception = false;
- URL test;
- java.net.URLConnection conn2 = null;
-
- test = new URL("http://localhost:" + port + "/");
- conn2 = (java.net.URLConnection) test.openConnection();
-
- try {
- conn2.getOutputStream();
- fail("should throw ProtocolException");
- } catch (java.net.ProtocolException e) {
- // correct
- }
-
- conn2.setDoOutput(true);
- conn2.getOutputStream();
- conn2.connect();
- conn2.getOutputStream();
-
- try {
- conn2.getInputStream();
- conn2.getOutputStream();
- fail("should throw ProtocolException");
- } catch (ProtocolException e) {
- // expected.
- }
-
- URL u = new URL("http://localhost:" + port + "/");
- 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);
- }
- assertEquals("Response to POST method invalid 1", posted, response);
-
- posted = "just a test";
- u = new URL("http://localhost:" + port + "/");
- conn = (java.net.HttpURLConnection) u.openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-length", String.valueOf(posted
- .length()));
- out = conn.getOutputStream();
- out.write(posted.getBytes());
- out.close();
- conn.getResponseCode();
- is = conn.getInputStream();
- response = "";
- b = new byte[1024];
- count = 0;
- while ((count = is.read(b)) > 0) {
- response += new String(b, 0, count);
- }
- assertTrue("Response to POST method invalid 2", response
- .equals(posted));
-
- posted = "just another test";
- u = new URL("http://localhost:" + port + "/");
- conn = (java.net.HttpURLConnection) u.openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-length", String.valueOf(posted
- .length()));
- out = conn.getOutputStream();
- out.write(posted.getBytes());
- // out.close();
- conn.getResponseCode();
- is = conn.getInputStream();
- response = "";
- b = new byte[1024];
- count = 0;
- while ((count = is.read(b)) > 0) {
- response += new String(b, 0, count);
- }
- assertTrue("Response to POST method invalid 3", response
- .equals(posted));
-
- u = new URL("http://localhost:" + port + "/");
- conn = (java.net.HttpURLConnection) u.openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- int result = conn.getResponseCode();
- assertTrue("Unexpected response code: " + result, result == 200);
-
- } finally {
- Support_Jetty.startDefaultServlet();
- }
- }
-
- /**
* @tests java.net.URLConnection#getPermission()
*/
public void test_getPermission() throws Exception {
@@ -949,7 +485,7 @@
assertTrue("Permission of wrong type: " + p.toString(),
p instanceof java.net.SocketPermission);
assertTrue("Permission has wrong name: " + p.getName(), p.getName()
- .contains("localhost:" + port));
+ .contains("localhost:80"));
URL fileUrl = new URL("file:myfile");
Permission perm = new FilePermission("myfile", "read");
@@ -1199,44 +735,6 @@
/**
* @throws IOException
- * @throws MalformedURLException
- * @tests java.net.URLConnection#setDoInput(boolean)
- */
- public void test_setDoInputZ() throws MalformedURLException, IOException {
- assertTrue("Used to test", true);
- HttpURLConnection u = null;
-
- u = (HttpURLConnection) (new URL("http://localhost:" + port)
- .openConnection());
- u.connect();
-
- try {
- u.setDoInput(true);
- } catch (IllegalStateException e) { // expected
- }
- }
-
- /**
- * @throws IOException
- * @throws MalformedURLException
- * @tests java.net.URLConnection#setDoOutput(boolean)
- */
- public void test_setDoOutputZ() throws MalformedURLException, IOException {
- assertTrue("Used to test", true);
- HttpURLConnection u = null;
-
- u = (HttpURLConnection) (new URL("http://localhost:" + port)
- .openConnection());
- u.connect();
-
- try {
- u.setDoOutput(true);
- } catch (IllegalStateException e) { // expected
- }
- }
-
- /**
- * @throws IOException
* @tests java.net.URLConnection#setFileNameMap(java.net.FileNameMap)
*/
public void test_setFileNameMapLjava_net_FileNameMap() throws IOException {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
index fd53ea0..d91f6f6 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
@@ -18,14 +18,13 @@
package org.apache.harmony.luni.tests.java.net;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
+import java.net.Proxy.Type;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
@@ -33,14 +32,10 @@
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;
-
import junit.framework.TestCase;
import tests.support.Support_Configuration;
-import tests.support.Support_Jetty;
import tests.support.resource.Support_Resources;
public class URLTest extends TestCase {
@@ -70,55 +65,6 @@
static boolean isSelectCalled;
-
- /**
- * Check when the argument in url consists of windows path character back-slash
- * @tests java.net.URL#openConnection(Proxy)
- * @throws Exception
- */
- public void test_openConnection_windows_path_character() throws Exception {
- int port = Support_Jetty.startDefaultHttpServer();
- HttpURLConnection con = null;
- try {
- URL url = new URL("http://0.0.0.0:" + port + "/servlet?ResourceName=C:\\temp\\test.txt");
- con = (HttpURLConnection) url.openConnection();
- con.setDoInput(true);
- con.setDoOutput(true);
- con.setUseCaches(false);
- con.setRequestMethod("GET");
- InputStream is = con.getInputStream();
- } finally {
- if (con != null) {
- con.disconnect();
- }
- }
- }
-
- /**
- * Check when the argument in url consists of quotation marks character
- * @tests java.net.URL#openConnection(Proxy)
- * @throws Exception
- */
- public void test_openConnection_quotation_marks_character()
- throws Exception {
- int port = Support_Jetty.startDefaultHttpServer();
- HttpURLConnection con = null;
- try {
- URL url = new URL("http://0.0.0.0:" + port
- + "/servlet?ResourceName=[\"11111\",\"22222\"]");
- con = (HttpURLConnection) url.openConnection();
- con.setDoInput(true);
- con.setDoOutput(true);
- con.setUseCaches(false);
- con.setRequestMethod("GET");
- InputStream is = con.getInputStream();
- } finally {
- if (con != null) {
- con.disconnect();
- }
- }
- }
-
/**
* @tests java.net.URL#URL(java.lang.String)
*/
@@ -876,41 +822,6 @@
exception = true;
}
assertTrue("openStream succeeded for non existent resource", exception);
-
- int port = Support_Jetty
- .startHttpServerWithDocRoot("resources/org/apache/harmony/luni/tests/java/net/");
- URL u = new URL("jar:" + "http://localhost:" + port
- + "/lf.jar!/plus.bmp");
- InputStream in = u.openStream();
- byte[] buf = new byte[3];
- int result = in.read(buf);
- assertTrue("Incompete read: " + result, result == 3);
- in.close();
- assertTrue("Returned incorrect data", buf[0] == 0x42 && buf[1] == 0x4d
- && buf[2] == (byte) 0xbe);
-
- // FIXME Lack of FTP server, comment it out temporarily
- /*
- * u = new URL("ftp://" + Support_Configuration.FTPTestAddress +
- * "/nettest.txt"); in = u.openStream(); buf = new byte[3];
- * assertEquals("Incompete read 2", 3, in.read(buf)); in.close();
- * assertTrue("Returned incorrect data 2", buf[0] == 0x54 && buf[1] ==
- * 0x68 && buf[2] == 0x69);
- */
-
- File test = new File("hytest.$$$");
- FileOutputStream out = new FileOutputStream(test);
- out.write(new byte[] { 0x55, (byte) 0xaa, 0x14 });
- out.close();
- u = new URL("file:" + test.getName());
- in = u.openStream();
- buf = new byte[3];
- result = in.read(buf);
- in.close();
- test.delete();
- assertEquals("Incompete read 3", 3, result);
- assertTrue("Returned incorrect data 3", buf[0] == 0x55
- && buf[1] == (byte) 0xaa && buf[2] == 0x14);
}
/**