Skip to content

Commit 37c4a56

Browse files
committed
test: add test case for v03
Signed-off-by: Ning Sun <sunng@protonmail.com>
1 parent c659e70 commit 37c4a56

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

formats/avro/src/test/java/io/cloudevents/avro/AvroFormatTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,33 @@ public void testSerde() {
6060
assertThat(cloudEvent2.getType()).isEqualTo("testdata");
6161
}
6262

63+
@Test
64+
public void testV03Serde() {
65+
EventFormat avroFormat = new AvroFormat();
66+
CloudEventData cloudEventData = new AvroCloudEventDataWrapper(testData);
67+
68+
assertThat(cloudEventData).isNotNull();
69+
assertThat(cloudEventData.toBytes()).isNotNull();
70+
71+
CloudEvent cloudEvent = CloudEventBuilder.v03()
72+
.withId("1")
73+
.withType("testdata")
74+
.withSource(URI.create("http://localhost/test"))
75+
.withData("application/avro", cloudEventData)
76+
.build();
77+
assertThat(cloudEvent).isNotNull();
78+
assertThat(cloudEvent.getSpecVersion()).isEqualTo(SpecVersion.V03);
79+
80+
byte[] bytes = avroFormat.serialize(cloudEvent);
81+
82+
assertThat(bytes).isNotNull();
83+
assertThat(bytes).hasSizeGreaterThan(0);
84+
85+
CloudEvent cloudEvent2 = avroFormat.deserialize(bytes);
86+
87+
assertThat(cloudEvent2).isNotNull();
88+
assertThat(cloudEvent2.getId()).isEqualTo("1");
89+
assertThat(cloudEvent2.getType()).isEqualTo("testdata");
90+
}
91+
6392
}

0 commit comments

Comments
 (0)