blob: 0a19c840149d5279c154c22cad1fa7d5d27ede71 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2005, 2012 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.core.tests.internal.runtime;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.tests.harness.BundleTestingHelper;
import org.eclipse.core.tests.runtime.RuntimeTest;
import org.eclipse.core.tests.runtime.RuntimeTestsPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
public class PlatformURLLocalTest extends RuntimeTest {
public static void assertEquals(String tag, URL expected, URL actual, boolean external) {
if (external) {
assertEquals(tag, expected, actual);
return;
}
try {
assertEquals(tag + ".1", new URL(expected.getProtocol(), expected.getHost(), expected.getPort(), expected.getFile()), new URL(actual.getProtocol(), actual.getHost(), actual.getPort(), actual.getFile()));
} catch (MalformedURLException e) {
fail(tag + ".2", e);
}
}
public static Test suite() {
return new TestSuite(PlatformURLLocalTest.class);
}
public PlatformURLLocalTest(String name) {
super(name);
}
public void testPlatformURLConfigResolution() {
URL platformURL = null;
try {
// create a fake URL
platformURL = new URL("platform:/config/x");
} catch (MalformedURLException e) {
fail("1.0", e);
}
URL resolvedURL = null;
try {
resolvedURL = Platform.resolve(platformURL);
} catch (IOException e) {
fail("2.0", e);
}
assertFalse("3.0", platformURL.equals(resolvedURL));
URL expected = null;
try {
expected = new URL(Platform.getConfigurationLocation().getURL(), "x");
} catch (MalformedURLException e) {
fail("4.0", e);
}
assertEquals("5.0", expected, resolvedURL, false);
}
public void testPlatformURLMetaResolution() {
URL platformURL = null;
try {
// create a fake URL
platformURL = new URL("platform:/meta/" + PI_RUNTIME_TESTS + "/x");
} catch (MalformedURLException e) {
fail("1.0", e);
}
URL resolvedURL = null;
try {
resolvedURL = Platform.resolve(platformURL);
} catch (IOException e) {
fail("2.0", e);
}
assertFalse("3.0", platformURL.equals(resolvedURL));
URL expected = null;
try {
expected = new URL(RuntimeTestsPlugin.getPlugin().getStateLocation().toFile().toURL(), "x");
} catch (MalformedURLException e) {
fail("4.0", e);
}
assertEquals("5.0", expected, resolvedURL, false);
}
public void testBug155081() throws IOException, BundleException {
Bundle bundle = null;
try {
bundle = BundleTestingHelper.installBundle("0.1", RuntimeTestsPlugin.getContext(), RuntimeTestsPlugin.TEST_FILES_ROOT + "platformURL/platform.test.underscore");
BundleTestingHelper.refreshPackages(RuntimeTestsPlugin.getContext(), new Bundle[] {bundle});
URL test = new URL("platform:/plugin/platform.test.underscore_1.1.0.r321_v20060816/test.txt");
InputStream in = test.openStream();
in.close();
} finally {
if (bundle != null)
bundle.uninstall();
}
}
public void testBug300197_01() throws IOException, BundleException {
Bundle bundle = null;
try {
bundle = BundleTestingHelper.installBundle("0.1", RuntimeTestsPlugin.getContext(), RuntimeTestsPlugin.TEST_FILES_ROOT + "platformURL/platform_test_underscore");
BundleTestingHelper.refreshPackages(RuntimeTestsPlugin.getContext(), new Bundle[] {bundle});
URL test = new URL("platform:/plugin/platform_test_underscore/test.txt");
InputStream in = test.openStream();
in.close();
} finally {
if (bundle != null)
bundle.uninstall();
}
}
public void testBug300197_02() throws IOException, BundleException {
Bundle bundle = null;
try {
bundle = BundleTestingHelper.installBundle("0.1", RuntimeTestsPlugin.getContext(), RuntimeTestsPlugin.TEST_FILES_ROOT + "platformURL/platform_test_underscore_2.0.0");
BundleTestingHelper.refreshPackages(RuntimeTestsPlugin.getContext(), new Bundle[] {bundle});
URL test = new URL("platform:/plugin/platform_test_underscore_2.0.0/test.txt");
InputStream in = test.openStream();
in.close();
} finally {
if (bundle != null)
bundle.uninstall();
}
}
}