Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 44671 invoked from network); 11 Sep 2009 13:18:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Sep 2009 13:18:05 -0000 Received: (qmail 69136 invoked by uid 500); 11 Sep 2009 13:18:04 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 69082 invoked by uid 500); 11 Sep 2009 13:18:04 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 69072 invoked by uid 99); 11 Sep 2009 13:18:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Sep 2009 13:18:04 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of cmoulliard@gmail.com designates 209.85.219.205 as permitted sender) Received: from [209.85.219.205] (HELO mail-ew0-f205.google.com) (209.85.219.205) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Sep 2009 13:17:52 +0000 Received: by ewy1 with SMTP id 1so1037036ewy.6 for ; Fri, 11 Sep 2009 06:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=NJDgTkAd4aewJjnWQZoLuscDBpYLHEhesUrbmO7UKz4=; b=SzwjwEwSHk9ZEmrMJoRegNzhdCBT7PE5nUXPxszggemaaZYbjhErHP2JBpQrbkW1/Z uG42yRQoz4ZS+fnDDQj3jjzfiDv0BWRlOKR+e7sDTJhrL0iLd5WW14e/cZfeOUni4cpT WFsN4XNDuIC4AqFRvL29bpCU2PsBSsPkOt3Rg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=vvChsD9iaCAj/Z3hzMwj94pljrt3lyflU2ZZNgZWLhwqOzvpZEb10oqPb2Oy7QNL/9 kvvVAUnB/Lo6Xq3jTE/L58X8bix/lYQ2iMa0b2bObM54ulGhVCzffcDHHWjKlpOi04nf Po4ZNgqJwfCuXoU46D5Xzl+Jd2pdsbCMfmxZg= MIME-Version: 1.0 Received: by 10.216.90.212 with SMTP id e62mr692568wef.26.1252675051706; Fri, 11 Sep 2009 06:17:31 -0700 (PDT) In-Reply-To: <5380c69c0909110536l7c3d579ejfe5f21d62287cfc3@mail.gmail.com> References: <5380c69c0909110536l7c3d579ejfe5f21d62287cfc3@mail.gmail.com> Date: Fri, 11 Sep 2009 15:17:31 +0200 Message-ID: Subject: Re: Unit test with try/catch block From: Charles Moulliard To: users@camel.apache.org Content-Type: multipart/alternative; boundary=0016e6d7e88779db9104734d2336 X-Virus-Checked: Checked by ClamAV on apache.org --0016e6d7e88779db9104734d2336 Content-Type: text/plain; charset=ISO-8859-1 I have created the following route (after looking to the example provided under camel-core\src\test\java\org\apache\camel\processor\onexception) and I receive a NPE : java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:201) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at ... ... Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelBeanPostProcessor': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.apache.camel.spring.CamelBeanPostProcessor ... Caused by: java.lang.NullPointerException at org.apache.camel.spring.spi.ApplicationContextRegistry.lookupByType(ApplicationContextRegistry.java:60) at org.apache.camel.processor.DefaultChannel.getOrCreateTracer(DefaultChannel.java:176) at org.apache.camel.processor.DefaultChannel.initChannel(DefaultChannel.java:153) at org.apache.camel.model.ProcessorDefinition.wrapChannel(ProcessorDefinition.java:174) at org.apache.camel.model.ProcessorDefinition.wrapProcessor(ProcessorDefinition.java:157) at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:288) @ContextConfiguration(locations = "com.xpectis.x3s.intoout.OinpExampleBadDateFormatTest$ContextConfig", loader = JavaConfigContextLoader.class) public class OinpExampleBadDateFormatTest extends AbstractJUnit4SpringContextTests { private static final transient Log LOG = LogFactory.getLog(OinpExampleBadDateFormatTest.class); private static final String uriMockResult = "mock:result"; private static final String uriMockError = "mock:error"; @EndpointInject(uri = uriMockResult) private MockEndpoint result; @EndpointInject(uri = uriMockError) private MockEndpoint error; // Test OINP_Example-bad_date_format.csv file @Test @DirtiesContext public void testParseFile() throws Exception { // We don't expect to have a message as an error will be raised result.expectedMessageCount(0); // Message has been delivered to the mock error error.expectedMessageCount(1); result.assertIsSatisfied(); error.assertIsSatisfied(); } @Configuration public static class ContextConfig extends SingleRouteCamelConfiguration { BindyCsvDataFormat oinpDataFormat = new BindyCsvDataFormat(" com.xpectis.x3s.model.backoffice.emx.oinp.in"); @Override @Bean public RouteBuilder route() { return new RouteBuilder() { @Override public void configure() { // default should errors go to mock:error errorHandler(deadLetterChannel(uriMockError).redeliverDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); from(uriFile).unmarshal(oinpDataFormat).to(uriMockResult); } }; } } } Charles Moulliard Senior Enterprise Architect Apache Camel Committer ***************************** blog : http://cmoulliard.blogspot.com On Fri, Sep 11, 2009 at 2:36 PM, Claus Ibsen wrote: > You can use the dead letter channel to move the failed message to a > mock:dead endpoint which you can use in unit tests. > > > On Fri, Sep 11, 2009 at 2:06 PM, Charles Moulliard > wrote: > > Hi, > > > > I develop a unit to detect if an error has been raised during the parsing > of > > a file through Camel-bindy. In this unit test, I don't use a template to > > produce message as they will be generated by the file endpoint. > > > > try { > > // cannot be used as we work with a fileEndpoint --> > > template.sendBody("direct:start", ""); > > fail("Exception has been throwed"); > > } catch (CamelExecutionException ex) { > > ... > > } > > > > > > How can I check the error generated during file parsing (camel-bindy) ? > > > > Here is the route > > > > from(uriFile).unmarshal(oinpDataFormat).to(uriMockResult); > > > > Error to be catched : > > > > 2009-09-11 13:53:48,308 DEBUG GenericFileOnCompletion - Done processing > > file: GenericFile[OINP_Example-bad_date_format.csv] using exchange: > > Exchange[GenericFileMessage with file: > > GenericFile[OINP_Example-bad_date_format.csv]] > > 2009-09-11 13:53:48,308 ERROR GenericFileOnCompletion - Date provided > does > > not fit the pattern defined, position : 43, line nber : 1 > > java.lang.IllegalArgumentException: Date provided does not fit the > pattern > > defined, position : 43, line nber : 1 > > > > > > 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 > --0016e6d7e88779db9104734d2336--