If you want camel-cxf send the exception back to you, you can assert the to get 
the example from the template response.
If you just want to test the error handling of the route, you can add a mock 
endpoint after the onException, to make sure you go the exception there.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) 
(English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Monday, November 11, 2013 at 7:26 AM, sdelanghe wrote:

> Hey, i am wondering how testing exception throwing in junit.  
>  
> I have my mock endpoint defined and the exchange received with a processor
> that throws an error.
> Now the template.sendBody on the endpoint does throw an error but still has
> a normal exchange message.
>  
> How can i do this last part to assert the exception on the exchange.  
>  
>  
> Unit test:
> @Test
> @DirtiesContext
> public void test_echo_route_socketError() throws InterruptedException{
> final String echoString = "Welcome to Camel echo demonstration" ;
>  
> endPoint.expectedMessageCount(0);
> endPoint.whenAnyExchangeReceived(new Processor() {
> public void process(Exchange exchange) throws Exception {
> exchange.setException(new ConnectException("Simulated
> connection error"));
> }
> });
>  
> template.sendBody("mock:cxf:bean:echoService", echoString);
>  
> endPoint.assertIsSatisfied();
> }
>  
>  
> Route:
> @Override
> public void configure() throws Exception {
>  
> onException(ConnectException.class)
> .log(LoggingLevel.WARN,".......")
> ;
>  
>  
> from("cxf:bean:echoService")
> .log(LoggingLevel.TRACE, "Start echo route") ;
>  
>  
> }
>  
>  
>  
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Test-exception-thrown-in-junit-test-tp5742984.html
> Sent from the Camel - Users mailing list archive at Nabble.com 
> (http://Nabble.com).



Reply via email to