I'm new to Camel (and relatively new to Spring). I've got a route with a bean up and running but I want to perform some unit testing. I'm trying to figure out how to "feed" my test with XML that is contained in a file.
My working app has a bean with a method to load XML into the header parameters and a method to create SQL from the header parameters: This route works for me in my application: <camel:route> <camel:from uri="file:/archive/inbox/> <camel:bean ref="myEventBean" method="fromXML"/> <camel:bean ref="myEventBean" method="toJdbc"/> <camel:to uri="jdbc:dataSource"/> </camel:route> I'm trying to create an XML file that I can tweak to make sure that the bean's methods hold up regardless of the XML passed (it comes from JMS queues and files and there is a lot of error checking to make sure the resulting jdbc query is valid). Seems like it should be easy enough. Here is my test to read the file and see the query produced. The first one (testMocksAreValid) works. I'm trying to figure out the second Test which causes the Exception: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: file://src/test/resources/inbox/?noop=true] ...8<... Caused by: org.apache.camel.builder.xml.InvalidXPathExtression: Invalid xpth: //event/@topic. Reason: javax.xml.xpath.XPathExpressionException *Note, because this exact XML file works in my application, I'm assuming the problem is with the way I am consuming it... ------------- public class myEventBeanTest extends org.apache.camel.test.junit4.CamelSpringTestSupport{ @EndpointInject(uri="mock:result") protected MockEndpoint resultEndpoint; @Produce(uri="direct:start") protected ProducerTemplate template @Autowired protected CamelContext camelContext; @Test public void testMocksAreValid() throws Exception{ MockEndPoint.assertIsSatisfied(camelContext); } public void setUp() throws Exception{ super.setUp(); } protected AbstractXmlApplicationContext createApplicationContext(){ return new ClasspathXmlApplicationContext("myEventBeanTest-context.xml"}; } @Override protected RouteBuilder createRouteBuilder() throws Exception{ return new RouteBuilder(){ @Override public void configure() throws Exception{ from("direct:start").beanRef("myEventBean","fromXML").beanRef("myEventBean","toJdbc").to("stream:out"); } @Test public void secondTest() throws Exception{ Thread.sleep(3000); template.sendBody("file://src/test/resources/inbox/?noop=true"); <------???? } ------------------------ fyi, I am injecting the route because I want to use the same context file/content that my live application has. I'm sure this is based upon some fundamental misunderstanding, but I'm stuck. I think I can see that I need to read the xml file into body. I've trying moving the file endpoint up into the route, but then am not sure how to kick the whole thing off. Which leads me to my questions (whew): 1) What magic do i need to work to feed the XML file? 2) My noop option on the File component isn't working - the file gets deleted each time I run the test - anybody know why? 3) I have read the api/javadocs on sendBody, sendBodyAndHeader, etc, but I'm having a hard time finding good explanations of what they do and how to use them (I have Camel in Action, which has been a big help except for this). Can someone point me to a more thorough explanation/tutorial of using the producer template?...better than http://camel.apache.org/producertemplate.html :) Thanks for any insight! -J -- View this message in context: http://camel.465427.n5.nabble.com/noob-spring-testing-question-tp4668163p4668163.html Sent from the Camel - Users mailing list archive at Nabble.com.