5
5
import com .fasterxml .jackson .databind .ObjectMapper ;
6
6
import io .cloudevents .CloudEvent ;
7
7
import io .cloudevents .core .builder .CloudEventBuilder ;
8
- import io .cloudevents .jackson .JsonCloudEventData ;
9
8
import lombok .AllArgsConstructor ;
10
9
import lombok .Data ;
11
10
import lombok .NoArgsConstructor ;
18
17
19
18
import java .net .URI ;
20
19
import java .time .OffsetDateTime ;
21
- import java .time . format . DateTimeFormatter ;
20
+ import java .util . Date ;
22
21
import java .util .UUID ;
23
22
24
23
import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -69,13 +68,15 @@ void shouldSerializeCloudEvent() throws JsonProcessingException {
69
68
"\" ,\" source\" :\" https://reactivecommons.org/events\" ,\" type\" :\" test\" ," +
70
69
"\" datacontenttype\" :\" application/json\" ,\" time\" :\" " + dateTime +
71
70
"\" ,\" data\" :{\" name\" :\" name\" ,\" age\" :1}}" ;
71
+ JsonCloudEvent expectedJsonNode = objectMapper .readValue (expectedJson , JsonCloudEvent .class );
72
72
// Act
73
73
Message message = converter .toMessage (testCloudEvent );
74
74
// Assert
75
75
assertEquals ("test" , message .getProperties ().getTopic ());
76
76
assertEquals (id , message .getProperties ().getKey ());
77
77
assertEquals ("application/cloudevents+json" , message .getProperties ().getContentType ());
78
- assertEquals (expectedJson , new String (message .getBody ()));
78
+ JsonCloudEvent receivedJsonNode = objectMapper .readValue (new String (message .getBody ()), JsonCloudEvent .class );
79
+ assertEquals (expectedJsonNode , receivedJsonNode );
79
80
}
80
81
81
82
@ Data
@@ -85,4 +86,15 @@ public static class MyEvent {
85
86
private String name ;
86
87
private int age ;
87
88
}
89
+
90
+ @ Data
91
+ public static class JsonCloudEvent {
92
+ private String specversion ;
93
+ private String id ;
94
+ private String source ;
95
+ private String type ;
96
+ private String datacontenttype ;
97
+ private Date time ;
98
+ private MyEvent data ;
99
+ }
88
100
}
0 commit comments