Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.osgi.tests')
-rw-r--r--bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.osgi.tests/plugin.xml12
-rw-r--r--bundles/org.eclipse.osgi.tests/pom.xml4
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/AllTests.java1
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationRelaunchTest.java121
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/RelaunchApp.java136
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java2
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java6
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java6
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/AllTests.java1
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ModuleWiringTest.java166
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java48
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java2
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java15
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java1
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/StorageUtilTestCase.java53
16 files changed, 550 insertions, 26 deletions
diff --git a/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF
index 2f6c49b33..e6c6868a7 100644
--- a/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Core OSGi Tests
Bundle-SymbolicName: org.eclipse.osgi.tests;singleton:=true
-Bundle-Version: 3.16.400.qualifier
+Bundle-Version: 3.16.500.qualifier
Bundle-Vendor: Eclipse.org
Require-Bundle:
org.eclipse.core.runtime,
diff --git a/bundles/org.eclipse.osgi.tests/plugin.xml b/bundles/org.eclipse.osgi.tests/plugin.xml
index b27d6ae5d..f8453e146 100644
--- a/bundles/org.eclipse.osgi.tests/plugin.xml
+++ b/bundles/org.eclipse.osgi.tests/plugin.xml
@@ -95,4 +95,16 @@
</run>
</application>
</extension>
+ <extension
+ id="relaunchApp"
+ point="org.eclipse.core.runtime.applications">
+ <application
+ cardinality="1"
+ thread="main"
+ visible="true">
+ <run
+ class="org.eclipse.osgi.tests.appadmin.RelaunchApp">
+ </run>
+ </application>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.osgi.tests/pom.xml b/bundles/org.eclipse.osgi.tests/pom.xml
index 0d83c9778..c3f537cc2 100644
--- a/bundles/org.eclipse.osgi.tests/pom.xml
+++ b/bundles/org.eclipse.osgi.tests/pom.xml
@@ -14,12 +14,12 @@
<parent>
<artifactId>rt.equinox.framework</artifactId>
<groupId>org.eclipse.equinox.framework</groupId>
- <version>4.21.0-SNAPSHOT</version>
+ <version>4.22.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.tests</artifactId>
- <version>3.16.400-SNAPSHOT</version>
+ <version>3.16.500-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/AllTests.java
index 37a0e7283..66f8ca602 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/AllTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/AllTests.java
@@ -20,6 +20,7 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTest(ApplicationAdminTest.suite());
+ suite.addTest(ApplicationRelaunchTest.suite());
return suite;
}
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationRelaunchTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationRelaunchTest.java
new file mode 100644
index 000000000..d91ba9af9
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationRelaunchTest.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2021 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
+ *******************************************************************************/
+package org.eclipse.osgi.tests.appadmin;
+
+import java.util.HashMap;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.core.tests.session.ConfigurationSessionTestSuite;
+import org.eclipse.core.tests.session.SetupManager.SetupException;
+import org.eclipse.osgi.tests.OSGiTest;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.application.ApplicationDescriptor;
+import org.osgi.service.application.ApplicationHandle;
+
+// This is for the most part a stripped down copy of ApplicationAdminTest.
+public class ApplicationRelaunchTest extends OSGiTest {
+ public static final String testRunnerRelauncherApp = PI_OSGI_TESTS + ".relaunchApp"; //$NON-NLS-1$
+ public static final String testResults = "test.results"; //$NON-NLS-1$
+ public static final String SUCCESS = "success"; //$NON-NLS-1$
+ public static final String simpleResults = "test.simpleResults"; //$NON-NLS-1$
+ public static final String[] tests = new String[] { "testRelaunch" };
+ private static final String PI_OSGI_SERVICES = "org.eclipse.osgi.services"; //$NON-NLS-1$
+ private static final String PI_OSGI_UTIL = "org.eclipse.osgi.util";
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ApplicationRelaunchTest.class.getName());
+
+ ConfigurationSessionTestSuite appAdminSessionTest = new ConfigurationSessionTestSuite(PI_OSGI_TESTS, ApplicationRelaunchTest.class.getName());
+ String[] ids = ConfigurationSessionTestSuite.MINIMAL_BUNDLE_SET;
+ for (String id : ids) {
+ appAdminSessionTest.addBundle(id);
+ }
+ appAdminSessionTest.addBundle(PI_OSGI_UTIL);
+ appAdminSessionTest.addBundle(PI_OSGI_SERVICES);
+ appAdminSessionTest.addBundle(PI_OSGI_TESTS);
+ appAdminSessionTest.setApplicationId(testRunnerRelauncherApp);
+ try {
+ appAdminSessionTest.getSetup().setSystemProperty("eclipse.application.registerDescriptors", "true"); //$NON-NLS-1$//$NON-NLS-2$
+ } catch (SetupException e) {
+ throw new RuntimeException(e);
+ }
+ // we add tests the hard way so we can control the order of the tests.
+ for (String test : tests) {
+ appAdminSessionTest.addTest(new ApplicationRelaunchTest(test));
+ }
+ suite.addTest(appAdminSessionTest);
+ return suite;
+ }
+
+ public ApplicationRelaunchTest(String name) {
+ super(name);
+ }
+
+ private ApplicationDescriptor getApplication(String appName) {
+ try {
+ BundleContext context = getContext();
+ assertNotNull("BundleContext is null!!", context); //$NON-NLS-1$
+ Class appDescClass = ApplicationDescriptor.class;
+ assertNotNull("ApplicationDescriptor.class is null!!", appDescClass); //$NON-NLS-1$
+ ServiceReference[] refs = context.getServiceReferences(appDescClass.getName(), "(" + ApplicationDescriptor.APPLICATION_PID + "=" + appName + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (refs == null || refs.length == 0) {
+ refs = getContext().getServiceReferences(ApplicationDescriptor.class.getName(), null);
+ String availableApps = ""; //$NON-NLS-1$
+ if (refs != null) {
+ for (int i = 0; i < refs.length; i++) {
+ availableApps += refs[i].getProperty(ApplicationDescriptor.APPLICATION_PID);
+ if (i < refs.length - 1)
+ availableApps += ","; //$NON-NLS-1$
+ }
+ }
+ fail("Could not find app pid: " + appName + " available apps are: " + availableApps); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ ApplicationDescriptor result = (ApplicationDescriptor) getContext().getService(refs[0]);
+ if (result != null)
+ getContext().ungetService(refs[0]);
+ else
+ fail("Could not get application descriptor service: " + appName); //$NON-NLS-1$
+ return result;
+ } catch (InvalidSyntaxException e) {
+ fail("Could not create app filter", e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ private HashMap getArguments() {
+ HashMap args = new HashMap();
+ args.put(testResults, new HashMap());
+ return args;
+ }
+
+ public void testRelaunch() {
+ // this is the same as ApplicationAdminTest.testSimpleApp() (but launched
+ // through a different test runner app RelaunchApp which is the thing being
+ // tested)
+ ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".simpleApp"); //$NON-NLS-1$
+ HashMap args = getArguments();
+ HashMap results = (HashMap) args.get(testResults);
+ try {
+ ApplicationHandle handle = app.launch(args);
+ handle.destroy();
+ } catch (Throwable e) {
+ fail("failed to launch simpleApp", e); //$NON-NLS-1$
+ }
+ String result = (String) results.get(simpleResults);
+ assertEquals("Check application result", SUCCESS, result); //$NON-NLS-1$
+ }
+
+}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/RelaunchApp.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/RelaunchApp.java
new file mode 100644
index 000000000..f349f77d6
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/RelaunchApp.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+* Copyright (c) 2021 Indel AG 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:
+* Indel AG - initial API and implementation
+*******************************************************************************/
+package org.eclipse.osgi.tests.appadmin;
+
+import java.util.Collection;
+import java.util.Map;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+import org.eclipse.osgi.service.environment.EnvironmentInfo;
+import org.eclipse.osgi.tests.OSGiTestsActivator;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.application.ApplicationDescriptor;
+import org.osgi.service.application.ApplicationException;
+import org.osgi.service.application.ApplicationHandle;
+
+public class RelaunchApp implements IApplication {
+
+ @Override
+ public Object start(IApplicationContext context) throws Exception {
+ final Map arguments = context.getArguments();
+
+ // Setting eclipse.allowAppRelaunch to true at runtime should allow us to launch
+ // multiple applications in sequence
+ ServiceReference<EnvironmentInfo> envref = OSGiTestsActivator.getContext()
+ .getServiceReference(EnvironmentInfo.class);
+ EnvironmentInfo env = OSGiTestsActivator.getContext().getService(envref);
+ if (Boolean.valueOf(env.getProperty("eclipse.allowAppRelaunch"))) { //$NON-NLS-1$
+ throw new AssertionError("eclipse.allowAppRelaunch should not be set initially"); //$NON-NLS-1$
+ }
+ env.setProperty("eclipse.allowAppRelaunch", "true"); //$NON-NLS-1$ //$NON-NLS-2$
+ OSGiTestsActivator.getContext().ungetService(envref);
+
+ // Get a handle for the running application so we can wait for it to exit
+ ServiceReference<ApplicationHandle> thisAppRef = OSGiTestsActivator.getContext()
+ .getServiceReference(ApplicationHandle.class);
+ ApplicationHandle thisAppHandle = OSGiTestsActivator.getContext().getService(thisAppRef);
+
+ new Thread("launcher") { //$NON-NLS-1$
+ public void run() {
+ // Wait for this application to exit
+ try {
+ thisAppHandle.getExitValue(0);
+ } catch (ApplicationException e) {
+ // does not occur for timeout 0
+ } catch (InterruptedException e) {
+ // I don't think this should occur
+ e.printStackTrace();
+ }
+
+ // Get the descriptor for the actual test runner application.
+ // Need a test runner that runs in the main thread to avoid race conditions.
+ Collection<ServiceReference<ApplicationDescriptor>> testAppRefs = null;
+ try {
+ testAppRefs = OSGiTestsActivator.getContext().getServiceReferences(
+ org.osgi.service.application.ApplicationDescriptor.class,
+ "(" + Constants.SERVICE_PID + "=org.eclipse.pde.junit.runtime.nonuithreadtestapplication)"); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (InvalidSyntaxException e) {
+ // shouldn't happen, the hardcoded filter expression
+ // should be syntactically correct
+ e.printStackTrace();
+ }
+ ServiceReference<ApplicationDescriptor> testAppRef = testAppRefs.iterator().next();
+ ApplicationDescriptor testAppDescriptor = OSGiTestsActivator.getContext().getService(testAppRef);
+
+ // Launch the new application
+ // If it does launch, it will run some unrelated succeeding test
+ // and thereby confirm that relaunching works.
+ try {
+ ApplicationHandle testAppHandle;
+ // There is a race condition in that the previous
+ // application may not have exited far enough yet for
+ // the EclipseAppLauncher to allow launching of a new
+ // application: Setting the exit value happens earlier
+ // in EclipseAppLauncher.runApplication() (inside
+ // EclipseAppHandle.run()) than releasing runningLock.
+ // Unfortunately there is no way to wait for the
+ // EclipseAppLauncher to be ready, so just try again
+ // after a delay when that happens.
+ while (true) {
+ try {
+ testAppHandle = testAppDescriptor.launch(arguments);
+ break;
+ } catch (IllegalStateException e) {
+ Thread.sleep(100);
+ }
+ }
+
+ // Wait for the test application to exit
+ testAppHandle.getExitValue(0);
+ } catch (ApplicationException | InterruptedException e) {
+ // ApplicationException "The main thread is not available to launch the
+ // application" can happen when the test fails
+ e.printStackTrace();
+ } finally {
+ OSGiTestsActivator.getContext().ungetService(thisAppRef);
+ OSGiTestsActivator.getContext().ungetService(testAppRef);
+
+ try {
+ // This will not return but cause the process to terminate
+ OSGiTestsActivator.getContext().getBundle(0).stop();
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }.start();
+
+ // If relaunching does not work, the process will end after this and the test
+ // will end with an error "Test did not run". The "launcher" thread will be
+ // killed wherever its execution happens to be, which is a race condition that
+ // means that there may be various exceptions printed or not. However even if it
+ // successfully got past testAppDescriptor.launch(), the test runner which wants
+ // to run in the main thread will never actually run, so the test cannot
+ // mistakenly succeed.
+ return null;
+ }
+
+ @Override
+ public void stop() {
+ }
+
+}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java
index 7d2d6c2c5..50bc6a608 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java
@@ -312,7 +312,7 @@ public class AbstractBundleTests extends CoreTest {
final Exception[] failureException = new BundleException[1];
final FrameworkEvent[] success = new FrameworkEvent[] { null };
final String uuid = getUUID(equinox);
- Thread waitForUpdate = new Thread((Runnable) () -> success[0] = waitForStop(equinox, uuid, false, 10000), "test waitForStop thread"); //$NON-NLS-1$
+ Thread waitForUpdate = new Thread(() -> success[0] = waitForStop(equinox, uuid, false, 10000), "test waitForStop thread"); //$NON-NLS-1$
waitForUpdate.start();
try {
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java
index e12ce5674..11f37e8d5 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java
@@ -600,7 +600,7 @@ public class ClassLoadingBundleTests extends AbstractBundleTests {
final Bundle osgiE = installer.installBundle("osgi.lazystart.e"); //$NON-NLS-1$
assertTrue("osgi lazy start resolve", installer.resolveBundles(new Bundle[] {osgiD, osgiE})); //$NON-NLS-1$
- Thread t = new Thread((Runnable) () -> {
+ Thread t = new Thread(() -> {
try {
osgiD.loadClass("osgi.lazystart.d.DTest");
} catch (ClassNotFoundException e) {
@@ -2158,7 +2158,7 @@ public class ClassLoadingBundleTests extends AbstractBundleTests {
};
getContext().addBundleListener(delayB1);
try {
- new Thread((Runnable) () -> {
+ new Thread(() -> {
try {
System.out.println(getName() + ": Initial load test.");
a1.loadClass("test.bug490902.a.TestLoadA1").newInstance();
@@ -2168,7 +2168,7 @@ public class ClassLoadingBundleTests extends AbstractBundleTests {
}, "Initial load test thread.").start();
startingB.await();
- Thread secondThread = new Thread((Runnable) () -> {
+ Thread secondThread = new Thread(() -> {
try {
System.out.println(getName() + ": Second load test.");
a1.loadClass("test.bug490902.a.TestLoadA1").newInstance();
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java
index 1dbf74eec..afd38db6c 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java
@@ -569,10 +569,8 @@ public class ConnectTests extends AbstractBundleTests {
ModuleContainer.createRequirement(IdentityNamespace.IDENTITY_NAMESPACE, //
Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(tags=osgi.connect)"), //
Collections.emptyMap()));
- osgiConnectTags.forEach(c -> {
- assertTrue("Unexpected tag on bundle: " + c.getRevision().getBundle(),
- locations.contains(c.getRevision().getBundle().getLocation()));
- });
+ osgiConnectTags.forEach(c -> assertTrue("Unexpected tag on bundle: " + c.getRevision().getBundle(),
+ locations.contains(c.getRevision().getBundle().getLocation())));
}
public void testConnectContentActivatorsWithFrameworkLoaders() {
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/AllTests.java
index e3ef17db1..327d0b855 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/AllTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/AllTests.java
@@ -25,6 +25,7 @@ public class AllTests {
suite.addTest(new JUnit4TestAdapter(ModuleContainerUsageTest.class));
suite.addTest(new JUnit4TestAdapter(NamespaceListTest.class));
suite.addTest(new JUnit4TestAdapter(NamespaceListBuilderTest.class));
+ suite.addTest(new JUnit4TestAdapter(ModuleWiringTest.class));
return suite;
}
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ModuleWiringTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ModuleWiringTest.java
new file mode 100644
index 000000000..84377c5e5
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ModuleWiringTest.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2021, 2021 Hannes Wellmann 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:
+ * Hannes Wellmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osgi.tests.container;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.eclipse.osgi.container.Module;
+import org.eclipse.osgi.container.ModuleCapability;
+import org.eclipse.osgi.container.ModuleContainer;
+import org.eclipse.osgi.container.ModuleRequirement;
+import org.eclipse.osgi.container.ModuleRevision;
+import org.eclipse.osgi.container.ModuleWire;
+import org.eclipse.osgi.container.ModuleWiring;
+import org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Wire;
+
+public class ModuleWiringTest extends AbstractTest {
+
+ private ModuleWiring wiring;
+
+ @Before
+ public void setUpBefore() throws BundleException, IOException {
+ // Based on TestModuleContainer.testSimpleResolve
+ DummyContainerAdaptor adaptor = createDummyAdaptor();
+ ModuleContainer container = adaptor.getContainer();
+
+ Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
+ ModuleRevision systemRevision = systemBundle.getCurrentRevision();
+ container.resolve(Arrays.asList(systemBundle), true);
+ ModuleWiring systemWiring = systemRevision.getWiring();
+ assertNotNull("system wiring is null", systemWiring);
+
+ Module b1 = installDummyModule("b1_v1.MF", "b1", container);
+ ModuleRevision b1Revision = b1.getCurrentRevision();
+ container.resolve(Arrays.asList(b1), true);
+ wiring = b1Revision.getWiring();
+ assertNotNull("b1 wiring is null", wiring);
+ }
+
+ // --- test org.eclipse.osgi.container.ModuleWiring specific methods ---
+
+ @Test
+ public void testGetModuleCapabilities_isUnmodifiable() {
+ List<ModuleCapability> capabilities = wiring.getModuleCapabilities(null);
+ assertUnmodifiable(capabilities);
+ }
+
+ @Test
+ public void testGetModuleRequirements_isUnmodifiable() {
+ List<ModuleRequirement> requirements = wiring.getModuleRequirements(null);
+ assertUnmodifiable(requirements);
+ }
+
+ @Test
+ public void testGetProvidedModuleWires_isUnmodifiable() {
+ List<ModuleWire> wiries = wiring.getProvidedModuleWires(null);
+ assertUnmodifiable(wiries);
+ }
+
+ @Test
+ public void testGetRequiredModuleWires_isUnmodifiable() {
+ List<ModuleWire> wiries = wiring.getRequiredModuleWires(null);
+ assertUnmodifiable(wiries);
+ }
+
+ // --- test org.osgi.framework.wiring.BundleWiring specific methods ---
+
+ @Test
+ public void testGetCapabilities_isModifiable() {
+ List<BundleCapability> capabilities = wiring.getCapabilities(null);
+ assertModifiable(capabilities);
+ }
+
+ @Test
+ public void testGetRequirements_isModifiable() {
+ List<BundleRequirement> requirements = wiring.getRequirements(null);
+ assertModifiable(requirements);
+ }
+
+ @Test
+ public void testGetProvidedWires_isModifiable() {
+ List<BundleWire> wiries = wiring.getProvidedWires(null);
+ assertModifiable(wiries);
+ }
+
+ @Test
+ public void testGetRequiredWires_isModifiable() {
+ List<BundleWire> wiries = wiring.getRequiredWires(null);
+ assertModifiable(wiries);
+ }
+
+ // --- test org.osgi.resource.Wiring specific methods ---
+
+ @Test
+ public void testGetResourceCapabilities_isModifiable() {
+ List<Capability> capabilities = wiring.getResourceCapabilities(null);
+ assertModifiable(capabilities);
+ }
+
+ @Test
+ public void testGetResourceRequirements_isModifiable() {
+ List<Requirement> requirements = wiring.getResourceRequirements(null);
+ assertModifiable(requirements);
+ }
+
+ @Test
+ public void testGetProvidedResourceWires_isModifiable() {
+ List<Wire> wiries = wiring.getProvidedResourceWires(null);
+ assertModifiable(wiries);
+ }
+
+ @Test
+ public void testGetRequiredResourceWires_isModifiable() {
+ List<Wire> wiries = wiring.getRequiredResourceWires(null);
+ assertModifiable(wiries);
+ }
+
+ // --- utility methods ---
+
+ private static <T> void assertUnmodifiable(List<T> list) {
+ Assert.assertThrows(RuntimeException.class, () -> list.add(null));
+ Assert.assertThrows(RuntimeException.class, () -> list.remove(0));
+ Assert.assertThrows(RuntimeException.class, () -> list.set(0, null));
+ }
+
+ private static <T> void assertModifiable(List<T> list) {
+ List<T> copy = new ArrayList<>(list);
+ list.add(null);
+ copy.add(null);
+ assertEquals(copy, list);
+
+ list.set(0, null);
+ copy.set(0, null);
+ assertEquals(copy, list);
+
+ list.remove(0);
+ copy.remove(0);
+ assertEquals(copy, list);
+ }
+}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java
index 49afd98e5..2e4a99f62 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java
@@ -17,12 +17,22 @@ import java.util.Dictionary;
import java.util.Hashtable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.osgi.tests.OSGiTestsActivator;
import org.eclipse.osgi.tests.bundles.AbstractBundleTests;
import org.eclipse.osgi.tests.util.MapDictionary;
-import org.osgi.framework.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
public class ServiceRegistryTests extends AbstractBundleTests {
public static Test suite() {
@@ -532,6 +542,42 @@ public class ServiceRegistryTests extends AbstractBundleTests {
}
}
+ public void testWrongServiceFactoryObject() throws InterruptedException {
+ AtomicReference<String> errorMsg = new AtomicReference<>();
+ CountDownLatch gotEvent = new CountDownLatch(1);
+ FrameworkListener fwkListener = (e) -> {
+ if (e.getType() == FrameworkEvent.ERROR && e.getThrowable() != null) {
+ errorMsg.set(e.getThrowable().getMessage());
+ gotEvent.countDown();
+ }
+ };
+ ServiceRegistration<Runnable> reg = OSGiTestsActivator.getContext().registerService(Runnable.class,
+ new ServiceFactory() {
+
+ @Override
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ return "Wrong object!!";
+ }
+
+ @Override
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+ }
+
+ }, null);
+ OSGiTestsActivator.getContext().addFrameworkListener(fwkListener);
+ try {
+ ServiceReference<Runnable> ref = reg.getReference();
+ Runnable service = OSGiTestsActivator.getContext().getService(ref);
+ assertNull(service);
+ gotEvent.await(30, TimeUnit.SECONDS);
+ assertNotNull(errorMsg.get());
+ assertTrue("Wrong error message: " + errorMsg.get(), errorMsg.get().contains(String.class.getName()));
+ } finally {
+ OSGiTestsActivator.getContext().removeFrameworkListener(fwkListener);
+ reg.unregister();
+ }
+ }
+
private void clearResults(boolean[] results) {
for (int i = 0; i < results.length; i++)
results[i] = false;
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java
index 45b5fea23..16e776c9f 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java
@@ -484,7 +484,7 @@ public class BasicLocationTests extends CoreTest {
try {
final List<LogEntry> logEntries = new ArrayList<>();
LogReaderService logReaderService = getLogReaderService(equinox);
- SynchronousLogListener logListener = entry -> logEntries.add(entry);
+ SynchronousLogListener logListener = logEntries::add;
logReaderService.addLogListener(logListener);
Map<String, Location> locations = getLocations(equinox);
Location userLocation = locations.get(Location.USER_FILTER);
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
index 8bd3e5b2d..030876111 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
@@ -3820,19 +3820,8 @@ public class StateResolverTest extends AbstractStateTest {
public void testSelectionPolicy() throws BundleException {
State state = buildEmptyState();
Resolver resolver = state.getResolver();
- resolver.setSelectionPolicy(new Comparator() {
- @Override
- public int compare(Object o1, Object o2) {
- if (!(o1 instanceof BaseDescription) || !(o2 instanceof BaseDescription))
- throw new IllegalArgumentException();
- Version v1 = null;
- Version v2 = null;
- v1 = ((BaseDescription) o1).getVersion();
- v2 = ((BaseDescription) o2).getVersion();
- // only take version in to account and use lower versions over higher ones
- return v1.compareTo(v2);
- }
- });
+ // only take version into account and use lower versions over higher ones
+ resolver.setSelectionPolicy(Comparator.comparing(BaseDescription::getVersion));
Hashtable manifest = new Hashtable();
long bundleID = 0;
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java
index beaa87133..9ac4293dd 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java
@@ -30,6 +30,7 @@ public class AllTests extends TestSuite {
addTest(new TestSuite(ObjectPoolTestCase.class));
addTest(new JUnit4TestAdapter(ManifestElementTestCase.class));
addTest(new TestSuite(NLSTestCase.class));
+ addTest(new TestSuite(StorageUtilTestCase.class));
addBidiTests();
addLatinTests();
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/StorageUtilTestCase.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/StorageUtilTestCase.java
new file mode 100644
index 000000000..749138288
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/StorageUtilTestCase.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2013 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
+ *******************************************************************************/
+package org.eclipse.osgi.tests.util;
+
+import java.io.File;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.tests.harness.CoreTest;
+import org.eclipse.osgi.storage.StorageUtil;
+import org.junit.Test;
+
+public class StorageUtilTestCase extends CoreTest {
+
+ @Test
+ public void testRegularWindowsFileName() {
+ String[] validFilenames = { //
+ "something\\somethingelse", // normal file
+ "something/somethingelse", // normal file
+ "COM1anything", // normal file
+ "COM1/anything", // illegal directory name but normal file
+ ".temp", // It is acceptable to specify a period as the first character of a
+ // name. For example, ".temp".
+ "COM56", // there is no predefined NT namespace for COM56.
+ };
+ for (String validFilename : validFilenames) {
+ assertFalse(validFilename, StorageUtil.isReservedFileName(new File(validFilename)));
+ }
+ // test reserved names according to
+ // https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
+ String[] invalidFilenames = { //
+ "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
+ "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", // reserved names
+ "COM1.anything", "NUL.txt", // "Also avoid these names followed immediately by an extension; for
+ // example, NUL.txt is not recommended"
+ "COM1", "com1", "coM1"// case insensitive
+ };
+ boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32);
+ for (String invalidFilename : invalidFilenames) {
+ assertTrue(invalidFilename, isWindows == StorageUtil.isReservedFileName(new File(invalidFilename)));
+ }
+ }
+
+}

Back to the top