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"));
}
Aggregations