Search in sources :

Example 61 with CamelExecutionException

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);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) Set(java.util.Set) Processor(org.apache.camel.Processor) ConstraintViolation(javax.validation.ConstraintViolation) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

Example 62 with CamelExecutionException

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());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException)

Example 63 with CamelExecutionException

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));
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) File(java.io.File)

Example 64 with CamelExecutionException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 65 with CamelExecutionException

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());
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) Endpoint(org.apache.camel.Endpoint)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)156 RouteBuilder (org.apache.camel.builder.RouteBuilder)69 Test (org.junit.Test)64 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)59 Exchange (org.apache.camel.Exchange)23 CamelContext (org.apache.camel.CamelContext)20 Processor (org.apache.camel.Processor)17 ProducerTemplate (org.apache.camel.ProducerTemplate)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 Set (java.util.Set)6 Subject (javax.security.auth.Subject)6 ConstraintViolation (javax.validation.ConstraintViolation)6 FailedLoginException (javax.security.auth.login.FailedLoginException)5 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4