Exemple #1
0
  public void testReceivingASpringEvent() throws Exception {
    TestApplicationEventBean bean =
        (TestApplicationEventBean) context.getBean("testEventSpringBean");
    assertNotNull(bean);

    final Latch whenFinished = new Latch();
    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object o) throws Exception {
            assertNull(context);
            if (o instanceof TestApplicationEvent) {
              if (eventCounter1.incrementAndGet() == 1) {
                whenFinished.countDown();
              }
            }
          }
        };

    bean.setEventCallback(callback);

    context.publishEvent(new TestApplicationEvent(context));

    whenFinished.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(1, eventCounter1.get());
  }
  @Test
  public void dropsEventIfNotForCorrectDomainType() {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    context.refresh();

    SamplePersonEventListener listener = new SamplePersonEventListener();
    context.addApplicationListener(listener);

    context.publishEvent(new BeforeConvertEvent<Person>(new Person("Dave", "Matthews")));
    assertThat(listener.invokedOnBeforeConvert, is(true));

    listener.invokedOnBeforeConvert = false;
    context.publishEvent(new BeforeConvertEvent<String>("Test"));
    assertThat(listener.invokedOnBeforeConvert, is(false));
  }
Exemple #3
0
  public void testReceivingAllEvents() throws Exception {
    TestAllEventBean bean = (TestAllEventBean) context.getBean("testAllEventBean");
    assertNotNull(bean);

    Latch whenFinished = new Latch();
    bean.setEventCallback(new CountingEventCallback(eventCounter1, 2, whenFinished));

    MuleClient client = new MuleClient();
    client.send("vm://event.multicaster", "Test Spring Event", null);
    context.publishEvent(new TestApplicationEvent(context));

    whenFinished.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(2, eventCounter1.get());
  }