use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class FluentProducerTemplateTest method testRequestExceptionUsingBody.
public void testRequestExceptionUsingBody() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
DefaultFluentProducerTemplate.on(context).withBody("Hello World").to("direct:exception").request();
fail("Should have thrown RuntimeCamelException");
} catch (RuntimeCamelException e) {
assertTrue(e.getCause() instanceof IllegalArgumentException);
assertEquals("Forced exception by unit test", e.getCause().getMessage());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class MyServiceProxyTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").choice().when(body().isEqualTo("Tiger in Action")).throwException(new MyApplicationException("No tigers", 9)).when(body().isEqualTo("Donkey in Action")).throwException(new RuntimeCamelException(new MyApplicationException("No donkeys", 8))).when(body().isEqualTo("Elephant in Action")).throwException(new MyCustomException("Damn", new MyApplicationException("No elephants", 7))).when(body().isEqualTo("Kaboom")).throwException(new IllegalArgumentException("Damn")).otherwise().transform(constant("Camel in Action"));
from("direct:request").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
MyRequest request = exchange.getIn().getBody(MyRequest.class);
MyResponse response = new MyResponse();
response.id = request.id;
response.response = "Hi " + request.request;
// we need to setup the body as a response
exchange.getOut().setBody(response);
}
});
}
};
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class TimerEndpointTest method testTimerEndpointNoProducer.
public void testTimerEndpointNoProducer() throws Exception {
Endpoint te = context.getEndpoint("timer://foo");
try {
te.createProducer();
fail("Should have thrown an exception");
} catch (RuntimeCamelException e) {
// expected
}
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class ValidatingProcessorTest method testInvalidMessage.
public void testInvalidMessage() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:invalid");
mock.expectedMessageCount(1);
String xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + "<user xmlns=\"http://foo.com/bar\">" + " <username>someone</username>" + "</user>";
try {
template.sendBody("direct:start", xml);
fail("Should have thrown a RuntimeCamelException");
} catch (RuntimeCamelException e) {
assertTrue(e.getCause() instanceof SchemaValidationException);
// expected
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class ValidatingProcessorTest method testNonWellFormedXml.
public void testNonWellFormedXml() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:invalid");
mock.expectedMessageCount(1);
String xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + "user xmlns=\"http://foo.com/bar\">" + " <id>1</id>" + " <username>davsclaus</username>";
try {
template.sendBody("direct:start", xml);
fail("Should have thrown a RuntimeCamelException");
} catch (RuntimeCamelException e) {
assertTrue(e.getCause() instanceof SchemaValidationException);
// expected
}
assertMockEndpointsSatisfied();
}
Aggregations