|
17 | 17 | package io.cloudevents.avro;
|
18 | 18 |
|
19 | 19 | import java.util.Map;
|
| 20 | +import java.util.HashMap; |
20 | 21 | import java.net.URI;
|
21 | 22 |
|
22 | 23 | import io.cloudevents.CloudEvent;
|
|
29 | 30 |
|
30 | 31 | public class AvroFormatTest {
|
31 | 32 |
|
32 |
| - Map<String, Object> testData = Map.of("name", "Ning", "age", 22.0); |
| 33 | + public static Map<String, Object> testData = new HashMap<>(); |
| 34 | + |
| 35 | + static { |
| 36 | + testData.put("name", "Ning"); |
| 37 | + testData.put("age", 22.0); |
| 38 | + } |
33 | 39 |
|
34 | 40 | @Test
|
35 | 41 | public void testSerde() {
|
@@ -60,4 +66,33 @@ public void testSerde() {
|
60 | 66 | assertThat(cloudEvent2.getType()).isEqualTo("testdata");
|
61 | 67 | }
|
62 | 68 |
|
| 69 | + @Test |
| 70 | + public void testV03Serde() { |
| 71 | + EventFormat avroFormat = new AvroFormat(); |
| 72 | + CloudEventData cloudEventData = new AvroCloudEventDataWrapper(testData); |
| 73 | + |
| 74 | + assertThat(cloudEventData).isNotNull(); |
| 75 | + assertThat(cloudEventData.toBytes()).isNotNull(); |
| 76 | + |
| 77 | + CloudEvent cloudEvent = CloudEventBuilder.v03() |
| 78 | + .withId("1") |
| 79 | + .withType("testdata") |
| 80 | + .withSource(URI.create("http://localhost/test")) |
| 81 | + .withData("application/avro", cloudEventData) |
| 82 | + .build(); |
| 83 | + assertThat(cloudEvent).isNotNull(); |
| 84 | + assertThat(cloudEvent.getSpecVersion()).isEqualTo(SpecVersion.V03); |
| 85 | + |
| 86 | + byte[] bytes = avroFormat.serialize(cloudEvent); |
| 87 | + |
| 88 | + assertThat(bytes).isNotNull(); |
| 89 | + assertThat(bytes).hasSizeGreaterThan(0); |
| 90 | + |
| 91 | + CloudEvent cloudEvent2 = avroFormat.deserialize(bytes); |
| 92 | + |
| 93 | + assertThat(cloudEvent2).isNotNull(); |
| 94 | + assertThat(cloudEvent2.getId()).isEqualTo("1"); |
| 95 | + assertThat(cloudEvent2.getType()).isEqualTo("testdata"); |
| 96 | + } |
| 97 | + |
63 | 98 | }
|
0 commit comments