use of org.apache.camel.CamelExecutionException in project camel by apache.
the class ContextScopedOnExceptionCorrectRouteContextTest method testContextScopedOnExceptionLogRouteBarFail.
public void testContextScopedOnExceptionLogRouteBarFail() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Exception.class).log("Error due ${exception.message}").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String routeId = exchange.getUnitOfWork().getRouteContext().getRoute().getId();
assertEquals("bar", routeId);
}
});
from("direct:start").routeId("foo").to("mock:foo").to("direct:bar").to("mock:result");
from("direct:bar").routeId("bar").to("mock:bar").throwException(new IllegalArgumentException("Forced bar error"));
}
});
context.start();
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(0);
try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Forced bar error", cause.getMessage());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class ContextScopedOnExceptionCorrectRouteContextTest method testContextScopedOnExceptionLogRouteFooFail.
public void testContextScopedOnExceptionLogRouteFooFail() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Exception.class).log("Error due ${exception.message}").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String routeId = exchange.getUnitOfWork().getRouteContext().getRoute().getId();
assertEquals("foo", routeId);
}
});
from("direct:start").routeId("foo").to("mock:foo").throwException(new IllegalArgumentException("Forced foo error")).to("direct:bar").to("mock:result");
from("direct:bar").routeId("bar").to("mock:bar");
from("direct:killer").routeId("killer").to("mock:killer");
}
});
context.start();
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
getMockEndpoint("mock:result").expectedMessageCount(0);
try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Forced foo error", cause.getMessage());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class AdviceWithTest method testAdvisedThrowException.
public void testAdvisedThrowException() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:foo").to("mock:advised").throwException(new IllegalArgumentException("Damn"));
}
});
getMockEndpoint("mock:foo").expectedMessageCount(0);
getMockEndpoint("mock:advised").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(0);
try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", e.getCause().getMessage());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithOrderedChecksGroup.
@Test
public void validateShouldFailWithOrderedChecksGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=org.apache.camel.component.bean.validator.OrderedChecks";
final Car car = createCar(null, "D-A");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("manufacturer", constraintViolation.getPropertyPath().toString());
assertEquals(null, constraintViolation.getInvalidValue());
assertEquals("may not be null", constraintViolation.getMessage());
}
car.setManufacturer("BMW");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals("D-A", constraintViolation.getInvalidValue());
assertEquals("size must be between 5 and 14", constraintViolation.getMessage());
}
car.setLicensePlate("DD-AB-123");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithExpliciteDefaultGroup.
@Test
public void validateShouldFailWithExpliciteDefaultGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=javax.validation.groups.Default";
final Car car = createCar("BMW", null);
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals(null, constraintViolation.getInvalidValue());
assertEquals("may not be null", constraintViolation.getMessage());
}
car.setLicensePlate("D-A");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
Aggregations