Search in sources :

Example 16 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class DirectVmNoConsumerTest method testFailIfNoConsumerFalse.

@Test
public void testFailIfNoConsumerFalse() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct-vm:start").to("direct-vm:foo?failIfNoConsumers=false");
        }
    });
    context.start();
    try {
        template.sendBody("direct-vm:start", "Hello World");
    } catch (CamelExecutionException e) {
        fail("Should not throw an exception");
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

Example 17 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class DirectVmNoConsumerTest method testFailIfNoConsumersAfterConsumersLeave.

@Test
public void testFailIfNoConsumersAfterConsumersLeave() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct-vm:foo").routeId("stopThisRoute").to("mock:foo");
        }
    });
    context.start();
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    template.sendBody("direct-vm:foo", "Hello World");
    assertMockEndpointsSatisfied();
    context.stopRoute("stopThisRoute");
    TimeUnit.MILLISECONDS.sleep(100);
    try {
        template.sendBody("direct-vm:foo", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(DirectVmConsumerNotAvailableException.class, e.getCause());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

Example 18 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class DirectVmNoConsumerTest method testInOut.

public void testInOut() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct-vm:start").to("direct-vm:foo");
        }
    });
    context.start();
    try {
        template.requestBody("direct-vm:start", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(DirectVmConsumerNotAvailableException.class, e.getCause());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException)

Example 19 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class DirectVmProducerBlockingTest method testProducerBlocksWithNoConsumers.

public void testProducerBlocksWithNoConsumers() throws Exception {
    DirectVmEndpoint endpoint = getMandatoryEndpoint("direct-vm:suspended", DirectVmEndpoint.class);
    endpoint.getConsumer().suspend();
    StopWatch watch = new StopWatch();
    try {
        template.sendBody("direct-vm:start?block=true&timeout=2000", "hello world");
        fail("Expected CamelExecutionException");
    } catch (CamelExecutionException e) {
        DirectVmConsumerNotAvailableException cause = assertIsInstanceOf(DirectVmConsumerNotAvailableException.class, e.getCause());
        assertIsInstanceOf(CamelExchangeException.class, cause);
        assertTrue(watch.taken() > 1500);
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) StopWatch(org.apache.camel.util.StopWatch)

Example 20 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class XsltDTDTest method sendEntityMessage.

private void sendEntityMessage(Object message) throws Exception {
    MockEndpoint endpoint = getMockEndpoint("mock:result");
    endpoint.reset();
    endpoint.expectedMessageCount(1);
    template.sendBody("direct:start1", message);
    assertMockEndpointsSatisfied();
    List<Exchange> list = endpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    String xml = exchange.getIn().getBody(String.class);
    assertTrue("Get a wrong transformed message", xml.indexOf("<transformed subject=\"\">") > 0);
    try {
        endpoint.reset();
        endpoint.expectedMessageCount(1);
        template.sendBody("direct:start2", message);
        assertMockEndpointsSatisfied();
        list = endpoint.getReceivedExchanges();
        exchange = list.get(0);
        xml = exchange.getIn().getBody(String.class);
        assertTrue("Get a wrong transformed message", xml.indexOf("<transformed subject=\"\">") > 0);
    } catch (Exception ex) {
        // expect an exception here
        assertTrue("Get a wrong exception", ex instanceof CamelExecutionException);
        // the file could not be found
        assertTrue("Get a wrong exception cause", ex.getCause() instanceof TransformerException);
    }
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) TransformerException(javax.xml.transform.TransformerException) CamelExecutionException(org.apache.camel.CamelExecutionException) TransformerException(javax.xml.transform.TransformerException)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)140 RouteBuilder (org.apache.camel.builder.RouteBuilder)60 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)58 Test (org.junit.Test)48 Exchange (org.apache.camel.Exchange)23 Processor (org.apache.camel.Processor)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4 Set (java.util.Set)4 ConstraintViolation (javax.validation.ConstraintViolation)4 CamelContext (org.apache.camel.CamelContext)4 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)4 QuartzComponent (org.apache.camel.component.quartz2.QuartzComponent)4 List (java.util.List)3 JSONException (net.sf.json.JSONException)3