Skip to main content

rocketmq_protocol/protocol/body/
create_topic_list_request_body.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use 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}