@Test
public void shouldSerializeMessageCorrectly() throws Exception {
final MessageToJsonSerializer serializer = new MessageToJsonSerializer(objectMapper, streamService, inputService);
final DateTime now = Tools.iso8601();
final Message message = new Message("test", "localhost", now);
message.setSourceInput(messageInput);
message.setStreams(Lists.newArrayList(stream));
message.addField("test1", "hello");
message.addField("test2", 1);
message.addField("test3", 1.2);
message.addField("test4", false);
final String s = serializer.serializeToString(message);
final Message newMessage = serializer.deserialize(s);
assertEquals(newMessage.getField("timestamp"), now);
assertEquals(newMessage.getMessage(), message.getMessage());
assertEquals(newMessage.getSource(), message.getSource());
assertEquals(newMessage.getSourceInput(), messageInput);
assertEquals(newMessage.getStreams(), Lists.newArrayList(stream));
assertEquals(newMessage.getField("test1"), "hello");
assertEquals(newMessage.getField("test2"), 1);
assertEquals(newMessage.getField("test3"), 1.2);
assertEquals(newMessage.getField("test4"), false);
// Just assert that the message id is not null because we cannot set the _id field on deserialize because the
// Message object does not allow the _id field to be set.
assertNotNull(newMessage.getId());
// Make sure the injected ObjectMapper instance is copied before adding custom config.
verify(objectMapper, times(1)).copy();
}