Search in sources :

Example 1 with TestEventPayload

use of org.motechproject.event.domain.TestEventPayload in project motech by motech.

the class EventBundleIT method testEventWithTypedPayloadAndMetadata.

@Test
public void testEventWithTypedPayloadAndMetadata() throws Exception {
    final ArrayList<MotechEvent> receivedEvents = new ArrayList<>();
    registry.registerListener(new EventListener() {

        @Override
        public void handle(MotechEvent event) {
            receivedEvents.add(event);
            synchronized (waitLock) {
                waitLock.notify();
            }
        }

        @Override
        public String getIdentifier() {
            return "event";
        }
    }, "event");
    Map<String, Object> params = new HashMap<>();
    params.put("foo", new TestEventPayload());
    Map<String, Object> metadata = new HashMap<>();
    metadata.put("meta", new TestEventPayload());
    metadata.put("theNumberSeven", 7);
    wait2s();
    MotechEvent testEvent = new MotechEvent("event", params);
    testEvent.setMetadata(metadata);
    eventRelay.sendEventMessage(testEvent);
    wait2s();
    assertEquals(1, receivedEvents.size());
    MotechEvent receivedEvent = receivedEvents.get(0);
    assertTrue(receivedEvent.getParameters().get("foo") instanceof TestEventPayload);
    assertEquals(2, receivedEvent.getMetadata().size());
    assertTrue(receivedEvent.getMetadata().containsKey("meta"));
    assertTrue(receivedEvent.getMetadata().containsKey("theNumberSeven"));
    assertTrue(receivedEvent.getMetadata().get("meta") instanceof TestEventPayload);
    assertEquals(7, receivedEvent.getMetadata().get("theNumberSeven"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EventListener(org.motechproject.event.listener.EventListener) MotechEvent(org.motechproject.event.MotechEvent) TestEventPayload(org.motechproject.event.domain.TestEventPayload) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 MotechEvent (org.motechproject.event.MotechEvent)1 TestEventPayload (org.motechproject.event.domain.TestEventPayload)1 EventListener (org.motechproject.event.listener.EventListener)1