Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2010-11-29 21:51:24 +0000
committerThomas Watson2010-11-29 21:51:24 +0000
commitd0bd85fa5981b74568f0061e331c7785c81cf00e (patch)
tree62a455d44f480c7ac0b9ce5f2e1e837c9d7e874a /bundles/org.eclipse.equinox.compendium.tests
parent61b3ff57e23216653a2e1ea684219ccb440b5fb1 (diff)
downloadrt.equinox.bundles-d0bd85fa5981b74568f0061e331c7785c81cf00e.tar.gz
rt.equinox.bundles-d0bd85fa5981b74568f0061e331c7785c81cf00e.tar.xz
rt.equinox.bundles-d0bd85fa5981b74568f0061e331c7785c81cf00e.zip
Bug 325064 - Handlers registered w/ topic a/b/c/* should not receive events on topic a/b/cv20101129
Diffstat (limited to 'bundles/org.eclipse.equinox.compendium.tests')
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java1
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java22
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java153
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventHandlerHelper.java32
4 files changed, 208 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java
index c7962a53a..b2aeee971 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/compendium/tests/AllTests.java
@@ -19,6 +19,7 @@ public class AllTests {
TestSuite suite = new TestSuite("Tests for Equinox Compendium"); //$NON-NLS-1$
suite.addTest(org.eclipse.equinox.metatype.tests.AllTests.suite());
suite.addTest(org.eclipse.equinox.useradmin.tests.AllTests.suite());
+ suite.addTest(org.eclipse.equinox.event.tests.AllTests.suite());
return suite;
}
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java
new file mode 100644
index 000000000..274e9813f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/AllTests.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.equinox.event.tests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Tests for Equinox EventAdmin"); //$NON-NLS-1$
+ suite.addTestSuite(EventAdminTest.class);
+ return suite;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java
new file mode 100644
index 000000000..2da46fbe5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventAdminTest.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 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.equinox.event.tests;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import junit.framework.TestCase;
+import org.eclipse.equinox.compendium.tests.Activator;
+import org.osgi.framework.*;
+import org.osgi.service.event.*;
+
+public class EventAdminTest extends TestCase {
+ private EventAdmin eventAdmin;
+ private ServiceReference eventAdminReference;
+
+ protected void setUp() throws Exception {
+ Activator.getBundle(Activator.BUNDLE_EVENT).start();
+ eventAdminReference = Activator.getBundleContext().getServiceReference(EventAdmin.class.getName());
+ eventAdmin = (EventAdmin) Activator.getBundleContext().getService(eventAdminReference);
+ }
+
+ protected void tearDown() throws Exception {
+ Activator.getBundleContext().ungetService(eventAdminReference);
+ Activator.getBundle(Activator.BUNDLE_EVENT).stop();
+ }
+
+ /*
+ * Ensures EventAdmin does not deliver an event published on topic "a/b/c"
+ * to an EventHandler listening to topic a/b/c/*.
+ *
+ * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=325064.
+ */
+ public void testEventDeliveryForWildcardTopic1() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$
+ BundleContext bundleContext = Activator.getBundleContext();
+ EventHandlerHelper handler = new EventHandlerHelper();
+ ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties);
+ Event event = new Event("a/b/c", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNull("Received event published to topic 'a/b/c' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$
+ handlerRegistration.unregister();
+ }
+
+ /*
+ * Ensures EventAdmin does not deliver an event published on topic "a/b" to
+ * an EventHandler listening to topic a/b/c/*.
+ */
+ public void testEventDeliveryForWildcardTopic2() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$
+ BundleContext bundleContext = Activator.getBundleContext();
+ EventHandlerHelper handler = new EventHandlerHelper();
+ ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties);
+ Event event = new Event("a/b", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNull("Received event published to topic 'a/b' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$
+ handlerRegistration.unregister();
+ }
+
+ /*
+ * Ensures EventAdmin does not deliver an event published on topic "a" to
+ * an EventHandler listening to topic a/b/c/*.
+ */
+ public void testEventDeliveryForWildcardTopic3() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$
+ BundleContext bundleContext = Activator.getBundleContext();
+ EventHandlerHelper handler = new EventHandlerHelper();
+ ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties);
+ Event event = new Event("a", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNull("Received event published to topic 'a' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$
+ handlerRegistration.unregister();
+ }
+
+ /*
+ * Ensures EventAdmin delivers an event published on topic "a/b/c/d" to an
+ * EventHandler listening to topic "a/b/c/*".
+ */
+ public void testEventDeliveryForWildcardTopic4() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$
+ BundleContext bundleContext = Activator.getBundleContext();
+ EventHandlerHelper handler = new EventHandlerHelper();
+ ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties);
+ Event event = new Event("a/b/c/d", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNotNull("Did not receive event published to topic 'a/b/c/d' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$
+ handlerRegistration.unregister();
+ }
+
+ /*
+ * Ensures EventAdmin delivers an event published on topic "a/b/c/d/e" to
+ * an EventHandler listening to topic "a/b/c/*".
+ */
+ public void testEventDeliveryForWildcardTopic5() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$
+ BundleContext bundleContext = Activator.getBundleContext();
+ EventHandlerHelper handler = new EventHandlerHelper();
+ ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties);
+ Event event = new Event("a/b/c/d/e", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNotNull("Did not receive event published to topic 'a/b/c/d/e' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$
+ handlerRegistration.unregister();
+ }
+
+ /*
+ * Ensures EventAdmin delivers an event published on topic "a/b/c/d/e/f" to
+ * an EventHandler listening to topic "a/b/c/*".
+ */
+ public void testEventDeliveryForWildcardTopic6() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*"); //$NON-NLS-1$
+ BundleContext bundleContext = Activator.getBundleContext();
+ EventHandlerHelper handler = new EventHandlerHelper();
+ ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties);
+ Event event = new Event("a/b/c/d/e/f", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNotNull("Did not receive event published to topic 'a/b/c/d/e/f' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$
+ handlerRegistration.unregister();
+ }
+
+ /*
+ * Ensures EventAdmin delivers an event published to topics "a/b/c" and
+ * "a/b/c/d" to an EventHandler listening to topics "a/b/c" and "a/b/c/*".
+ *
+ * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=325064.
+ */
+ public void testEventDeliveryForWildcardTopic7() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, new String[] {"a/b/c", "a/b/c/*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ BundleContext bundleContext = Activator.getBundleContext();
+ EventHandlerHelper handler = new EventHandlerHelper();
+ ServiceRegistration handlerRegistration = bundleContext.registerService(EventHandler.class, handler, properties);
+ Event event = new Event("a/b/c", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNotNull("Did not receive event published to topic 'a/b/c' while listening to 'a/b/c'", handler.clearLastEvent()); //$NON-NLS-1$
+ event = new Event("a/b/c/d", (Dictionary) null); //$NON-NLS-1$
+ eventAdmin.sendEvent(event);
+ assertNotNull("Did not receive event published to topic 'a/b/c/d' while listening to 'a/b/c/*'", handler.lastEvent()); //$NON-NLS-1$
+ handlerRegistration.unregister();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventHandlerHelper.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventHandlerHelper.java
new file mode 100644
index 000000000..e9b4e0862
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/event/tests/EventHandlerHelper.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.equinox.event.tests;
+
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+public class EventHandlerHelper implements EventHandler {
+ private volatile Event lastEvent;
+
+ public Event clearLastEvent() {
+ Event result = lastEvent;
+ lastEvent = null;
+ return result;
+ }
+
+ public void handleEvent(Event event) {
+ lastEvent = event;
+ }
+
+ public Event lastEvent() {
+ return lastEvent;
+ }
+}

Back to the top