-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadmin.rs
250 lines (220 loc) · 8.49 KB
/
admin.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#[cfg(test)]
mod admin {
use tibco_ems::{
admin::{AdminCommands, BridgeInfo, OverflowPolicy, QueueInfo, ServerState, TopicInfo},
Destination,
};
#[test]
fn test_queue_info_default() {
let queue_info = QueueInfo::default();
// Ensure that the default values are set correctly
assert_eq!(queue_info.name, String::new());
assert_eq!(queue_info.pending_messages, None);
assert_eq!(queue_info.max_messages, None);
assert_eq!(queue_info.max_bytes, None);
assert_eq!(queue_info.overflow_policy, None);
assert_eq!(queue_info.failsafe, None);
assert_eq!(queue_info.secure, None);
assert_eq!(queue_info.global, None);
assert_eq!(queue_info.sender_name, None);
assert_eq!(queue_info.sender_name_enforced, None);
assert_eq!(queue_info.prefetch, None);
assert_eq!(queue_info.expiry_override, None);
assert_eq!(queue_info.redelivery_delay, None);
assert_eq!(queue_info.consumer_count, None);
assert_eq!(queue_info.incoming_total_count, None);
assert_eq!(queue_info.outgoing_total_count, None);
}
#[test]
fn test_topic_info_default() {
let topic_info = TopicInfo::default();
// Ensure that the default values are set correctly
assert_eq!(topic_info.name, String::new());
assert_eq!(topic_info.expiry_override, None);
assert_eq!(topic_info.global, None);
assert_eq!(topic_info.max_bytes, None);
assert_eq!(topic_info.max_messages, None);
assert_eq!(topic_info.overflow_policy, None);
assert_eq!(topic_info.prefetch, None);
assert_eq!(topic_info.durable_count, None);
assert_eq!(topic_info.subscriber_count, None);
assert_eq!(topic_info.pending_messages, None);
assert_eq!(topic_info.incoming_total_count, None);
assert_eq!(topic_info.outgoing_total_count, None);
}
#[test]
fn test_bridge_info_clone() {
let bridge_info = BridgeInfo {
source: Destination::Queue("source_queue".to_string()),
target: Destination::Topic("target_topic".to_string()),
selector: Some("some_selector".to_string()),
};
// Clone the BridgeInfo
let cloned_bridge_info = bridge_info.clone();
// Ensure that the cloned BridgeInfo is equal to the original
assert_eq!(cloned_bridge_info, bridge_info);
}
#[test]
fn test_overflow_policy_enum() {
let default_policy: OverflowPolicy = OverflowPolicy::Default;
let discard_old_policy: OverflowPolicy = OverflowPolicy::DiscardOld;
let reject_incoming_policy: OverflowPolicy = OverflowPolicy::RejectIncoming;
// Ensure that the enum variants have the correct values
assert_eq!(default_policy as i32, 0);
assert_eq!(discard_old_policy as i32, 1);
assert_eq!(reject_incoming_policy as i32, 2);
}
#[test]
fn test_admin_commands_delete_destination() {
let command = AdminCommands::DeleteDestination;
assert_eq!(command, AdminCommands::DeleteDestination);
assert_eq!(command as u8, 16);
}
#[test]
fn test_admin_commands_create_destination() {
let command = AdminCommands::CreateDestination;
assert_eq!(command, AdminCommands::CreateDestination);
assert_eq!(command as u8, 18);
}
#[test]
fn test_admin_commands_list_destination() {
let command = AdminCommands::ListDestination;
assert_eq!(command, AdminCommands::ListDestination);
assert_eq!(command as u8, 19);
}
#[test]
fn test_admin_commands_get_server_info() {
let command = AdminCommands::GetServerInfo;
assert_eq!(command, AdminCommands::GetServerInfo);
assert_eq!(command as u8, 120);
}
#[test]
fn test_admin_commands_get_state_info() {
let command = AdminCommands::GetStateInfo;
assert_eq!(command, AdminCommands::GetStateInfo);
assert_eq!(command as u8, 127);
}
#[test]
fn test_admin_commands_create_bridge() {
let command = AdminCommands::CreateBridge;
assert_eq!(command, AdminCommands::CreateBridge);
assert_eq!(command as u8, 220);
}
#[test]
fn test_admin_commands_delete_bridge() {
let command = AdminCommands::DeleteBridge;
assert_eq!(command, AdminCommands::DeleteBridge);
assert_eq!(command as u8, 221);
}
#[test]
fn test_server_state_standby() {
let state = ServerState::Standby;
assert_eq!(state, ServerState::Standby);
assert_eq!(state as u8, 3);
}
#[test]
fn test_server_state_active() {
let state = ServerState::Active;
assert_eq!(state, ServerState::Active);
assert_eq!(state as u8, 4);
}
}
#[cfg(feature = "integration-tests")]
#[cfg(test)]
mod admin_integration {
use tibco_ems::admin::{
create_bridge, create_queue, create_topic, delete_bridge, delete_queue, delete_topic,
get_server_state, list_all_queues, list_all_topics, BridgeInfo, QueueInfo, TopicInfo,
};
const USER: &str = "admin";
const PASSWORD: &str = "";
const URL: &str = "tcp://localhost:7222";
#[test]
fn test_admin_connection_success() {
let con = tibco_ems::admin::connect(URL, USER, PASSWORD);
assert!(con.is_ok());
}
#[test]
fn test_admin_connection_failure() {
let con = tibco_ems::admin::connect(URL, USER, "PASSWORD");
assert!(con.is_err());
}
#[test]
fn test_admin_list_all_queues_success() {
let con = tibco_ems::admin::connect(URL, USER, PASSWORD).unwrap();
let session = con.session().unwrap();
let queues_res = list_all_queues(&session);
assert!(queues_res.is_ok());
assert!(queues_res.unwrap().len() >= 1);
}
//FIXME: implement failures
#[test]
fn test_admin_list_all_topics_success() {
let con = tibco_ems::admin::connect(URL, USER, PASSWORD).unwrap();
let session = con.session().unwrap();
let topics_res = list_all_topics(&session);
assert!(topics_res.is_ok());
assert!(topics_res.unwrap().len() >= 1);
}
#[test]
fn test_admin_create_delete_queue_success() {
let con = tibco_ems::admin::connect(URL, USER, PASSWORD).unwrap();
let session = con.session().unwrap();
let queue = QueueInfo {
name: "create_queue".into(),
..Default::default()
};
let create_res = create_queue(&session, &queue);
assert!(create_res.is_ok());
let delete_res = delete_queue(&session, "create_queue");
assert!(delete_res.is_ok());
}
#[test]
fn test_admin_create_delete_topic_success() {
let con = tibco_ems::admin::connect(URL, USER, PASSWORD).unwrap();
let session = con.session().unwrap();
let topic = TopicInfo {
name: "create_topic".into(),
..Default::default()
};
let create_res = create_topic(&session, &topic);
assert!(create_res.is_ok());
let delete_res = delete_topic(&session, "create_topic");
assert!(delete_res.is_ok());
}
#[test]
fn test_admin_create_delete_bridge_success() {
let con = tibco_ems::admin::connect(URL, USER, PASSWORD).unwrap();
let session = con.session().unwrap();
let queue = QueueInfo {
name: "create_bridge".into(),
..Default::default()
};
let _ = create_queue(&session, &queue).unwrap();
let topic = TopicInfo {
name: "create_bridge".into(),
..Default::default()
};
let _ = create_topic(&session, &topic).unwrap();
let queue = tibco_ems::Destination::Queue("create_bridge".into());
let topic = tibco_ems::Destination::Topic("create_bridge".into());
let bridge = BridgeInfo {
source: topic,
target: queue,
selector: None,
};
let create_res = create_bridge(&session, &bridge);
assert!(create_res.is_ok());
let delete_res = delete_bridge(&session, &bridge);
assert!(delete_res.is_ok());
let _ = delete_queue(&session, "create_bridge");
let _ = delete_topic(&session, "create_bridge");
}
#[test]
fn test_admin_get_server_state_success() {
let con = tibco_ems::admin::connect(URL, USER, PASSWORD).unwrap();
let session = con.session().unwrap();
let server_state_res = get_server_state(&session);
assert!(server_state_res.is_ok());
}
}