THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring-1.4.0.xsd"> <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <!-- TODO --> </camelContext> </beans> |
Now the meaty part is to flesh out the test class and write the Camel routes.
- Write the routes (with in XML or the Java DSL) for the CSV conversion process
- Once again, start from the endpoint direct:start (which lets the test conveniently pass messages into the route)
- This time, there's a little preparation to be done. Camel doesn't know that the initial input is a CSV, so it won't be able to convert it to the expected
List<List<String>>
without a little hint. For that, we need an unmarshal transformation in the route. Theunmarshal
method (in the DSL) or element (in the XML) takes a child indicating the format to unmarshal; in this case that should becsv
. - Next invoke the POJO to transform the message with a bean:CSVConverter endpoint
- As before, send the result to the endpoint mock:finish (which lets the test verify the route output)
- Finally, we need a Spring
<bean>
element outside the<camelContext>
to declare the Spring bean that our route should invoke. This Spring bean should have aname
attribute that matches the name used in thebean
endpoint, and aclass
attribute that points to the CSV-to-JAXB POJO class you wrote above.
- Write a test method in the test class, which should look very similar to the XML test
- Get the MockEndpoint for the final endpoint, and tell it to expect one message
- Load the Partner 2 sample CSV file from the ClassPath, and send it as the body of a message to the starting endpoint
- Verify that the final MockEndpoint is satisfied (that is, it received one message) and examine the message body if you like
- Note that we didn't marshal the JAXB POJOs to XML in this test, so the final message should contain an
Invoice
as the body.
- Note that we didn't marshal the JAXB POJOs to XML in this test, so the final message should contain an
- Run this new test with mvn install and make sure it passes and the build completes successfully.
Solution: Your finished test might look something like this:
- src/test/java/org/apache/camel/tutorial/CSVInputTest.java
- For XML Configuration:
- src/test/resources/CSVInputTest-context.xml
- Or, for Java DSL Configuration:
- src/test/resources/CSVInputTest-dsl-context.xml
- src/test/java/org/apache/camel/tutorial/routes/CSVInputTestRoute.java
Step 6: Initial Work on Customer 3 Input (Excel over e-mail)
...