CommitRequestedSubscriber implements Consumer<CommitRequestedEvent> { @Override public void accept(CommitRequestedEvent commitRequestedEvent) { EntryPoint configuration = commitRequestedEvent.getConfiguration(); Map<String, String> context = configuration.getContext(); Optional.ofNullable(context.get("application")).ifPresent(application -> Optional.ofNullable(context.get("platform")).ifPresent(platform -> { try { nsqDispatcher.sendCommitRequested(commitRequestedEvent, configuration.getHaproxy(), application, platform, commitRequestedEvent.getBind()); } catch (Exception e) { LOGGER.error("Unable to send commit requested event {} to NSQ because of the following errors", commitRequestedEvent, e); } })); } CommitRequestedSubscriber(NSQDispatcher nsqDispatcher); @Override void accept(CommitRequestedEvent commitRequestedEvent);  }
@Test public void should_send_event_to_dispatcher() throws Exception { commitRequestedSubscriber.accept(commitRequestedEvent); verify(nsqDispatcher).sendCommitRequested(commitRequestedEvent, "hap", "app", "ptf", "bind"); }
@Test public void should_handle_exceptions_from_dispatcher() throws Exception { doThrow(new RuntimeException()).when(nsqDispatcher).sendCommitRequested(commitRequestedEvent, "hap", "app", "ptf", "bind"); commitRequestedSubscriber.accept(commitRequestedEvent); }
@Test public void should_not_send_event_to_dispatcher_when_application_is_null() throws Exception { context.put("application", null); doThrow(new RuntimeException()).when(nsqDispatcher).sendCommitRequested(commitRequestedEvent, "hap", "app", "ptf", "bind"); commitRequestedSubscriber.accept(commitRequestedEvent); verify(nsqDispatcher, never()).sendCommitRequested(any(), anyString(), anyString(), anyString(), anyString()); }
@Test public void should_not_send_event_to_dispatcher_when_platform_is_null() throws Exception { context.put("platform", null); doThrow(new RuntimeException()).when(nsqDispatcher).sendCommitRequested(commitRequestedEvent, "hap", "app", "ptf", "bind"); commitRequestedSubscriber.accept(commitRequestedEvent); verify(nsqDispatcher, never()).sendCommitRequested(any(), anyString(), anyString(), anyString(), anyString()); }