camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Moulliard <cmoulli...@gmail.com>
Subject Re: How to test an exception in a camel test
Date Wed, 15 Jul 2009 10:15:40 GMT
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.ibsen@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<cmoulliard@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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message