RegisterServerTransformer implements Function<NSQMessage, RegisterServerEvent> { @Override public RegisterServerEvent apply(NSQMessage nsqMessage) throws Exception { RegisterServer payload = objectMapper.readValue(nsqMessage.getMessage(), RegisterServer.class); LOGGER.debug("received an new RegisterServerEvent with cid {}", payload.getHeader().getCorrelationId()); return new RegisterServerEvent(payload.getHeader().getCorrelationId(), new EntryPointKeyVsctImpl(payload.getHeader().getApplication(), payload.getHeader().getPlatform()), payload.getServer().getBackendId(), Sets.newHashSet(new IncomingEntryPointBackendServer( payload.getServer().getId(), payload.getServer().getIp(), payload.getServer().getPort(), payload.getServer().getContext() ))); } RegisterServerTransformer(ObjectMapper objectMapper); @Override RegisterServerEvent apply(NSQMessage nsqMessage);  }
@Test public void should_transform_register_server_event_to_object() throws Exception { NSQMessage nsqMessage = mock(NSQMessage.class); when(nsqMessage.getMessage()).thenReturn(("" + "{" + " 'header':{" + " 'correlationId':'someCorrelationId'," + " 'application':'someApp'," + " 'platform':'somePlatform'" + " }," + " 'server':{" + " 'id':'someId'," + " 'ip':'someIp'," + " 'port':'somePort'," + " 'backendId':'someBackendId'," + " 'context':{}" + " }" + "}").replaceAll("'", "\"").getBytes()); RegisterServerEvent result = registerServerTransformer.apply(nsqMessage); assertThat(result).isNotNull(); assertThat(result.getCorrelationId()).isEqualTo("someCorrelationId"); assertThat(result.getKey().getID()).isEqualTo("someApp/somePlatform"); assertThat(result.getBackend()).isEqualTo("someBackendId"); assertThat(result.getServers()).hasSize(1); IncomingEntryPointBackendServer server = result.getServers().iterator().next(); assertThat(server.getContext()).isEmpty(); assertThat(server.getId()).isEqualTo("someId"); assertThat(server.getIp()).isEqualTo("someIp"); assertThat(server.getPort()).isEqualTo("somePort"); }