Skip to main content

camel_api/
routing_slip.rs

1use crate::filter::TargetSource;
2
3#[derive(Clone)]
4pub struct RoutingSlipConfig {
5    pub expression: TargetSource,
6    pub uri_delimiter: String,
7    pub cache_size: i32,
8    pub ignore_invalid_endpoints: bool,
9}
10
11impl RoutingSlipConfig {
12    pub fn new(expression: impl Into<TargetSource>) -> Self {
13        Self {
14            expression: expression.into(),
15            uri_delimiter: ",".to_string(),
16            cache_size: 1000,
17            ignore_invalid_endpoints: false,
18        }
19    }
20
21    pub fn uri_delimiter(mut self, d: impl Into<String>) -> Self {
22        self.uri_delimiter = d.into();
23        self
24    }
25
26    pub fn cache_size(mut self, n: i32) -> Self {
27        self.cache_size = n;
28        self
29    }
30
31    pub fn ignore_invalid_endpoints(mut self, ignore: bool) -> Self {
32        self.ignore_invalid_endpoints = ignore;
33        self
34    }
35}
36
37impl std::fmt::Debug for RoutingSlipConfig {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        f.debug_struct("RoutingSlipConfig")
40            .field("uri_delimiter", &self.uri_delimiter)
41            .field("cache_size", &self.cache_size)
42            .field("ignore_invalid_endpoints", &self.ignore_invalid_endpoints)
43            .finish()
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use std::sync::Arc;
50
51    use super::*;
52
53    fn noop_expr() -> TargetSource {
54        TargetSource::Sync(Arc::new(|_| None))
55    }
56
57    #[test]
58    fn new_has_defaults() {
59        let cfg = RoutingSlipConfig::new(noop_expr());
60        assert_eq!(cfg.uri_delimiter, ",");
61        assert_eq!(cfg.cache_size, 1000);
62        assert!(!cfg.ignore_invalid_endpoints);
63    }
64
65    #[test]
66    fn builder_chaining() {
67        let cfg = RoutingSlipConfig::new(noop_expr())
68            .uri_delimiter("|")
69            .cache_size(50)
70            .ignore_invalid_endpoints(true);
71        assert_eq!(cfg.uri_delimiter, "|");
72        assert_eq!(cfg.cache_size, 50);
73        assert!(cfg.ignore_invalid_endpoints);
74    }
75
76    #[test]
77    fn clone_preserves_values() {
78        let cfg = RoutingSlipConfig::new(noop_expr()).uri_delimiter(";");
79        let cloned = cfg.clone();
80        assert_eq!(cloned.uri_delimiter, ";");
81    }
82
83    #[test]
84    fn debug_format() {
85        let cfg = RoutingSlipConfig::new(noop_expr());
86        let debug = format!("{cfg:?}");
87        assert!(debug.contains("RoutingSlipConfig"));
88        assert!(debug.contains("uri_delimiter"));
89    }
90}