Thx. It works with this :
try { template1.sendBody(record1); } catch (CamelExecutionException e) { Charles Moulliard Senior Enterprise Architect Apache Camel Committer ***************************** blog : http://cmoulliard.blogspot.com On Wed, Jul 15, 2009 at 11:31 AM, Claus Ibsen <claus.ib...@gmail.com> 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<cmoulli...@gmail.com> > 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 >