Search in sources :

Example 1 with TestEvent

use of org.xwiki.observation.remote.test.TestEvent in project xwiki-platform by xwiki.

the class TCPROMTest method testSerializableEvent.

/**
 * Validate sharing a simple Serializable event between two instances of {@link RemoteObservationManager}.
 */
@Test
public void testSerializableEvent() throws InterruptedException {
    final EventListener localListener = this.mockery.mock(EventListener.class, "local");
    final EventListener remoteListener = this.mockery.mock(EventListener.class, "remote");
    final TestEvent event = new TestEvent();
    final Unserializable unserializable = new Unserializable();
    this.mockery.checking(new Expectations() {

        {
            allowing(localListener).getName();
            will(returnValue("mylistener"));
            allowing(remoteListener).getName();
            will(returnValue("mylistener"));
            allowing(localListener).getEvents();
            will(returnValue(Arrays.asList(event)));
            allowing(remoteListener).getEvents();
            will(returnValue(Arrays.asList(event)));
            oneOf(localListener).onEvent(with(same(event)), with(equal("some source")), with(equal("some data")));
            oneOf(localListener).onEvent(with(same(event)), with(same(unserializable)), with(same(unserializable)));
            oneOf(remoteListener).onEvent(with(equal(event)), with(equal("some source")), with(equal("some data")));
        }
    });
    getObservationManager1().addListener(localListener);
    getObservationManager2().addListener(remoteListener);
    getObservationManager1().notify(event, "some source", "some data");
    getObservationManager1().notify(event, unserializable, unserializable);
    getObservationManager1().notify(new LogEvent(), "some source", "some data");
    // Make sure JGroups has enough time to send the message
    Thread.sleep(1000);
}
Also used : Expectations(org.jmock.Expectations) TestEvent(org.xwiki.observation.remote.test.TestEvent) LogEvent(org.xwiki.logging.event.LogEvent) EventListener(org.xwiki.observation.EventListener) Test(org.junit.Test)

Aggregations

Expectations (org.jmock.Expectations)1 Test (org.junit.Test)1 LogEvent (org.xwiki.logging.event.LogEvent)1 EventListener (org.xwiki.observation.EventListener)1 TestEvent (org.xwiki.observation.remote.test.TestEvent)1