rocketmq_remoting/protocol/header/
notification_response_header.rs1use rocketmq_macros::RequestHeaderCodecV2;
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodecV2)]
20#[serde(rename_all = "camelCase")]
21pub struct NotificationResponseHeader {
22 #[required]
23 pub has_msg: bool,
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn test_notification_response_header_initialization_true() {
32 let header = NotificationResponseHeader { has_msg: true };
33 assert!(header.has_msg);
34 }
35
36 #[test]
37 fn test_notification_response_header_initialization_false() {
38 let header = NotificationResponseHeader { has_msg: false };
39 assert!(!header.has_msg);
40 }
41
42 #[test]
43 fn test_notification_response_header_serialize_true() {
44 let header = NotificationResponseHeader { has_msg: true };
45 let serialized = serde_json::to_string(&header).unwrap();
46 assert_eq!(serialized, r#"{"hasMsg":true}"#);
47 }
48
49 #[test]
50 fn test_notification_response_header_serialize_false() {
51 let header = NotificationResponseHeader { has_msg: false };
52 let serialized = serde_json::to_string(&header).unwrap();
53 assert_eq!(serialized, r#"{"hasMsg":false}"#);
54 }
55
56 #[test]
57 fn test_notification_response_header_deserialize_true() {
58 let json = r#"{"hasMsg":true}"#;
59 let header: NotificationResponseHeader = serde_json::from_str(json).unwrap();
60 assert!(header.has_msg);
61 }
62
63 #[test]
64 fn test_notification_response_header_deserialize_false() {
65 let json = r#"{"hasMsg":false}"#;
66 let header: NotificationResponseHeader = serde_json::from_str(json).unwrap();
67 assert!(!header.has_msg);
68 }
69
70 #[test]
71 fn test_notification_response_header_roundtrip_true() {
72 let original = NotificationResponseHeader { has_msg: true };
73 let serialized = serde_json::to_string(&original).unwrap();
74 let deserialized: NotificationResponseHeader = serde_json::from_str(&serialized).unwrap();
75 assert_eq!(original.has_msg, deserialized.has_msg);
76 }
77
78 #[test]
79 fn test_notification_response_header_roundtrip_false() {
80 let original = NotificationResponseHeader { has_msg: false };
81 let serialized = serde_json::to_string(&original).unwrap();
82 let deserialized: NotificationResponseHeader = serde_json::from_str(&serialized).unwrap();
83 assert_eq!(original.has_msg, deserialized.has_msg);
84 }
85
86 #[test]
87 fn test_notification_response_header_field_accessibility() {
88 let mut header = NotificationResponseHeader { has_msg: false };
89 assert!(!header.has_msg);
90 header.has_msg = true;
91 assert!(header.has_msg);
92 }
93
94 #[test]
95 fn test_notification_response_header_default() {
96 let header = NotificationResponseHeader::default();
97 assert!(!header.has_msg);
98 }
99
100 #[test]
101 fn test_notification_response_header_clone() {
102 let original = NotificationResponseHeader { has_msg: true };
103 let cloned = original.clone();
104 assert_eq!(original.has_msg, cloned.has_msg);
105 assert!(cloned.has_msg);
106 }
107
108 #[test]
109 fn test_notification_response_header_debug() {
110 let header = NotificationResponseHeader { has_msg: true };
111 let debug_str = format!("{:?}", header);
112 assert_eq!(debug_str, "NotificationResponseHeader { has_msg: true }");
113 }
114
115 #[test]
116 fn test_notification_response_header_debug_false() {
117 let header = NotificationResponseHeader { has_msg: false };
118 let debug_str = format!("{:?}", header);
119 assert_eq!(debug_str, "NotificationResponseHeader { has_msg: false }");
120 }
121
122 #[test]
123 fn test_notification_response_header_camel_case_serialization() {
124 let header = NotificationResponseHeader { has_msg: true };
125 let serialized = serde_json::to_string(&header).unwrap();
126 assert!(serialized.contains("hasMsg"));
128 assert!(!serialized.contains("has_msg"));
129 }
130
131 #[test]
132 fn test_notification_response_header_camel_case_deserialization() {
133 let json_camel = r#"{"hasMsg":true}"#;
135 let header: NotificationResponseHeader = serde_json::from_str(json_camel).unwrap();
136 assert!(header.has_msg);
137 }
138}