On Wed, Jul 15, 2009 at 12:15 PM, Charles Moulliard<[email protected]> wrote:
> Thx.
>
> It works with this :
>
> try {
> template1.sendBody(record1);
> } catch (CamelExecutionException e) {
>
You actually need to do it like this
try {
template1.sendBody(record1);
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
}
then you detect if an exception was NOT thrown
And you assert that the exception you forced thrown in your unit test
is wrapped in the exception.
>
>
> Charles Moulliard
> Senior Enterprise Architect
> Apache Camel Committer
>
> *****************************
> blog : http://cmoulliard.blogspot.com
>
>
> On Wed, Jul 15, 2009 at 11:31 AM, Claus Ibsen <[email protected]> wrote:
>
>> Some exceptions are wrapped in Camel so catch the wrapper and look for
>> your caused exception.
>>
>>
>> On Wed, Jul 15, 2009 at 11:25 AM, Charles Moulliard<[email protected]>
>> wrote:
>> > Hi,
>> >
>> > I try to create a test like this where I check if a specific exception
>> type
>> > is generated but it does not work.
>> >
>> > Is the code correct :
>> >
>> > @ContextConfiguration(locations =
>> >
>> "org.apache.camel.dataformat.bindy.csv.BindySimpleCsvMandatoryFieldsUnmarshallTest$ContextConfig",
>> > loader = JavaConfigContextLoader.class)
>> > public class BindySimpleCsvMandatoryFieldsUnmarshallTest extends
>> > AbstractJUnit4SpringContextTests {
>> >
>> > String header = "order nr,client ref,first name, last name,instrument
>> > code,instrument name,order type, instrument type,
>> > quantity,currency,date\r\n";
>> > String record1 = ",,,,,,,,,";
>> > String record2 = ",,blabla,,,,,,";
>> >
>> > �...@endpointinject(uri = "mock:result")
>> > protected MockEndpoint resultEndpoint;
>> >
>> > �...@produce(uri = "direct:start")
>> > protected ProducerTemplate template;
>> >
>> > �...@dirtiescontext
>> > �...@test
>> > public void testEmptyFields() throws Exception {
>> > resultEndpoint.expectedMessageCount(0);
>> >
>> > try {
>> > template.sendBody(header + record1);
>> > } catch (IllegalArgumentException e) {
>> > // expected
>> > }
>> > resultEndpoint.assertIsSatisfied();
>> > }
>> >
>> > �...@configuration
>> > public static class ContextConfig extends
>> SingleRouteCamelConfiguration
>> > {
>> > BindyCsvDataFormat camelDataFormat = new
>> >
>> BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.simple.oneclassmandatory");
>> >
>> > �...@override
>> > �...@bean
>> > public RouteBuilder route() {
>> > return new RouteBuilder() {
>> > �...@override
>> > public void configure() {
>> >
>> > from("direct:start").unmarshal(camelDataFormat).to("mock:result");
>> > }
>> > };
>> > }
>> > }
>> >
>> > An IllegalArgumentException is generated in the log but the test
>> > testEmptyFields failed.
>> >
>> >
>> > Regards,
>> >
>> > Charles Moulliard
>> > Senior Enterprise Architect
>> > Apache Camel Committer
>> >
>> > *****************************
>> > blog : http://cmoulliard.blogspot.com
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>
--
Claus Ibsen
Apache Camel Committer
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus