Search in sources :

Example 1 with EventTopic

use of org.eclipse.e4.core.di.extensions.EventTopic in project eclipse.platform.runtime by eclipse.

the class InjectionEventTest method testInjectType.

@Test
public void testInjectType() {
    IEclipseContext context = EclipseContextFactory.create();
    InjectTargetEvent target = ContextInjectionFactory.make(InjectTargetEvent.class, context);
    // initial state
    assertEquals(0, target.counter1);
    assertNull(target.event);
    // send event
    String eventTopic = "e4/test/eventInjection";
    Dictionary<String, Object> d = new Hashtable<>();
    d.put(EventConstants.EVENT_TOPIC, eventTopic);
    d.put("data1", Integer.valueOf(5));
    d.put("data2", "sample");
    Event event = new Event(eventTopic, d);
    helper.sendEvent(event);
    assertEquals(1, target.counter1);
    assertEquals(event, target.event);
    assertEquals(Integer.valueOf(5), target.event.getProperty("data1"));
    assertEquals("sample", target.event.getProperty("data2"));
}
Also used : Hashtable(java.util.Hashtable) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 2 with EventTopic

use of org.eclipse.e4.core.di.extensions.EventTopic in project eclipse.platform.runtime by eclipse.

the class InjectionEventTest method testInjectWildCard.

@Test
public void testInjectWildCard() {
    IEclipseContext context = EclipseContextFactory.create();
    InjectStarEvent target = ContextInjectionFactory.make(InjectStarEvent.class, context);
    // initial state
    assertEquals(0, target.counter1);
    assertNull(target.event);
    // send event
    String eventTopic = "e4/test/eventInjection";
    Dictionary<String, Object> d = new Hashtable<>();
    d.put(EventConstants.EVENT_TOPIC, eventTopic);
    d.put("data1", Integer.valueOf(5));
    d.put("data2", "sample");
    Event event = new Event(eventTopic, d);
    helper.sendEvent(event);
    assertEquals(1, target.counter1);
    assertEquals(event, target.event);
    assertEquals(Integer.valueOf(5), target.event.getProperty("data1"));
    assertEquals("sample", target.event.getProperty("data2"));
}
Also used : Hashtable(java.util.Hashtable) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Aggregations

Hashtable (java.util.Hashtable)2 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)2 Test (org.junit.Test)2 Event (org.osgi.service.event.Event)2