Skip to content

Commit

Permalink
Merge pull request #34 from SoftwareDefinedVehicle/add_examples_to_um…
Browse files Browse the repository at this point in the history
…essagetype

Add convenience functions and examples to UMessageType
  • Loading branch information
Steven Hartley authored Feb 9, 2024
2 parents 7e942cb + 9c3acd9 commit 5ecde85
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 89 deletions.
24 changes: 12 additions & 12 deletions src/cloudevent/builder/ucloudeventbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl UCloudEventBuilder {
attributes,
)
.extension("sink", service_method_uri)
.ty(UMessageType::UMESSAGE_TYPE_REQUEST)
.ty(UMessageType::UMESSAGE_TYPE_REQUEST.to_type_string())
.build();

bce.unwrap()
Expand Down Expand Up @@ -161,7 +161,7 @@ impl UCloudEventBuilder {
)
.extension("sink", rpc_uri)
.extension("reqid", request_id)
.ty(UMessageType::UMESSAGE_TYPE_RESPONSE)
.ty(UMessageType::UMESSAGE_TYPE_RESPONSE.to_type_string())
.build();

bce.unwrap()
Expand Down Expand Up @@ -227,7 +227,7 @@ impl UCloudEventBuilder {
.extension("sink", rpc_uri)
.extension("reqid", request_id)
.extension("commstatus", i64::from(communication_status))
.ty(UMessageType::UMESSAGE_TYPE_RESPONSE)
.ty(UMessageType::UMESSAGE_TYPE_RESPONSE.to_type_string())
.build();

bce.unwrap()
Expand Down Expand Up @@ -274,7 +274,7 @@ impl UCloudEventBuilder {
&payload.type_url,
attributes,
)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.build();

bce.unwrap()
Expand Down Expand Up @@ -332,7 +332,7 @@ impl UCloudEventBuilder {
attributes,
)
.extension("sink", sink)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.build();

bce.unwrap()
Expand Down Expand Up @@ -464,15 +464,15 @@ mod tests {
&proto_payload.type_url,
&ucloud_event_attributes,
)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.build()
.unwrap();

assert_eq!("1.0", cloud_event.specversion().to_string());
assert_eq!("testme", cloud_event.id());
assert_eq!(source, cloud_event.source().to_string());
assert_eq!(
UMessageType::UMESSAGE_TYPE_PUBLISH.to_string(),
UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string(),
cloud_event.ty()
);
assert!(!cloud_event
Expand Down Expand Up @@ -533,15 +533,15 @@ mod tests {
&proto_payload.type_url,
&ucloud_event_attributes,
)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.build()
.unwrap();

assert_eq!("1.0", cloud_event.specversion().to_string());
assert_eq!("testme", cloud_event.id());
assert_eq!(source, cloud_event.source().to_string());
assert_eq!(
UMessageType::UMESSAGE_TYPE_PUBLISH.to_string(),
UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string(),
cloud_event.ty()
);
assert!(!cloud_event
Expand Down Expand Up @@ -608,7 +608,7 @@ mod tests {
assert!(!cloud_event.id().is_empty());
assert_eq!(source, cloud_event.source().to_string());
assert_eq!(
UMessageType::UMESSAGE_TYPE_PUBLISH.to_string(),
UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string(),
cloud_event.ty()
);
assert!(!cloud_event
Expand Down Expand Up @@ -704,7 +704,7 @@ mod tests {
.any(|(name, _value)| name.contains("sink")));
assert_eq!(sink, cloud_event.extension("sink").unwrap().to_string());
assert_eq!(
UMessageType::UMESSAGE_TYPE_PUBLISH.to_string(),
UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string(),
cloud_event.ty()
);
assert_eq!(
Expand Down Expand Up @@ -1047,7 +1047,7 @@ mod tests {
EventBuilderV10::new()
.id("hello")
.source("https://example.com")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.data_with_schema(
"application/octet-stream",
"proto://type.googleapis.com/example.demo",
Expand Down
20 changes: 10 additions & 10 deletions src/cloudevent/builder/ucloudeventutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ mod tests {

let builder = cloudevents::EventBuilderV10::new()
.id("id")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source("/body.accss//door.front_left#Door")
.data_with_schema(
UCloudEventBuilder::PROTOBUF_CONTENT_TYPE,
Expand Down Expand Up @@ -962,7 +962,7 @@ mod tests {

let builder = cloudevents::EventBuilderV10::new()
.id("someid")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source("/body.accss//door.front_left#Door")
.data_with_schema(
UCloudEventBuilder::PROTOBUF_CONTENT_TYPE,
Expand All @@ -985,7 +985,7 @@ mod tests {

let cloud_event = cloudevents::EventBuilderV10::new()
.id("someId")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
// The url crate does not accept URLs without a base
.source(Url::parse("up:/body.access/1/door.front_left#Door").unwrap())
.data_with_schema(
Expand All @@ -1008,7 +1008,7 @@ mod tests {
fn test_extract_payload_from_cloud_event_when_payload_is_bad_proto_object() {
let cloud_event = cloudevents::EventBuilderV10::new()
.id("someId")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
// The url crate does not accept URLs without a base
.source(Url::parse("up:/body.access/1/door.front_left#Door").unwrap())
.data_with_schema(
Expand Down Expand Up @@ -1036,7 +1036,7 @@ mod tests {

let cloud_event = cloudevents::EventBuilderV10::new()
.id("someId")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source(Url::parse("up:/body.access/1/door.front_left#Door").unwrap())
.data(
UCloudEventBuilder::PROTOBUF_CONTENT_TYPE,
Expand All @@ -1056,7 +1056,7 @@ mod tests {

let cloud_event = cloudevents::EventBuilderV10::new()
.id("someId")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source(Url::parse("up:/body.access/1/door.front_left#Door").unwrap())
.data_with_schema(
UCloudEventBuilder::PROTOBUF_CONTENT_TYPE,
Expand All @@ -1076,7 +1076,7 @@ mod tests {
// Creating a protobuf CloudEvent message
let source_event = cloudevents::EventBuilderV10::new()
.id("hello")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source(Url::parse("up://VCU.MY_CAR_VIN/someService").unwrap())
.ty("example.demo")
.data(
Expand All @@ -1092,7 +1092,7 @@ mod tests {
// Creating the CloudEvent
let cloud_event = EventBuilderV10::new()
.id("someId")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source(Url::parse("up:/body.access/1/door.front_left#Door").unwrap())
.data_with_schema(
UCloudEventBuilder::PROTOBUF_CONTENT_TYPE,
Expand Down Expand Up @@ -1207,7 +1207,7 @@ mod tests {
payload.type_url.as_str(),
&attributes,
);
event.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
event.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
}

fn pack_event_into_any(event: &Event) -> Any {
Expand Down Expand Up @@ -1240,7 +1240,7 @@ mod tests {
EventBuilderV10::new()
.id("hello")
.source("//VCU.MY_CAR_VIN/body.access//door.front_left#Door")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.data_with_schema(
"application/octet-stream",
"proto://type.googleapis.com/example.demo",
Expand Down
18 changes: 10 additions & 8 deletions src/cloudevent/serializer/cloudeventprotobufserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ mod tests {
&proto_payload.type_url,
&u_cloud_event_attributes,
);
cloud_event_builder = cloud_event_builder.ty(UMessageType::UMESSAGE_TYPE_PUBLISH);
cloud_event_builder =
cloud_event_builder.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string());

let cloud_event = cloud_event_builder.build().unwrap();

Expand All @@ -105,7 +106,7 @@ mod tests {
// Cloud event
let cloud_event = EventBuilderV10::new()
.id("hello")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source("/body.access/1/door.front_left".to_string())
.data_with_schema(
"application/protobuf".to_string(),
Expand All @@ -118,7 +119,7 @@ mod tests {
// Another cloud event
let another_cloud_event = EventBuilderV10::new()
.id("hello")
.ty(UMessageType::UMESSAGE_TYPE_REQUEST)
.ty(UMessageType::UMESSAGE_TYPE_REQUEST.to_type_string())
.source("/body.access/1/door.front_left".to_string())
.build()
.unwrap();
Expand All @@ -137,7 +138,7 @@ mod tests {
// Cloud event
let cloud_event = EventBuilderV10::new()
.id("hello")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source("/body.access/1/door.front_left".to_string())
.data_with_schema(
"application/protobuf".to_string(),
Expand All @@ -150,7 +151,7 @@ mod tests {
// Another cloud event
let another_cloud_event = EventBuilderV10::new()
.id("hello")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source("/body.access/1/door.front_left".to_string())
.data_with_schema(
"application/protobuf".to_string(),
Expand Down Expand Up @@ -209,7 +210,8 @@ mod tests {
&proto_payload.type_url,
&u_cloud_event_attributes,
);
cloud_event_builder = cloud_event_builder.ty(UMessageType::UMESSAGE_TYPE_PUBLISH);
cloud_event_builder =
cloud_event_builder.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string());

let cloud_event1 = cloud_event_builder.build().unwrap();
let bytes1 = serializer.serialize(&cloud_event1).unwrap();
Expand Down Expand Up @@ -369,7 +371,7 @@ mod tests {
fn build_cloud_event_for_test() -> EventBuilderV10 {
EventBuilderV10::new()
.id("hello")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.source("//VCU.VIN/body.access")
}

Expand All @@ -394,7 +396,7 @@ mod tests {
let event = EventBuilderV10::new()
.id("hello")
.source("//VCU.VIN/body.access")
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH)
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_type_string())
.data_with_schema(
UCloudEventBuilder::PROTOBUF_CONTENT_TYPE,
format!("proto://{}", Any::default().type_url),
Expand Down
Loading

0 comments on commit 5ecde85

Please sign in to comment.