This sample deals with XML message payloads when sending and receiving messages to the todo sample application. Read about this feature in reference guide
The todo-list sample application provides a REST API for managing todo entries. We call this API and receive XML message structures for validation in our test cases.
As we want to deal with XML data it is a good idea to enable schema validation for incoming messages. Just put your known schemas to the schema repository and Citrus will automatically validate incoming messages with the available schema rules.
That is all for configuration, now we can use XML as message payload in the test cases.
As you can see we are able to send the XML data as payload. You can add test variables in message payloads. In a receive action we are able to use an expected XML message payload. Citrus performs a XML tree comparison where each element is checked to meet the expected values.
The XMl message payload can be difficult to read when used as String concatenation. Fortunately we can also use file resources as message payloads.
An alternative approach would be to use Xpath expressions when validating incoming XML messages.
Each expression is evaluated and checked for expected values. XPath is namespace sensitive. So we need to use the correct namespaces in the expressions. Here we have used a namespace prefix t:. This prefix is defined in a central namespace context in the configuration.
This makes sure that the Xpath expressions are able to find the elements with correct namespaces. Of course you can also specify the namespace context for each receive action individually.
You can run the sample on your localhost in order to see Citrus in action. Read the instructions how to run the sample.