camel_component_mock/
expectations.rs1use crate::matcher::{BodyMatcher, HeaderMatcher};
4
5pub(crate) enum BodyExpectation {
11 Exact(camel_component_api::Body),
13 Matcher(BodyMatcher),
15}
16
17pub struct MockExpectations {
26 pub(crate) expected_bodies: Vec<BodyExpectation>,
27 pub(crate) expected_headers: Vec<(String, serde_json::Value)>,
28 pub(crate) expected_header_regexes: Vec<(String, String)>,
29 pub(crate) expected_header_matchers: Vec<(String, HeaderMatcher)>,
30 pub(crate) expected_count: Option<usize>,
33 pub(crate) minimum_count: Option<usize>,
36}
37
38impl Default for MockExpectations {
39 fn default() -> Self {
40 Self::new()
41 }
42}
43
44impl MockExpectations {
45 pub fn new() -> Self {
47 Self {
48 expected_bodies: Vec::new(),
49 expected_headers: Vec::new(),
50 expected_header_regexes: Vec::new(),
51 expected_header_matchers: Vec::new(),
52 expected_count: None,
53 minimum_count: None,
54 }
55 }
56
57 pub fn push_body(&mut self, body: camel_component_api::Body) {
59 self.expected_bodies.push(BodyExpectation::Exact(body));
60 }
61
62 pub fn push_body_matcher(&mut self, matcher: BodyMatcher) {
64 self.expected_bodies.push(BodyExpectation::Matcher(matcher));
65 }
66
67 pub fn push_header(&mut self, key: String, value: serde_json::Value) {
69 self.expected_headers.push((key, value));
70 }
71
72 pub fn push_header_regex(&mut self, key: String, pattern: String) {
74 self.expected_header_regexes.push((key, pattern));
75 }
76
77 pub fn push_header_matcher(&mut self, key: String, matcher: HeaderMatcher) {
79 self.expected_header_matchers.push((key, matcher));
80 }
81
82 pub(crate) fn set_expected_count(&mut self, n: usize) {
84 self.expected_count = Some(n);
85 }
86
87 pub(crate) fn set_minimum_count(&mut self, n: usize) {
89 self.minimum_count = Some(n);
90 }
91}