Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2008-10-09 03:22:47 +0000
committerJohn Arthorne2008-10-09 03:22:47 +0000
commit773624727040c3a294359169f0f8d4aa22a7071d (patch)
treef51675a1f16deb759720dc7c3a4daa379935fdbd /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core
parentdfe94e43cf371e39d46b07c9f0e6c6b28eeb000e (diff)
downloadrt.equinox.p2-773624727040c3a294359169f0f8d4aa22a7071d.tar.gz
rt.equinox.p2-773624727040c3a294359169f0f8d4aa22a7071d.tar.xz
rt.equinox.p2-773624727040c3a294359169f0f8d4aa22a7071d.zip
Bug 237776 Replace URL by URI
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/URIUtilTest.java59
2 files changed, 60 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java
index cbcf6f376..ade5b0dfd 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java
@@ -21,6 +21,7 @@ public class AllTests extends TestCase {
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTestSuite(FileUtilsTest.class);
suite.addTestSuite(OrderedPropertiesTest.class);
+ suite.addTestSuite(URIUtilTest.class);
suite.addTestSuite(URLUtilTest.class);
return suite;
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/URIUtilTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/URIUtilTest.java
new file mode 100644
index 000000000..d1247a3a0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/URIUtilTest.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.core;
+
+import java.io.File;
+import java.net.*;
+import org.eclipse.equinox.internal.p2.core.helpers.URIUtil;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+/**
+ * Tests for the {@link URLUtil} class.
+ */
+public class URIUtilTest extends AbstractProvisioningTest {
+ private static final String[] testPaths = new String[] {"abc", "with spaces", "with%percent"};
+
+ /**
+ * Tests for {@link URLUtil#toFile(URL)}.
+ */
+ public void testToFile() {
+ File base = new File(System.getProperty("java.io.tmpdir"));
+ for (int i = 0; i < testPaths.length; i++) {
+ File original = new File(base, testPaths[i]);
+ URI uri = original.toURI();
+ File result = URIUtil.toFile(uri);
+ assertEquals("1." + i, original, result);
+ }
+ }
+
+ /**
+ * Tests for {@link URIUtil#fromString(String)}.
+ */
+ public void testFromString() throws URISyntaxException {
+ //spaces
+ assertEquals("1.1", new URI("http://foo.bar/a%20b"), URIUtil.fromString("http://foo.bar/a b"));
+ assertEquals("1.2", new URI("http://foo.bar/a#b%20c"), URIUtil.fromString("http://foo.bar/a#b c"));
+ assertEquals("1.3", new URI("foo.bar/a%20b"), URIUtil.fromString("foo.bar/a b"));
+ assertEquals("1.4", new URI("#a%20b"), URIUtil.fromString("#a b"));
+ }
+
+ /**
+ * Tests for {@link URIUtil#toURI(java.net.URL)}.
+ */
+ public void testURLtoURI() throws MalformedURLException, URISyntaxException {
+ //spaces
+ assertEquals("1.1", new URI("http://foo.bar/a%20b"), URIUtil.toURI(new URL("http://foo.bar/a b")));
+ assertEquals("1.2", new URI("http://foo.bar/a#b%20c"), URIUtil.toURI(new URL("http://foo.bar/a#b c")));
+
+ //missing slash
+ assertEquals("1.1", new URI("file:/c:/foo/bar.txt"), URIUtil.toURI(new URL("file:c:/foo/bar.txt")));
+ }
+}

Back to the top