Camel Mock test using file as input -


i want create mock test camel route uses input file:

<route id="myroute">     <from uri="file:/var/file.log&amp;noop=true" />      . . . </route> 

so far have been able include "direct:start" element @ beginning of route , include manually file body::

 context.createproducertemplate().sendbody("direct:start", "data1-data2-data3"); 

i guess there must better way doing it, without changing original spring xml file. ?

you can either use property in from-statement , replace property in test, or can use camel-test's weaving support modify route test.

here's example of latter:

import org.apache.camel.endpoint; import org.apache.camel.endpointinject; import org.apache.camel.builder.advicewithroutebuilder; import org.apache.camel.builder.routebuilder; import org.apache.camel.component.mock.mockendpoint; import org.apache.camel.test.junit4.cameltestsupport; import org.apache.commons.io.fileutils; import org.junit.test;  import java.io.file;  public class footest extends cameltestsupport {      private static final string uri_start_endpoint = "direct:teststart";     private static final string my_route_id = "my_route";     private static final string uri_end = "mock:end";      @endpointinject(uri = uri_start_endpoint)     private endpoint start;      @endpointinject(uri = uri_end)     private mockendpoint unmarhsalresult;      @override     public boolean isuseadvicewith() {         return true;     }      @override     protected routebuilder createroutebuilder() throws exception {         // return new myroutebuilder();         return new routebuilder() {             @override             public void configure() throws exception {                 from("file:/var/file.log&noop=true").routeid(my_route_id)                     .log("content: ${body}");             }         };     }      @override     protected void dopostsetup() throws exception {         context.getroutedefinition(my_route_id).advicewith(context, new advicewithroutebuilder() {             @override             public void configure() throws exception {                 replacefromwith(uri_start_endpoint);                 weaveaddlast().to(uri_end);             }         });         context.start();     }      @test     public void testunmarshal() throws exception {         unmarhsalresult.expectedmessagecount(1);         template.sendbody(uri_start_endpoint, fileutils.readfiletostring(new file("src/test/resources/my_test_file.txt")));          unmarhsalresult.assertissatisfied();     }  } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -