33a782777a106429194104a934af28159212e254
[demos/kafka/chat] /
1 package de.juplo.kafka.chat.backend.persistence.kafka.messages;
2
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.databind.SerializationFeature;
5 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
6 import org.junit.jupiter.api.BeforeEach;
7 import org.junit.jupiter.api.Test;
8
9 import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
10
11
12 public class EventChatMessageReceivedToTest
13 {
14   final String json = """
15   {
16     "id": 1,
17     "text": "Hallo, ich heiße Peter!",
18     "user": "Peter"
19   }""";
20
21   ObjectMapper mapper;
22
23   @BeforeEach
24   public void setUp()
25   {
26     mapper = new ObjectMapper();
27     mapper.registerModule(new JavaTimeModule());
28     mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
29   }
30
31   @Test
32   public void testDeserialization() throws Exception
33   {
34     EventChatMessageReceivedTo message = mapper.readValue(json, EventChatMessageReceivedTo.class);
35     assertThat(message.getId()).isEqualTo(1l);
36     assertThat(message.getText()).isEqualTo("Hallo, ich heiße Peter!");
37     assertThat(message.getUser()).isEqualTo("Peter");
38   }
39 }