Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-07-14 16:22:51 +0000
committerThomas Watson2011-07-14 16:22:51 +0000
commit96db772ebecef5d3d5e129d97b3905ff47520f40 (patch)
treeedea501d6816b7e45dd084a7cc1b63dac190e635 /bundles/org.eclipse.osgi.tests
parentebca5861a14f56b46a0bfee8a40c3495d0c69d1c (diff)
downloadrt.equinox.framework-96db772ebecef5d3d5e129d97b3905ff47520f40.tar.gz
rt.equinox.framework-96db772ebecef5d3d5e129d97b3905ff47520f40.tar.xz
rt.equinox.framework-96db772ebecef5d3d5e129d97b3905ff47520f40.zip
Bug 350961 - [R4.4] Use new osgi.identity for singleton capabilities passed to resolver hooks
Diffstat (limited to 'bundles/org.eclipse.osgi.tests')
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/AllTests.java1
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java87
-rw-r--r--bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v1/META-INF/MANIFEST.MF4
-rw-r--r--bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v2/META-INF/MANIFEST.MF4
4 files changed, 96 insertions, 0 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/AllTests.java
index 8a9cb34a7..a0d0fc79c 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/AllTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/AllTests.java
@@ -17,6 +17,7 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTest(BasicTest.suite());
+ suite.addTest(ResolverHookTests.suite());
return suite;
}
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java
new file mode 100644
index 000000000..743da8091
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.osgi.tests.resource;
+
+import java.util.*;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.resolver.ResolverHook;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.wiring.*;
+
+public class ResolverHookTests extends AbstractResourceTest {
+
+ public static Test suite() {
+ return new TestSuite(ResolverHookTests.class);
+ }
+
+ public ResolverHookTests(String name) {
+ super(name);
+ }
+
+ public void testSingletonIdentity() throws Exception {
+ final RuntimeException error[] = {null};
+ final boolean called[] = {false};
+ ResolverHookFactory resolverHookFactory = new ResolverHookFactory() {
+ public ResolverHook begin(Collection triggers) {
+ return new ResolverHook() {
+
+ public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
+ if (error[0] != null)
+ return;
+ called[0] = true;
+ try {
+ assertEquals("Wrong namespace", ResourceConstants.IDENTITY_NAMESPACE, singleton.getNamespace());
+ assertEquals("Wrong singleton directive", "true", singleton.getDirectives().get(ResourceConstants.IDENTITY_SINGLETON_DIRECTIVE));
+ String symbolicName = (String) singleton.getAttributes().get(ResourceConstants.IDENTITY_NAMESPACE);
+ for (Iterator iCandidates = collisionCandidates.iterator(); iCandidates.hasNext();) {
+ BundleCapability candidate = (BundleCapability) iCandidates.next();
+ assertEquals("Wrong namespace", ResourceConstants.IDENTITY_NAMESPACE, candidate.getNamespace());
+ assertEquals("Wrong singleton directive", "true", candidate.getDirectives().get(ResourceConstants.IDENTITY_SINGLETON_DIRECTIVE));
+ assertEquals("Wrong symbolic name", symbolicName, (String) candidate.getAttributes().get(ResourceConstants.IDENTITY_NAMESPACE));
+ }
+ } catch (RuntimeException e) {
+ error[0] = e;
+ }
+ }
+
+ public void filterResolvable(Collection candidates) {
+ // nothing
+ }
+
+ public void filterMatches(BundleRequirement requirement, Collection candidates) {
+ // nothing
+ }
+
+ public void end() {
+ // nothing
+ }
+ };
+ }
+ };
+
+ ServiceRegistration hookReg = getContext().registerService(ResolverHookFactory.class, resolverHookFactory, null);
+
+ try {
+ Bundle tb1v1 = installer.installBundle("singleton.tb1v1");
+ Bundle tb1v2 = installer.installBundle("singleton.tb1v2");
+ assertFalse(((FrameworkWiring) getContext().getBundle(0).adapt(FrameworkWiring.class)).resolveBundles(Arrays.asList(new Bundle[] {tb1v1, tb1v2})));
+ assertTrue("ResolverHook was not called", called[0]);
+ if (error[0] != null)
+ throw error[0];
+ } finally {
+ hookReg.unregister();
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v1/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v1/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..768d2406d
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v1/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: singleton.tb1; singleton:=true
+Bundle-Version: 1.0.0
diff --git a/bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v2/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v2/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..330157e66
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/test_files/wiringTests/bundles/singleton.tb1v2/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: singleton.tb1; singleton:=true
+Bundle-Version: 2.0.0

Back to the top