Search in sources :

Example 41 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class BeanLanguageMethodMissingParenthesisTest method testFooMissingParenthesis.

public void testFooMissingParenthesis() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").filter(method(BeanLanguageMethodMissingParenthesisTest.class, "couldThisBeFoo(${body}, ${header.foo}")).to("mock:foo").end().to("mock:result");
        }
    });
    context.start();
    try {
        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "yes");
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
        assertEquals("Method should end with parenthesis, was couldThisBeFoo(${body}, ${header.foo}", iae.getMessage());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException)

Example 42 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class SplitterParallelStopOnExceptionTest method testSplitParallelStopOnExceptionStop.

public void testSplitParallelStopOnExceptionStop() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:split");
    mock.expectedMinimumMessageCount(0);
    mock.allMessages().body().isNotEqualTo("Kaboom");
    try {
        template.sendBody("direct:start", "Hello World,Goodday World,Kaboom,Bye World");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Parallel processing failed for number "));
        assertEquals("Forced", cause.getCause().getMessage());
        String body = cause.getExchange().getIn().getBody(String.class);
        assertTrue(body.contains("Kaboom"));
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 43 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class SplitterNoAggregationStrategyTest method testSplitNoAggregationStrategyException.

public void testSplitNoAggregationStrategyException() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:split");
    mock.expectedBodiesReceived("Hello World", "Bye World", "Hi World");
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "Hello World,Kaboom,Bye World,Hi World");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        assertEquals("Forced", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 44 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class SplitterStopOnExceptionTest method testSplitStopOnExceptionStop.

public void testSplitStopOnExceptionStop() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:split");
    // we do stop so we stop splitting when the exception occurs and thus we only receive 1 message
    mock.expectedBodiesReceived("Hello World");
    try {
        template.sendBody("direct:start", "Hello World,Kaboom,Bye World");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Sequential processing failed for number 1."));
        assertEquals("Forced", cause.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 45 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class PollEnricherAggregateOnExceptionTest method testEnrichFalseKaboom.

public void testEnrichFalseKaboom() throws Exception {
    template.send("seda:foo", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.setException(new IllegalArgumentException("I cannot do this"));
        }
    });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.sendBody("direct:start2", "Kaboom");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("I cannot do this", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) CamelExecutionException(org.apache.camel.CamelExecutionException) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CamelExecutionException(org.apache.camel.CamelExecutionException)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)140 RouteBuilder (org.apache.camel.builder.RouteBuilder)60 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)58 Test (org.junit.Test)48 Exchange (org.apache.camel.Exchange)23 Processor (org.apache.camel.Processor)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4 Set (java.util.Set)4 ConstraintViolation (javax.validation.ConstraintViolation)4 CamelContext (org.apache.camel.CamelContext)4 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)4 QuartzComponent (org.apache.camel.component.quartz2.QuartzComponent)4 List (java.util.List)3 JSONException (net.sf.json.JSONException)3