diff options
author | spingel | 2008-01-02 10:40:26 +0000 |
---|---|---|
committer | spingel | 2008-01-02 10:40:26 +0000 |
commit | b3f04d7700291ff747b39188eea19e85bb43b208 (patch) | |
tree | 545701671cb7920594a15e2241a5fdedb2de6e36 | |
parent | 189e0e06d5970a886e30eea52749ab9f4622090d (diff) | |
download | org.eclipse.mylyn-b3f04d7700291ff747b39188eea19e85bb43b208.tar.gz org.eclipse.mylyn-b3f04d7700291ff747b39188eea19e85bb43b208.tar.xz org.eclipse.mylyn-b3f04d7700291ff747b39188eea19e85bb43b208.zip |
NEW - bug 203403: Update to Apache HttpClient 3.1
https://bugs.eclipse.org/bugs/show_bug.cgi?id=203403
-rw-r--r-- | org.eclipse.mylyn.tests/src/org/eclipse/mylyn/tests/WebClientUtilTest.java | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tests/src/org/eclipse/mylyn/tests/WebClientUtilTest.java b/org.eclipse.mylyn.tests/src/org/eclipse/mylyn/tests/WebClientUtilTest.java index ce1f87ff..0d6161f1 100644 --- a/org.eclipse.mylyn.tests/src/org/eclipse/mylyn/tests/WebClientUtilTest.java +++ b/org.eclipse.mylyn.tests/src/org/eclipse/mylyn/tests/WebClientUtilTest.java @@ -8,17 +8,23 @@ package org.eclipse.mylyn.tests; +import java.io.IOException; +import java.io.InterruptedIOException; import java.net.InetSocketAddress; import java.net.Proxy; +import java.net.Socket; import java.net.Proxy.Type; import javax.net.ssl.SSLHandshakeException; import junit.framework.TestCase; +import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpClientParams; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.mylyn.tests.TestProxy.Message; import org.eclipse.mylyn.web.core.AbstractWebLocation; import org.eclipse.mylyn.web.core.AuthenticatedProxy; @@ -60,6 +66,92 @@ public class WebClientUtilTest extends TestCase { testProxy.stop(); } + public void testConnectCancelStalledConnect() throws Exception { + final StubProgressMonitor monitor = new StubProgressMonitor(); + String host = "google.com"; + int port = 9999; + + try { + Runnable runner = new Runnable() { + public void run() { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + monitor.canceled = true; + } + }; + new Thread(runner).start(); + WebClientUtil.connect(new Socket(), new InetSocketAddress(host, port), 5000, monitor); + fail("Expected InterruptedIOException"); + } catch (InterruptedIOException e) { + assertTrue(monitor.isCanceled()); + } + } + + public void testExecute() throws Exception { + StubProgressMonitor monitor = new StubProgressMonitor(); + HttpClient client = new HttpClient(); + String url = "http://eclipse.org/"; + WebLocation location = new WebLocation(url); + HostConfiguration hostConfiguration = WebClientUtil.createHostConfiguration(client, null, location, monitor); + + GetMethod method = new GetMethod(url); + try { + int result = WebClientUtil.execute(client, hostConfiguration, method, monitor); + assertEquals(HttpStatus.SC_OK, result); + } finally { + method.releaseConnection(); + } + } + + public void testExecuteCancelStalledConnect() throws Exception { + final StubProgressMonitor monitor = new StubProgressMonitor(); + HttpClient client = new HttpClient(); + String url = "http://google.com:9999/"; + WebLocation location = new WebLocation(url); + HostConfiguration hostConfiguration = WebClientUtil.createHostConfiguration(client, null, location, monitor); + + GetMethod method = new GetMethod(url); + try { + Runnable runner = new Runnable() { + public void run() { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + monitor.canceled = true; + } + }; + new Thread(runner).start(); + WebClientUtil.execute(client, hostConfiguration, method, monitor); + client.executeMethod(method); + fail("Expected exception"); + } catch (IOException e) { + assertTrue(monitor.isCanceled()); + } finally { + method.releaseConnection(); + } + } + + public void testExecuteAlreadyCancelled() throws Exception { + StubProgressMonitor monitor = new StubProgressMonitor(); + HttpClient client = new HttpClient(); + String url = "http://eclipse.org/"; + WebLocation location = new WebLocation(url); + HostConfiguration hostConfiguration = WebClientUtil.createHostConfiguration(client, null, location, monitor); + + GetMethod method = new GetMethod(url); + try { + monitor.canceled = true; + WebClientUtil.execute(client, hostConfiguration, method, monitor); + fail("Expected InterruptedIOException"); + } catch (InterruptedIOException expected) { + } finally { + method.releaseConnection(); + } + } + public void testConnect() throws Exception { String url = "http://" + proxyAddress.getHostName() + ":" + proxyAddress.getPort() + "/"; WebClientUtil.setupHttpClient(client, null, url, "", ""); @@ -527,4 +619,36 @@ public class WebClientUtilTest extends TestCase { assertEquals(200, statusCode); } + private class StubProgressMonitor implements IProgressMonitor { + + private volatile boolean canceled; + + public void beginTask(String name, int totalWork) { + } + + public void done() { + } + + public void internalWorked(double work) { + } + + public boolean isCanceled() { + return canceled; + } + + public void setCanceled(boolean value) { + this.canceled = value; + } + + public void setTaskName(String name) { + } + + public void subTask(String name) { + } + + public void worked(int work) { + } + + } + } |