diff options
author | Hannes Wellmann | 2022-02-11 17:12:19 +0000 |
---|---|---|
committer | Hannes Wellmann | 2022-02-11 17:50:02 +0000 |
commit | 120e8a7bb1fc368e3d75eecec5c08679985e70c0 (patch) | |
tree | a89432710933773a88b68fda0e4b2f084b802779 | |
parent | 28af65eac1ff2aa96e2b5fcc8f0e7552a9752ab3 (diff) | |
download | rt.equinox.bundles-120e8a7bb1fc368e3d75eecec5c08679985e70c0.tar.gz rt.equinox.bundles-120e8a7bb1fc368e3d75eecec5c08679985e70c0.tar.xz rt.equinox.bundles-120e8a7bb1fc368e3d75eecec5c08679985e70c0.zip |
Bug 578702 - Move FileLocatorTest to rt.equinox.bundles repositoryI20220211-1800
This is the addition part of the move.
As part of the move FileLocatorTest was ported to JUnit-4 and some minor
improvements were applied.
Change-Id: I035c760a8063a1b9dc42d127aeb165b9f1c61132
Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/190731
Tested-by: Equinox Bot <equinox-bot@eclipse.org>
11 files changed, 257 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/META-INF/MANIFEST.MF new file mode 100644 index 000000000..074ef97de --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/META-INF/MANIFEST.MF @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: fileLocator test NL Fragment +Bundle-SymbolicName: fileLocatorTest.nl +Bundle-Version: 1.0.0 +Fragment-Host: fileLocatorTest;bundle-version="1.0.0" diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/nl/aa/BB/intro/messages.properties b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/nl/aa/BB/intro/messages.properties new file mode 100644 index 000000000..69474551c --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/nl/aa/BB/intro/messages.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2012 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/nl/aa/intro/messages.properties b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/nl/aa/intro/messages.properties new file mode 100644 index 000000000..69474551c --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator.nl/nl/aa/intro/messages.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2012 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/META-INF/MANIFEST.MF new file mode 100644 index 000000000..65ae0657e --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: fileLocator test +Bundle-SymbolicName: fileLocatorTest +Bundle-Version: 1.0.0 diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/intro/messages.properties b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/intro/messages.properties new file mode 100644 index 000000000..69474551c --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/intro/messages.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2012 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/nl/aa/BB/intro/messages.properties b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/nl/aa/BB/intro/messages.properties new file mode 100644 index 000000000..69474551c --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/nl/aa/BB/intro/messages.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2012 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/nl/aa/intro/messages.properties b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/nl/aa/intro/messages.properties new file mode 100644 index 000000000..69474551c --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocator/nl/aa/intro/messages.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2012 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocatorGetRootFile.jar b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocatorGetRootFile.jar Binary files differnew file mode 100644 index 000000000..2c955a322 --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocatorGetRootFile.jar diff --git a/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocatorGetRootFile/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocatorGetRootFile/META-INF/MANIFEST.MF new file mode 100644 index 000000000..2505a834e --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/Plugin_Testing/fileLocator/testFileLocatorGetRootFile/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: fileLocator test +Bundle-SymbolicName: fileLocatorTestGetRootFile +Bundle-Version: 1.0.0 diff --git a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/core/runtime/tests/FileLocatorTest.java b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/core/runtime/tests/FileLocatorTest.java new file mode 100644 index 000000000..c585836e0 --- /dev/null +++ b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/core/runtime/tests/FileLocatorTest.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2006, 2022 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Hannes Wellmann - Bug 578702 - Move FileLocatorTest to rt.equinox.bundles repository + *******************************************************************************/ +package org.eclipse.core.runtime.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.tests.harness.BundleTestingHelper; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.FrameworkUtil; + +public class FileLocatorTest { + + private final static String searchLocation = "$nl$/intro/messages.properties"; + + private final static String nl = "aa_BB"; // make sure we have a stable NL value + + private final static String mostSpecificPath = "/nl/aa/BB/intro/messages.properties"; + private final static String lessSpecificPath = "/nl/aa/intro/messages.properties"; + private final static String nonSpecificPath = "/intro/messages.properties"; + + @Test + public void testFileLocatorFind() throws IOException, BundleException { + Bundle bundle = BundleTestingHelper.installBundle("Plugin", getContext(), + "Plugin_Testing/fileLocator/testFileLocator"); + BundleTestingHelper.refreshPackages(getContext(), new Bundle[] { bundle }); + Bundle fragment = BundleTestingHelper.installBundle("Fragment", getContext(), + "Plugin_Testing/fileLocator/testFileLocator.nl"); + BundleTestingHelper.refreshPackages(getContext(), new Bundle[] { fragment }); + + IPath path = new Path(searchLocation); + Map<String, String> map = new HashMap<>(1); + map.put("$nl$", nl); + + URL oneSolution = FileLocator.find(bundle, path, map); + assertNotNull(oneSolution); + assertEquals(mostSpecificPath, oneSolution.getPath()); + assertBundleURL(oneSolution); + + URL[] solutions = FileLocator.findEntries(bundle, path, map); + + // expected: + // Bundle/nl/aa/BB/intro/messages.properties, + // Fragment/nl/aa/BB/intro/messages.properties, + // Bundle/nl/aa/intro/messages.properties, + // Fragment/nl/aa/intro/messages.properties, + // Bundle/121/intro/messages.properties + + assertEquals(5, solutions.length); + + assertEquals(mostSpecificPath, solutions[0].getPath()); + assertBundleURL(solutions[0]); + assertEquals(mostSpecificPath, solutions[1].getPath()); + assertFragmentURL(solutions[1]); + + assertEquals(lessSpecificPath, solutions[2].getPath()); + assertBundleURL(solutions[2]); + assertEquals(lessSpecificPath, solutions[3].getPath()); + assertFragmentURL(solutions[3]); + + assertEquals(nonSpecificPath, solutions[4].getPath()); + assertBundleURL(solutions[4]); + + // remove the first bundle + fragment.uninstall(); + BundleTestingHelper.refreshPackages(getContext(), new Bundle[] { fragment }); + bundle.uninstall(); + BundleTestingHelper.refreshPackages(getContext(), new Bundle[] { bundle }); + } + + @Test + public void testFileLocatorGetBundleFile01() throws BundleException, IOException { + // test for bug 198447 + // install the bundle via reference + BundleContext context = getContext(); + URL url = context.getBundle().getEntry("Plugin_Testing/fileLocator/testFileLocatorGetRootFile"); + Bundle bundle = context.installBundle("reference:" + FileLocator.toFileURL(url).toExternalForm()); + BundleTestingHelper.refreshPackages(context, new Bundle[] { bundle }); + + File file1 = FileLocator.getBundleFile(bundle); + assertNotNull(file1); + + URL fileURL = FileLocator + .toFileURL(context.getBundle().getEntry("Plugin_Testing/fileLocator/testFileLocatorGetRootFile")); + assertEquals(file1, new File(fileURL.getFile())); + + // remove the bundle + bundle.uninstall(); + BundleTestingHelper.refreshPackages(context, new Bundle[] { bundle }); + } + + @Test + public void testFileLocatorGetBundleFile02() throws BundleException, IOException, URISyntaxException { + // install the bundle via reference + BundleContext context = getContext(); + URL url = context.getBundle().getEntry("Plugin_Testing/fileLocator/testFileLocatorGetRootFile.jar"); + Bundle bundle = context.installBundle("reference:" + FileLocator.toFileURL(url).toExternalForm()); + BundleTestingHelper.refreshPackages(context, new Bundle[] { bundle }); + + File file1 = FileLocator.getBundleFile(bundle); + assertNotNull(file1); + + URL fileURL = FileLocator + .toFileURL(context.getBundle().getEntry("Plugin_Testing/fileLocator/testFileLocatorGetRootFile.jar")); + assertEquals(file1, new File(fileURL.getFile())); + + URL manifest = bundle.getEntry("META-INF/MANIFEST.MF"); + manifest = FileLocator.resolve(manifest); + assertEquals("Expection jar protocol: " + manifest.toExternalForm(), "jar", manifest.getProtocol()); + + String manifestExternal = manifest.toExternalForm(); + int index = manifestExternal.lastIndexOf('!'); + assertTrue("No ! found", index >= 0); + String fileExternal = manifestExternal.substring(4, index); + + URL fileExternalURL = new URL(fileExternal); + new File(fileExternalURL.toURI()); + + // remove the bundle + bundle.uninstall(); + BundleTestingHelper.refreshPackages(context, new Bundle[] { bundle }); + } + + private BundleContext getContext() { + return FrameworkUtil.getBundle(FileLocatorTest.class).getBundleContext(); + } + + private Bundle getHostBundle(URL url) { + String host = url.getHost(); + int dot = host.indexOf('.'); + Long hostId = Long.decode(dot < 0 ? host : host.substring(0, dot)); + assertNotNull(hostId); + return getContext().getBundle(hostId.longValue()); + } + + private void assertBundleURL(URL url) { + Bundle hostBundle = getHostBundle(url); + assertNotNull(hostBundle); + assertEquals("fileLocatorTest", hostBundle.getSymbolicName()); + } + + private void assertFragmentURL(URL url) { + Bundle hostBundle = getHostBundle(url); + assertNotNull(hostBundle); + assertEquals("fileLocatorTest.nl", hostBundle.getSymbolicName()); + } +} diff --git a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/AllTests.java b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/AllTests.java index 9780832b2..e55f05ca7 100644 --- a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/AllTests.java +++ b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/AllTests.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.equinox.common.tests; +import org.eclipse.core.runtime.tests.FileLocatorTest; import org.eclipse.equinox.common.tests.adaptable.AdaptableTests; import org.eclipse.equinox.common.tests.registry.RegistryTests; import org.eclipse.equinox.common.tests.registry.simple.SimpleRegistryTests; @@ -27,7 +28,8 @@ import org.junit.runners.Suite.SuiteClasses; RuntimeTests.class, AdaptableTests.class, RegistryTests.class, - SimpleRegistryTests.class + SimpleRegistryTests.class, + FileLocatorTest.class }) public class AllTests { // intentionally left blank |