summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-05-08 23:10:59 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-05-09 09:17:42 (EDT)
commitc14566b7d2047b6747e359bf22ce5a17d972fe82 (patch)
tree5173a3ff3cd8923a09a26fc76d62e0b87d727746
parent3abd816821095f39a02344f491fe3970983b897c (diff)
downloadorg.eclipse.mylyn.commons-c14566b7d2047b6747e359bf22ce5a17d972fe82.zip
org.eclipse.mylyn.commons-c14566b7d2047b6747e359bf22ce5a17d972fe82.tar.gz
org.eclipse.mylyn.commons-c14566b7d2047b6747e359bf22ce5a17d972fe82.tar.bz2
407445: [api] provide web locations for testingrefs/changes/69/12669/3
Change-Id: Ie967ab5336607fac4ba154a7ea35b73c3e217320 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=407445
-rw-r--r--org.eclipse.mylyn.commons.sdk.util/.project2
-rw-r--r--org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestUrl.java74
-rw-r--r--org.eclipse.mylyn.commons.tests/.classpath1
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java20
4 files changed, 85 insertions, 12 deletions
diff --git a/org.eclipse.mylyn.commons.sdk.util/.project b/org.eclipse.mylyn.commons.sdk.util/.project
index d2142fe..627f382 100644
--- a/org.eclipse.mylyn.commons.sdk.util/.project
+++ b/org.eclipse.mylyn.commons.sdk.util/.project
@@ -33,7 +33,7 @@
</natures>
<filteredResources>
<filter>
- <id>1367109048408</id>
+ <id>1368069128607</id>
<name></name>
<type>10</type>
<matcher>
diff --git a/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestUrl.java b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestUrl.java
new file mode 100644
index 0000000..24424b6
--- /dev/null
+++ b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestUrl.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.sdk.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Provides URLs for testing connections.
+ *
+ * @author Steffen Pingel
+ */
+public class TestUrl {
+
+ public static final TestUrl DEFAULT = new TestUrl();
+
+ private final String URL_HTTP_404_NOT_FOUND = "http://mylyn.org/notfound";
+
+ private final String URL_HTTP_CONNECTION_REFUSED = "http://mylyn.org:9999/";
+
+ private final String URL_HTTP_CONNECTION_TIMEOUT = "http://google.com:9999/";
+
+ private final String URL_HTTP_OK = "http://mylyn.org/";
+
+ private final String URL_HTTP_UNKNOWN_HOST = "http://nonexistant.mylyn.org";
+
+ private final String URL_HTTPS_OK = "https://mylyn.org/";
+
+ public URL getConnectionRefused() {
+ return createUrl(URL_HTTP_CONNECTION_REFUSED);
+ }
+
+ public URL getConnectionTimeout() {
+ return createUrl(URL_HTTP_CONNECTION_TIMEOUT);
+ }
+
+ public URL getHttpNotFound() {
+ return createUrl(URL_HTTP_404_NOT_FOUND);
+ }
+
+ public URL getHttpOk() {
+ return createUrl(URL_HTTP_OK);
+ }
+
+ public URL getHttpsOk() {
+ return createUrl(URL_HTTPS_OK);
+ }
+
+ public URL getUnknownHost() {
+ return createUrl(URL_HTTP_UNKNOWN_HOST);
+ }
+
+ private URL createUrl(String url) {
+ try {
+ return new URL(url);
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private TestUrl() {
+ // not intended to be instantiated
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.tests/.classpath b/org.eclipse.mylyn.commons.tests/.classpath
index 2c447f4..e2615e5 100644
--- a/org.eclipse.mylyn.commons.tests/.classpath
+++ b/org.eclipse.mylyn.commons.tests/.classpath
@@ -5,6 +5,7 @@
<accessrules>
<accessrule kind="accessible" pattern="org/eclipse/mylyn/internal/**"/>
<accessrule kind="accessible" pattern="org/eclipse/core/internal/net/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/mylyn/commons/sdk/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="src" path="src"/>
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
index f539986..7b09467 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
@@ -41,6 +41,7 @@ import org.eclipse.mylyn.commons.net.IProxyProvider;
import org.eclipse.mylyn.commons.net.WebLocation;
import org.eclipse.mylyn.commons.net.WebUtil;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
+import org.eclipse.mylyn.commons.sdk.util.TestUrl;
import org.eclipse.mylyn.commons.tests.support.TestProxy;
import org.eclipse.mylyn.commons.tests.support.TestProxy.Message;
import org.eclipse.mylyn.internal.commons.net.AuthenticatedProxy;
@@ -139,11 +140,10 @@ public class WebUtilTest extends TestCase {
public void testExecute() throws Exception {
StubProgressMonitor monitor = new StubProgressMonitor();
HttpClient client = new HttpClient();
- String url = "http://mylyn.org/";
- WebLocation location = new WebLocation(url);
+ WebLocation location = new WebLocation(TestUrl.DEFAULT.getHttpOk().toString());
HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, monitor);
- GetMethod method = new GetMethod(url);
+ GetMethod method = new GetMethod(location.getUrl());
try {
int result = WebUtil.execute(client, hostConfiguration, method, monitor);
assertEquals(HttpStatus.SC_OK, result);
@@ -155,11 +155,10 @@ public class WebUtilTest extends TestCase {
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);
+ WebLocation location = new WebLocation(TestUrl.DEFAULT.getConnectionTimeout().toString());
HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, monitor);
- GetMethod method = new GetMethod(url);
+ GetMethod method = new GetMethod(location.getUrl());
try {
Runnable runner = new Runnable() {
public void run() {
@@ -184,11 +183,10 @@ public class WebUtilTest extends TestCase {
public void testExecuteAlreadyCancelled() throws Exception {
StubProgressMonitor monitor = new StubProgressMonitor();
HttpClient client = new HttpClient();
- String url = "http://mylyn.org/";
- WebLocation location = new WebLocation(url);
+ WebLocation location = new WebLocation(TestUrl.DEFAULT.getHttpOk().toString());
HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, monitor);
- GetMethod method = new GetMethod(url);
+ GetMethod method = new GetMethod(location.getUrl());
try {
monitor.canceled = true;
WebUtil.execute(client, hostConfiguration, method, monitor);
@@ -217,13 +215,13 @@ public class WebUtilTest extends TestCase {
public void testCreateHostConfigurationProxy() throws Exception {
StubProgressMonitor monitor = new StubProgressMonitor();
HttpClient client = new HttpClient();
- WebUtil.createHostConfiguration(client, new WebLocation("http://mylyn.org/", null, null, new IProxyProvider() {
+ WebUtil.createHostConfiguration(client, new WebLocation(TestUrl.DEFAULT.getHttpOk().toString(), null, null, new IProxyProvider() {
public Proxy getProxyForHost(String host, String proxyType) {
assertEquals(IProxyData.HTTP_PROXY_TYPE, proxyType);
return null;
}
}), monitor);
- WebUtil.createHostConfiguration(client, new WebLocation("https://eclipse.org/", null, null,
+ WebUtil.createHostConfiguration(client, new WebLocation(TestUrl.DEFAULT.getHttpsOk().toString(), null, null,
new IProxyProvider() {
public Proxy getProxyForHost(String host, String proxyType) {
assertEquals(IProxyData.HTTPS_PROXY_TYPE, proxyType);