The test works if I add this in the route config :

                    Tracer tracer = new Tracer();
                    tracer.setLogLevel(LoggingLevel.FATAL);
                    tracer.setLogName("com.xpectis.x3s");

                    getContext().addInterceptStrategy(tracer);


Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer

*****************************
blog : http://cmoulliard.blogspot.com


On Fri, Sep 11, 2009 at 3:17 PM, Charles Moulliard <[email protected]>wrote:

> 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 <[email protected]>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 <[email protected]>
>> 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
>>
>
>

Reply via email to