Search in sources :

Example 11 with CamelExecutionException

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

the class OnExceptionRouteTest method testErrorWhileHandlingException.

public void testErrorWhileHandlingException() throws Exception {
    // DLC does not handle the exception as we failed during processing in onException
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(0);
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "<order><type>myType</type><user>FuncError</user></order>");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        // the myOwnHandlerBean throw exception while handling an exception
        IOException cause = assertIsInstanceOf(IOException.class, e.getCause());
        assertEquals("Damn something did not work", cause.getMessage());
    }
    assertMockEndpointsSatisfied();
    // should not handle it
    assertNull(myOwnHandlerBean.getPayload());
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IOException(java.io.IOException)

Example 12 with CamelExecutionException

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

the class FtpProducerFileExistFailTest method testFail.

@Test
public void testFail() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    mock.expectedFileExists(FTP_ROOT_DIR + "/exist/hello.txt", "Hello World");
    try {
        template.sendBodyAndHeader(getFtpUrl(), "Bye World", Exchange.FILE_NAME, "hello.txt");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        GenericFileOperationFailedException cause = assertIsInstanceOf(GenericFileOperationFailedException.class, e.getCause());
        assertEquals("File already exist: exist/hello.txt. Cannot write new file.", cause.getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) GenericFileOperationFailedException(org.apache.camel.component.file.GenericFileOperationFailedException) Test(org.junit.Test)

Example 13 with CamelExecutionException

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

the class FluentProducerTemplateTest method testInOutWithBodyConversionFault.

public void testInOutWithBodyConversionFault() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        DefaultFluentProducerTemplate.on(context).withBodyAs("10", Double.class).to("direct:sum").request();
    } catch (CamelExecutionException e) {
        assertTrue(e.getCause() instanceof IllegalArgumentException);
        assertEquals("Expected body of type Integer", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 14 with CamelExecutionException

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

the class DirectNoConsumerTest method testInOut.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").to("direct:foo");
        }
    });
    context.start();
    try {
        template.requestBody("direct:start", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException)

Example 15 with CamelExecutionException

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

the class DirectNoConsumerTest method testFailIfNoConsumersAfterConsumersLeave.

@Test
public void testFailIfNoConsumersAfterConsumersLeave() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:foo").routeId("stopThisRoute").to("mock:foo");
        }
    });
    context.start();
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    template.sendBody("direct:foo", "Hello World");
    assertMockEndpointsSatisfied();
    context.stopRoute("stopThisRoute");
    TimeUnit.MILLISECONDS.sleep(100);
    try {
        template.sendBody("direct:foo", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

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