use of org.apache.camel.CamelExecutionException in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithOptionalChecksGroup.
@Test
public void validateShouldFailWithOptionalChecksGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=org.apache.camel.component.bean.validator.OptionalChecks";
final Car car = createCar("BMW", "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("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 BeanOverloadedMethodTest method testHelloOverloadedStringInt.
public void testHelloOverloadedStringInt() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").bean(MyBean.class, "hello(String,int)").to("mock:result");
}
});
context.start();
try {
template.sendBodyAndHeader("direct:start", "Claus", "country", "Denmark");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
AmbiguousMethodCallException cause = assertIsInstanceOf(AmbiguousMethodCallException.class, e.getCause());
assertEquals(2, cause.getMethods().size());
}
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class FileProducerTempFileExistsIssueTest method testWriteUsingTempPrefixButFileExistFail.
public void testWriteUsingTempPrefixButFileExistFail() throws Exception {
template.sendBodyAndHeader("file://target/tempprefix", "Hello World", Exchange.FILE_NAME, "hello.txt");
try {
template.sendBodyAndHeader("file://target/tempprefix?tempPrefix=foo&fileExist=Fail", "Bye World", Exchange.FILE_NAME, "hello.txt");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
GenericFileOperationFailedException cause = assertIsInstanceOf(GenericFileOperationFailedException.class, e.getCause());
assertTrue(cause.getMessage().startsWith("File already exist"));
}
File file = new File("target/tempprefix/hello.txt");
assertEquals(true, file.exists());
// should not write new file as we should fail
assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file));
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class XsltTransformingExceptionTest method testXsltException.
public void testXsltException() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.sendBody("direct:start", BAD_XML_STRING);
fail("Except a camel Execution exception here");
} catch (CamelExecutionException ex) {
assertTrue(ex.getCause() instanceof javax.xml.transform.TransformerException);
}
// we should not get any message from the result endpoint
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class EventDrivenPollingConsumerQueueSizeTest method testQueueSize.
public void testQueueSize() throws Exception {
// must start context as we do not use route builder that auto-start
context.start();
PollingConsumer consumer = context.getEndpoint(uri).createPollingConsumer();
consumer.start();
assertNotNull(consumer);
EventDrivenPollingConsumer edpc = assertIsInstanceOf(EventDrivenPollingConsumer.class, consumer);
assertEquals(0, edpc.getQueueSize());
assertEquals(10, edpc.getQueueCapacity());
assertFalse(edpc.isBlockWhenFull());
for (int i = 0; i < 10; i++) {
template.sendBody(uri, "Message " + i);
}
assertEquals(10, edpc.getQueueSize());
try {
template.sendBody(uri, "Message 10");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
// queue should be full
assertIsInstanceOf(IllegalStateException.class, e.getCause());
}
Exchange out = consumer.receive(5000);
assertNotNull(out);
assertEquals("Message 0", out.getIn().getBody());
assertEquals(9, edpc.getQueueSize());
assertEquals(10, edpc.getQueueCapacity());
// now there is room
template.sendBody(uri, "Message 10");
assertEquals(10, edpc.getQueueSize());
assertEquals(10, edpc.getQueueCapacity());
ServiceHelper.stopService(consumer);
// not cleared if we stop
assertEquals(10, edpc.getQueueSize());
assertEquals(10, edpc.getQueueCapacity());
ServiceHelper.stopAndShutdownService(consumer);
// now its cleared as we shutdown
assertEquals(0, edpc.getQueueSize());
assertEquals(10, edpc.getQueueCapacity());
}
Aggregations