Event Admin

The EventAdminTestCase uses the EventAdmin service to send/receive events.

public void testEventHandler() throws Exception
{
  TestEventHandler eventHandler = new TestEventHandler();
  
  // Register the EventHandler
  Dictionary param = new Hashtable();
  param.put(EventConstants.EVENT_TOPIC, new String[Introduction] { TOPIC });
  context.registerService(EventHandler.class.getName(), eventHandler, param);

  // Send event through the the EventAdmin
  EventAdmin eventAdmin = EventAdminSupport.provideEventAdmin(context, bundle);
  eventAdmin.sendEvent(new Event(TOPIC, null));
  
  // Verify received event
  assertEquals("Event received", 1, eventHandler.received.size());
  assertEquals(TOPIC, eventHandler.received.get(0).getTopic());
}

Event Admin support in AS7

This test uses the OSGi Repository functionality to provision the runtime with the required support functionality like this

EventAdminSupport.provideEventAdmin(context, bundle);

To enable event admin support in AS7 you would configure this capability

<capability name="org.apache.felix:org.apache.felix.eventadmin:1.2.6"/>