Citrus includes a lot of convenient features which are only waiting for you to discover and use them. The other day I needed to validate a SoapAttachment.
As you probably already know, a SoapAttachment is referenced by a href property in an Include tag like this:
Validation is quite easy when you’re still mock testing your application because you have full control over what your mock response will look like.
So just add the following bean to your citrus-context.xml:
And use it in your test file like so:
Things become a little more complicated as soon as you start to connect to real backend systems for integration testing. Especially when timestamps are involved. In my case the SoapAttachment contains a calendar
invitation in vCal format which is basically a simple text based key/value format. I have to ignore the value for the key LAST-MODIFIED because it would be impossible to predict this timestamp and
it’s not really relevant either. So what I really need is a way to compare the expected structure with the actual result line by line, a possibility to completely ignore a line and a way to only ignore the value
but still compare the keys of some lines.
To solve this, the Citrus framework offers the possibility to define your own validators and include them into your test cases. Simply add a Java class which extends AbstractSoapAttachmentValidator to your test project and
implement the validateAttachmentContent method. This will be your new validator and could look somewhat like the simple example I’ll add to the end of this blog entry.
Go back to your citrus-context.xml and add your newly created validator bean:
Now you can use the validator in your test files:
So here’s the promised simple example for your lineByLineSoapAttachmentValidator: