rocketmq_protocol/protocol/body/
create_topic_list_request_body.rs1use rocketmq_model::topic::TopicConfig;
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Serialize, Deserialize, Default)]
20#[serde(rename_all = "camelCase")]
21pub struct CreateTopicListRequestBody {
22 pub topic_config_list: Vec<TopicConfig>,
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn serialize_create_topic_list_request_body() {
31 let topic = TopicConfig::new("test_topic");
32 let body = CreateTopicListRequestBody {
33 topic_config_list: vec![topic],
34 };
35 let json = serde_json::to_string(&body).unwrap();
36
37 assert!(json.contains("topicConfigList"));
38 assert!(json.contains("test_topic"));
39 }
40
41 #[test]
42 fn deserialize_create_topic_list_request_body() {
43 let json = r#"
44 {
45 "topicConfigList": [
46 {
47 "topicName": "test_topic",
48 "readQueueNums": 2,
49 "writeQueueNums": 8,
50 "perm": 6,
51 "topicFilterType": "SINGLE_TAG",
52 "topicSysFlag": 0,
53 "order": false,
54 "attributes": {}
55 }
56 ]
57 }
58 "#;
59
60 let body: CreateTopicListRequestBody = serde_json::from_str(json).unwrap();
61
62 assert_eq!(body.topic_config_list.len(), 1);
63
64 let topic = &body.topic_config_list[0];
65
66 assert_eq!(topic.topic_name.as_deref(), Some("test_topic"));
67 assert_eq!(topic.read_queue_nums, 2);
68 }
69}