-
Notifications
You must be signed in to change notification settings - Fork 163
Avro format implementation #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
6575ac5
662032e
0b64945
b0f17b8
371d31e
30ca8ad
8d8a668
8505d78
c659e70
3af281b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Ning Sun <sunng@protonmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2018-Present The CloudEvents Authors | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package io.cloudevents.avro; | ||
|
||
import java.util.Map; | ||
import java.net.URI; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.CloudEventData; | ||
import io.cloudevents.SpecVersion; | ||
import io.cloudevents.core.builder.CloudEventBuilder; | ||
import io.cloudevents.core.format.EventFormat; | ||
import org.junit.jupiter.api.Test; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AvroFormatTest { | ||
|
||
Map<String, Object> testData = Map.of("name", "Ning", "age", 22.0); | ||
|
||
@Test | ||
public void testSerde() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add more test cases?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I will do it in next few commits. |
||
EventFormat avroFormat = new AvroFormat(); | ||
CloudEventData cloudEventData = new AvroCloudEventDataWrapper(testData); | ||
|
||
assertThat(cloudEventData).isNotNull(); | ||
assertThat(cloudEventData.toBytes()).isNotNull(); | ||
|
||
CloudEvent cloudEvent = CloudEventBuilder.v1() | ||
.withId("1") | ||
.withType("testdata") | ||
.withSource(URI.create("http://localhost/test")) | ||
.withData("application/avro", cloudEventData) | ||
.build(); | ||
assertThat(cloudEvent).isNotNull(); | ||
assertThat(cloudEvent.getSpecVersion()).isEqualTo(SpecVersion.V1); | ||
|
||
byte[] bytes = avroFormat.serialize(cloudEvent); | ||
|
||
assertThat(bytes).isNotNull(); | ||
assertThat(bytes).hasSizeGreaterThan(0); | ||
|
||
CloudEvent cloudEvent2 = avroFormat.deserialize(bytes); | ||
|
||
assertThat(cloudEvent2).isNotNull(); | ||
assertThat(cloudEvent2.getId()).isEqualTo("1"); | ||
assertThat(cloudEvent2.getType()).isEqualTo("testdata"); | ||
} | ||
|
||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.