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