THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
- Save the input-customer1.xml file to
src/test/resources
- Save your XSLT file (created in the previous step) to
src/main/resources
- Write a Camel Route, either right in the Spring XML, or using the Java DSL (in another class under
src/test/java
somewhere). This route should use the Pipes and Filters integration pattern to:- Start from the endpoint direct:start (which lets the test conveniently pass messages into the route)
- Call the endpoint xslt:YourXSLTFile.xsl to transform the message
- Send the result to the endpoint mock:finish (which lets the test verify the route output)
- Add a test method to the unit test class that:
- Get a reference to the Mock endpoint
mock:finish
using code like this:Code Block java java MockEndpoint finish = MockEndpoint.resolve(camelContext, "mock:finish");
- Set the expectedMessageCount on that endpoint to 1
- Get a reference to the Customer 1 input file, using code like this:
Code Block java java InputStream in = XMLInputTest.class.getResourceAsStream("/input-partner1.xml"); assertNotNull(in);
- Send that InputStream as a message to the
direct:start
endpoint, using code like this:Code Block java java template.sendBody("direct:start", in);
- Ensure that the message made it through the route to the final endpoint, by testing all configured Mock endpoints like this:
Code Block java java MockEndpoint.assertIsSatisfied(camelContext);
- If you like, inspect the final message body using some code like
finish.getExchanges().get(0).getIn().getBody()
.- If you do this, you'll need to know what format that body is – String, byte array, InputStream, etc.
- Get a reference to the Mock endpoint
- Run your test with mvn install and make sure the build completes successfully.
...