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());
}
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();
}
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();
}
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());
}
}
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());
}
}
Aggregations