CommitFailedTransformer implements Function<NSQMessage, CommitFailedEvent> { @Override public CommitFailedEvent apply(NSQMessage nsqMessage) throws Exception { CommitFailed payload = objectMapper.readValue(nsqMessage.getMessage(), CommitFailed.class); LOGGER.debug("received an new CommitFailedEvent with cid {}", payload.getHeader().getCorrelationId()); return new CommitFailedEvent( payload.getHeader().getCorrelationId(), new EntryPointKeyVsctImpl( payload.getHeader().getApplication(), payload.getHeader().getPlatform()) ); } CommitFailedTransformer(ObjectMapper objectMapper); @Override CommitFailedEvent apply(NSQMessage nsqMessage);  }
@Test public void should_transform_commit_failed_event_to_object() throws Exception { NSQMessage nsqMessage = mock(NSQMessage.class); when(nsqMessage.getMessage()).thenReturn(("" + "{" + " 'header':{" + " 'correlationId':'someCorrelationId'," + " 'application':'someApp'," + " 'platform':'somePlatform'" + " }" + "}").replaceAll("'", "\"").getBytes()); CommitFailedEvent result = commitFailedTransformer.apply(nsqMessage); assertThat(result).isNotNull(); assertThat(result.getCorrelationId()).isEqualTo("someCorrelationId"); assertThat(result.getKey().getID()).isEqualTo("someApp/somePlatform"); }