Skip to content

Commit

Permalink
revision + added SourceType
Browse files Browse the repository at this point in the history
  • Loading branch information
ozdoganoguzhan committed Sep 26, 2023
1 parent 7370c50 commit 7869917
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 6 deletions.
2 changes: 1 addition & 1 deletion onvif/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ xsd-macro-utils = { git = "https://github.com/lumeohq/xsd-parser-rs", rev = "7f3
xsd-types = { git = "https://github.com/lumeohq/xsd-parser-rs", rev = "7f3d433" }
yaserde = "0.7.1"
yaserde_derive = "0.7.1"
b_2 = {path = "../wsdl_rs/b_2"}

[dev-dependencies]
dotenv = "0.15.0"
futures-util = "0.3.8"
structopt = "0.3.21"
tokio = { version = "1.0.1", features = ["full"] }
tracing-subscriber = "0.2.20"
b_2 = {path = "../wsdl_rs/b_2"}
4 changes: 2 additions & 2 deletions onvif/examples/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ async fn main() {
let create_pull_sub_request = CreatePullPointSubscription {
initial_termination_time: None,
filter: Some(b_2::FilterType {
topic_expression: b_2::TopicExpressionType {
topic_expression: Some(b_2::TopicExpressionType {
dialect: "http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet".to_string(),
inner_text: "tns1:RuleEngine//.".to_string(),
},
}),
}),
subscription_policy: None,
};
Expand Down
85 changes: 85 additions & 0 deletions schema/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,88 @@ fn extension_inside_extension() {

let _ = yaserde::de::from_str::<tt::SecurityCapabilities>(ser).unwrap();
}

#[tokio::test]
async fn operation_pull_messages() {
let req: event::PullMessages = Default::default();

let transport = FakeTransport {
response: r#"
<wsnt:Message>
<tt:Message
UtcTime="2023-09-26T07:55:05Z"
PropertyOperation="Initialized">
<tt:Source>
<tt:SimpleItem
Name="VideoSourceConfigurationToken"
Value="00000"/>
<tt:SimpleItem
Name="VideoAnalyticsConfigurationToken"
Value="00000"/>
<tt:SimpleItem
Name="Rule"
Value="00000"/>
</tt:Source>
<tt:Data>
<tt:SimpleItem
Name="IsMotion"
Value="true"/>
</tt:Data>
</tt:Message>
</wsnt:Message>
"#
.into(),
};

let resp = event::pull_messages(&transport, &req).await.unwrap();

assert_eq!(
resp.notification_message[0].message.msg.source.simple_item[0].name,
"VideoSourceConfigurationToken"
);
assert_eq!(
resp.notification_message[0].message.msg.source.simple_item[0].value,
"00000"
);
assert_eq!(
resp.notification_message[0].message.msg.data.simple_item[0].name,
"IsMotion"
);
assert_eq!(
resp.notification_message[0].message.msg.data.simple_item[0].value,
"true"
);
}

#[tokio::test]
async fn operation_create_pullpoint_subscription() {
let req: event::CreatePullPointSubscription = Default::default();

let transport = FakeTransport {
response: r#"
<tev:CreatePullPointSubscriptionResponse>
<tev:SubscriptionReference>
<wsa5:Address>
http://192.168.88.108/onvif/Subscription?Idx=162
</wsa5:Address>
</tev:SubscriptionReference>
<wsnt:CurrentTime>
2023-09-26T07:55:05Z
</wsnt:CurrentTime>
<wsnt:TerminationTime>
2023-09-26T07:56:05Z
</wsnt:TerminationTime>
</tev:CreatePullPointSubscriptionResponse>
"#
.into(),
};

let resp = event::create_pull_point_subscription(&transport, &req)
.await
.unwrap();

assert_eq!(
resp.subscription_reference.address,
"http://192.168.88.108/onvif/Subscription?Idx=162"
);
}
15 changes: 12 additions & 3 deletions wsdl_rs/b_2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Validate for TopicExpressionType {}
)]
pub struct FilterType {
#[yaserde(prefix = "wsnt", rename = "TopicExpression")]
pub topic_expression: TopicExpressionType,
pub topic_expression: Option<TopicExpressionType>,
}

impl Validate for FilterType {}
Expand Down Expand Up @@ -139,7 +139,6 @@ impl Validate for NotificationMessageHolderType {}

#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")]

pub struct SimpleItemType {
// Item name.
#[yaserde(attribute, rename = "Name")]
Expand All @@ -157,12 +156,22 @@ pub mod notification_message_holder_type {
#[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")]
pub struct DataType {
#[yaserde(prefix = "tt", rename = "SimpleItem")]
pub simple_item: SimpleItemType,
pub simple_item: Vec<SimpleItemType>,
}

#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")]
pub struct SourceType {
#[yaserde(prefix = "tt", rename = "SimpleItem")]
pub simple_item: Vec<SimpleItemType>,
}

#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "tt", namespace = "tt: http://www.onvif.org/ver10/schema")]
pub struct MessageTypeInner {
#[yaserde(prefix = "tt", rename = "Source")]
pub source: SourceType,

#[yaserde(prefix = "tt", rename = "Data")]
pub data: DataType,
}
Expand Down

0 comments on commit 7869917

Please sign in to comment.