MessageHandler { @MotechListener(subjects = EventSubjects.MESSAGE_SUBJECT) public void messageReceived(MotechEvent event) { String message = (String) event.getParameters().get(EventKeys.MESSAGE); String moduleName = (String) event.getParameters().get(EventKeys.MODULE_NAME); String levelStr = (String) event.getParameters().get(EventKeys.LEVEL); Level level = (StringUtils.isNotBlank(levelStr)) ? Level.valueOf(StringUtils.upperCase(levelStr)) : Level.INFO; DateTime timeout = (DateTime) event.getParameters().get(EventKeys.TIMEOUT); if (timeout == null) { statusMessageService.postMessage(message, moduleName, level); } else { statusMessageService.postMessage(message, moduleName, level, timeout); } }  @MotechListener(subjects = EventSubjects.MESSAGE_SUBJECT) void messageReceived(MotechEvent event);  }
@Test public void shouldPostMessageWithTimeout() { final DateTime timeout = DateTime.now(); Map<String, Object> params = new HashMap<>(); params.put(EventKeys.MESSAGE, "testMsg"); params.put(EventKeys.MODULE_NAME, "testModule"); params.put(EventKeys.LEVEL, "info"); params.put(EventKeys.TIMEOUT, timeout); MotechEvent event = new MotechEvent(EventSubjects.MESSAGE_SUBJECT, params); messageHandler.messageReceived(event); verify(statusMessageService).postMessage("testMsg", "testModule", Level.INFO, timeout); }
@Test public void shouldPostMessageWithoutTimeout() { Map<String, Object> params = new HashMap<>(); params.put(EventKeys.MESSAGE, "testMsg"); params.put(EventKeys.MODULE_NAME, "testModule"); params.put(EventKeys.LEVEL, "warn"); MotechEvent event = new MotechEvent(EventSubjects.MESSAGE_SUBJECT, params); messageHandler.messageReceived(event); verify(statusMessageService).postMessage("testMsg", "testModule", Level.WARN); }