use of au.com.dius.pact.consumer.xml.PactXmlBuilder in project pact-jvm by DiUS.
the class TodoXmlTest method projects.
// body: <?xml version="1.0" encoding="UTF-8"?>
// <projects foo="bar">
// <project id="1" name="Project 1" due="2016-02-11T09:46:56.023Z">
// <tasks>
// <task id="1" name="Do the laundry" done="true"/>
// <task id="2" name="Do the dishes" done="false"/>
// <task id="3" name="Do the backyard" done="false"/>
// <task id="4" name="Do nothing" done="false"/>
// </tasks>
// </project>
// <project/>
// </projects>
@Pact(provider = "TodoProvider", consumer = "TodoConsumer")
public RequestResponsePact projects(PactDslWithProvider builder) {
return builder.given("i have a list of projects").uponReceiving("a request for projects in XML").path("/projects").query("from=today").headers(mapOf("Accept", "application/xml")).willRespondWith().headers(mapOf("Content-Type", "application/xml")).status(200).body(new PactXmlBuilder("projects", "http://some.namespace/and/more/stuff").build(root -> {
root.setAttributes(mapOf("id", "1234"));
root.eachLike("project", 2, mapOf("id", integer(), "type", "activity", "name", string("Project 1"), "due", timestamp("yyyy-MM-dd'T'HH:mm:ss.SSSX", "2016-02-11T09:46:56.023Z")), project -> {
project.appendElement("tasks", Collections.emptyMap(), task -> {
task.eachLike("task", 5, mapOf("id", integer(), "name", string("Task 1"), "done", bool(true)));
});
});
})).toPact();
}
Aggregations