Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorpelder2007-07-11 14:37:34 -0400
committerpelder2007-07-11 14:37:34 -0400
commit41f81d40fc42738ee3b7a2847fc34bf6ab05595b (patch)
tree7287b15c756395fa83ae68513107f987d0aeeb50 /tests
parent613c2fd6cc0190811cbb16703b1e88af2a78ec42 (diff)
downloadorg.eclipse.jet-41f81d40fc42738ee3b7a2847fc34bf6ab05595b.tar.gz
org.eclipse.jet-41f81d40fc42738ee3b7a2847fc34bf6ab05595b.tar.xz
org.eclipse.jet-41f81d40fc42738ee3b7a2847fc34bf6ab05595b.zip
[195924] Malformed URLs in JET
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.jet.tests-feature/feature.xml2
-rw-r--r--tests/org.eclipse.jet.tests.core/data/templates folder.jarbin0 -> 1567 bytes
-rw-r--r--tests/org.eclipse.jet.tests.core/data/templates folder.zipbin0 -> 1567 bytes
-rw-r--r--tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java1
-rw-r--r--tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java17
-rw-r--r--tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java125
6 files changed, 144 insertions, 1 deletions
diff --git a/tests/org.eclipse.jet.tests-feature/feature.xml b/tests/org.eclipse.jet.tests-feature/feature.xml
index d8731aa..4e8b72c 100644
--- a/tests/org.eclipse.jet.tests-feature/feature.xml
+++ b/tests/org.eclipse.jet.tests-feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jet.tests"
label="%featureName"
- version="0.8.0.qualifier"
+ version="0.8.1.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/modeling/m2t">
diff --git a/tests/org.eclipse.jet.tests.core/data/templates folder.jar b/tests/org.eclipse.jet.tests.core/data/templates folder.jar
new file mode 100644
index 0000000..055a260
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/data/templates folder.jar
Binary files differ
diff --git a/tests/org.eclipse.jet.tests.core/data/templates folder.zip b/tests/org.eclipse.jet.tests.core/data/templates folder.zip
new file mode 100644
index 0000000..055a260
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/data/templates folder.zip
Binary files differ
diff --git a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java
index 9af446f..04964bd 100644
--- a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java
+++ b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java
@@ -7,6 +7,7 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.eclipse.jet.tests.tools"); //$NON-NLS-1$
+ suite.addTest(org.eclipse.jet.tests.core.url.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.parser.jasper.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.tools.compiler.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.tools.parser.AllTests.suite());
diff --git a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java
new file mode 100644
index 0000000..75ed8cf
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.tests.core.url;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test for org.eclipse.jet.tests.core.url");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(TestURLUtility.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java
new file mode 100644
index 0000000..7fff5f3
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2007 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.jet.tests.core.url;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jet.internal.core.url.URLUtility;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author pelder
+ *
+ */
+public class TestURLUtility extends TestCase {
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#jarRootEntryURL(java.net.URL)}.
+ * @throws IOException
+ */
+ public void test_jar_platform_plugin() throws IOException {
+ URL platformURL = new URL("platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar");
+ assertEquals("platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar", platformURL.toExternalForm());
+
+ URL platformJARRoot = URLUtility.jarRootEntryURL(platformURL);
+ assertEquals("jar:platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar!/", platformJARRoot.toExternalForm());
+
+ URL test1TxtURL = URLUtility.jarEntryURL(platformURL, "templates/base1/Copy of test1.txt");
+ assertEquals("jar:platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar!/templates/base1/Copy of test1.txt",test1TxtURL.toExternalForm());
+ InputStream stream = test1TxtURL.openStream();
+ int nBytes = stream.available();
+ assertTrue(nBytes > 0);
+ byte[] buffer = new byte[nBytes];
+ int nRead = stream.read(buffer);
+ assertEquals(nBytes, nRead);
+ String content = new String(buffer,"Cp1252");
+ assertEquals("This is Copy of test1.txt in data/templates/base1.", content);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#jarRootEntryURL(java.net.URL)}.
+ * @throws IOException
+ */
+ public void test_jar_file() throws IOException {
+ final Bundle bundle = Platform.getBundle("org.eclipse.jet.tests.core");
+
+ final URL[] findEntries = FileLocator.findEntries(bundle, new Path("data/templates folder.jar"));
+ final URL entry = findEntries[0];
+ final URL resolved = FileLocator.resolve(entry);
+
+ URL test1TxtURL = URLUtility.jarEntryURL(resolved, "templates/base1/Copy of test1.txt");
+ InputStream stream = test1TxtURL.openStream();
+ int nBytes = stream.available();
+ assertTrue(nBytes > 0);
+ byte[] buffer = new byte[nBytes];
+ int nRead = stream.read(buffer);
+ assertEquals(nBytes, nRead);
+ String content = new String(buffer,"Cp1252");
+ assertEquals("This is Copy of test1.txt in data/templates/base1.", content);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#jarRootEntryURL(java.net.URL)}.
+ * @throws IOException
+ */
+ public void test_file_jar_file() throws IOException {
+ final Bundle bundle = Platform.getBundle("org.eclipse.jet.tests.core");
+
+ final URL[] findEntries = FileLocator.findEntries(bundle, new Path("data/templates folder.jar"));
+ final URL entry = findEntries[0];
+ final URL resolved = FileLocator.resolve(entry);
+
+ URL test1TxtURL = URLUtility.relativeURL(resolved, "templates/base1/Copy of test1.txt");
+// assertEquals("jar:platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar!/templates/base1/Copy of test1.txt",test1TxtURL.toExternalForm());
+ InputStream stream = test1TxtURL.openStream();
+ int nBytes = stream.available();
+ assertTrue(nBytes > 0);
+ byte[] buffer = new byte[nBytes];
+ int nRead = stream.read(buffer);
+ assertEquals(nBytes, nRead);
+ String content = new String(buffer,"Cp1252");
+ assertEquals("This is Copy of test1.txt in data/templates/base1.", content);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#toURL(java.net.URI)}.
+ * @throws URISyntaxException
+ * @throws IOException
+ */
+ public void testToURL() throws URISyntaxException, IOException {
+ final Bundle bundle = Platform.getBundle("org.eclipse.jet.tests.core");
+
+ final URL[] findEntries = FileLocator.findEntries(bundle, new Path("data/templates/base1/Copy of test1.txt"));
+ final URL entry = findEntries[0];
+ final URL resolved = FileLocator.resolve(entry);
+ final File file = new File(resolved.getPath());
+
+
+ URL test1TxtURL = file.toURL();
+
+ final String URI_STRING = file.toURI().toString();
+
+ URI uri = new URI(URI_STRING);
+ URL converted = uri.toURL();
+ assertEquals(URI_STRING, converted.toString());
+ }
+
+}

Back to the top