camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Gargan <steve.gar...@gmail.com>
Subject Re: Integration testing a route before production
Date Mon, 08 Feb 2010 17:41:13 GMT
Kevin,

You are almost there, If you split your integration route into two
routes then everything should works as you expect. The first is your
route under test, the production route as it will appear in the
released code. The second is the integration route to drive it. In
this case, you will use the integration route to write your test data
to the file being monitored and then your production route will then
pick it up e.g.

<camel:route id="integration-test">
 <camel:from uri="direct:file"/>
 <camel:to uri="file:file-that-file-component-is-watching"/>
</camel:route>

your production route (decouple it from the mock with a direct endpoint)

<camel:route id="production-route">
 <camel:from ref="file-consumer"/>
 <camel:split streaming="true">
   <camel:tokenize token="\n"/>
   <camel:bean ref="Unmarshaller" method="unmarshall"/>
   <camel:bean ref="Transformer" method="transform"/>
   <camel:to uri="direct:route-out"/>
 </camel:split>
</camel:route>

Add another test route in your test context to grab the output of the
production route

<camel:route id="integration-test-result">
 <camel:from uri="direct:route-out"/>
 <camel:to uri="mock:result" />
</camel:route>

If you notice, now 'production-route' contains no test artifacts, it
appears as it would in your final product.The other test routes exist
in a test context that can import your actual production routes and
drive them any which way you need to test them. Direct endpoints are
your friend as they make it very easy to decouple routes and give you
simple known in and out points to hook into for testing.

Give this a try, shout back if you've any questions.

rgds,

ste

On Mon, Feb 8, 2010 at 12:51 AM, Claus Ibsen <claus.ibsen@gmail.com> wrote:
> On Mon, Feb 8, 2010 at 9:37 AM, Kevin Jackson <foamdino@gmail.com> wrote:
>> Hi,
>>
>> Thanks for the responses.
>>
>>> [1] http://camel.apache.org/spring-testing.html
>>
>> I have read this and it doesn't really answer my question.
>>
>> I already do integration testing using fluent dsl for :
>> direct-> processor/bean -> mock
>>
>> I have integration tests in Camel using Camel test framework for these
>> simple integrations.  The problem is that I want to test the spring
>> config and also test the memory consumption of a single route before
>> integrating the route into my main context (which is also Spring).
>>
>
> Monitoring memory usage is not a Camel specific thing. Use google to
> find solutions for that.
>
>
>> So for each part of the route I have classic JUnit tests and also
>> Camel Tests, now I want an end-to-end test :
>>
>> from fileconsumer via processing pojos to persistence
>>
>>>> Then the next thing is to feed the data into the route.
>>>> If you want to keep your file endpoint you could copy files into the
>>>> directory it listens to.
>>
>> This needs to be repeatable, so manually copying a file into a directory is out.
>>
>
> You can use Camel to create or move files for your testing as well.
>
>>>> I normally use a producer (see
>>>> http://camel.apache.org/pojo-producing.html). For this aproach you need to
>>>> start the route with a direct endpoint.
>>
>> This is the part I don't get - I have already configured the from
>> endpoint in Spring, I need to kickstart the route from within the
>> context of JUnit's TestRunner.  This works fine with direct:start
>>
>> So I can get this route to work :
>> <camel:route id="mock-integration-test">
>>  <camel:from uri="direct:start"/>
>>  <camel:bean ref="Unmarshaller" method="unmarshall"/>
>>  <camel:bean ref="Transformer" method="transform"/>
>>  <camel:to uri="mock:result"/>
>> </camel:route>
>>
>> by using:
>> @Produce(uri = "direct:start")
>> private ProducerTemplate template;
>>
>> @Test
>> @DirtiesContext
>> public void testIntegrated() throws Exception {
>>  resultEndpoint.expectedBodiesReceived(result);
>>  template.sendBody(test);
>>  resultEndpoint.assertIsSatisfied();
>> }
>>
>> but this only has a subset of test data (hardcoded in the Test class),
>>
>> So I need to be able to consume a representative sample of test data:
>> <camel:route id="integration-test">
>>  <camel:from uri="direct:file"/>
>>  <camel:to ref="file-consumer"/>
>>  <camel:split streaming="true">
>>    <camel:tokenize token="\n"/>
>>    <camel:bean ref="Unmarshaller" method="unmarshall"/>
>>    <camel:bean ref="Transformer" method="transform"/>
>>    <camel:to uri="mock:result"/>
>>  </camel:split>
>> </camel:route>
>>
>> How can I trigger this?
>>
>> Thanks,
>> Kev
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>

Mime
View raw message