Skip to content

Commit f3b146a

Browse files
committed
feat: Implement generators for XML
1 parent cb06065 commit f3b146a

File tree

4 files changed

+515
-34
lines changed

4 files changed

+515
-34
lines changed

rust/pact_matching/src/generators/bodies.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use pact_models::path_exp::DocPath;
1313
use pact_models::plugins::PluginData;
1414
#[cfg(feature = "xml")] use pact_models::xml_utils::parse_bytes;
1515

16-
#[cfg(feature = "xml")] use crate::generators::XmlHandler;
16+
#[cfg(feature = "xml")] use pact_models::generators::xml::XmlHandler;
1717

1818
#[cfg(feature = "form_urlencoded")] use pact_models::generators::form_urlencoded::FormUrlEncodedHandler;
1919

@@ -168,10 +168,10 @@ mod tests {
168168
}
169169

170170
#[tokio::test]
171-
async fn do_not_apply_generator_to_xml_body_because_unimplemented() {
171+
async fn apply_generator_to_xml_body_test() {
172172
let body = OptionalBody::Present("<a>100</a>".into(), None, None);
173173
expect!(generators_process_body(&GeneratorTestMode::Provider, &body, Some(XML.clone()),
174-
&hashmap!{}, &hashmap!{DocPath::new_unwrap("$.name") => Generator::RandomInt(0, 10)}, &DefaultVariantMatcher{}, &vec![], &hashmap!{}).await.unwrap()).to(be_equal_to(body));
174+
&hashmap!{}, &hashmap!{DocPath::new_unwrap("$.name") => Generator::RandomInt(0, 10)}, &DefaultVariantMatcher{}, &vec![], &hashmap!{}).await.unwrap()).to_not(be_equal_to(body));
175175
}
176176

177177
#[tokio::test]

rust/pact_matching/src/generators/mod.rs

-31
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,13 @@ use pact_models::v4::async_message::AsynchronousMessage;
2323
use pact_models::v4::message_parts::MessageContents;
2424
use pact_models::v4::sync_message::SynchronousMessage;
2525
use serde_json::{self, Value};
26-
#[cfg(feature = "xml")] use sxd_document::dom::Document;
2726
use tracing::{debug, error, trace};
2827

2928
use crate::{CoreMatchingContext, DiffConfig, MatchingContext};
3029
use crate::json::compare_json;
3130

3231
pub mod bodies;
3332

34-
/// Implementation of a content type handler for XML (currently unimplemented).
35-
#[cfg(feature = "xml")]
36-
pub struct XmlHandler<'a> {
37-
/// XML document to apply the generators to.
38-
pub value: Document<'a>
39-
}
40-
41-
#[cfg(feature = "xml")]
42-
impl <'a> pact_models::generators::ContentTypeHandler<Document<'a>> for XmlHandler<'a> {
43-
fn process_body(
44-
&mut self,
45-
_generators: &HashMap<DocPath, Generator>,
46-
_mode: &GeneratorTestMode,
47-
_context: &HashMap<&str, Value>,
48-
_matcher: &Box<dyn VariantMatcher + Send + Sync>
49-
) -> Result<OptionalBody, String> {
50-
error!("UNIMPLEMENTED: Generators are not currently supported with XML");
51-
Err("Generators are not supported with XML".to_string())
52-
}
53-
54-
fn apply_key(
55-
&mut self,
56-
_key: &DocPath,
57-
_generator: &dyn GenerateValue<Document<'a>>,
58-
_context: &HashMap<&str, Value>,
59-
_matcher: &Box<dyn VariantMatcher + Send + Sync>
60-
) {
61-
error!("UNIMPLEMENTED: Generators are not currently supported with XML");
62-
}
63-
}
6433

6534
/// Apply the generators to the body, returning a new body
6635
#[deprecated(note = "moved to the generators::bodies module", since = "0.12.16")]

rust/pact_models/src/generators/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::path_exp::{DocPath, PathToken};
3636
#[cfg(feature = "datetime")] mod date_expression_parser;
3737
#[cfg(feature = "datetime")] mod time_expression_parser;
3838
#[cfg(feature = "form_urlencoded")] pub mod form_urlencoded;
39+
#[cfg(feature = "xml")] pub mod xml;
3940

4041
/// Trait to represent matching logic to find a matching variant for the Array Contains generator
4142
pub trait VariantMatcher: Debug {

0 commit comments

Comments
 (0)