Search in sources :

Example 51 with FailedToCreateRouteException

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

the class RouteMustHaveOutputOnExceptionTest method testInValid.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").onException(Exception.class).maximumRedeliveries(2).backOffMultiplier(1.5).handled(true).delay(1000).log("Halting for some time").to("mock:halt").end().to("mock:result");
        }
    });
    try {
        context.start();
        fail("Should have thrown an exception");
    } catch (FailedToCreateRouteException e) {
    // expected
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException)

Example 52 with FailedToCreateRouteException

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

the class TryCatchMustHaveExceptionConfiguredTest method testTryCatchMustHaveExceptionConfigured.

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

        @Override
        @SuppressWarnings("unchecked")
        public void configure() throws Exception {
            from("direct:a").doTry().to("mock:b").throwException(new IllegalArgumentException("Damn")).doCatch().to("mock:catch").end();
        }
    });
    try {
        context.start();
        fail("Should throw exception");
    } catch (FailedToCreateRouteException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("At least one Exception must be configured to catch", e.getCause().getMessage());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException)

Example 53 with FailedToCreateRouteException

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

the class OnExceptionHandledAndContinueTest method testHandledAndContinued.

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

        @Override
        public void configure() throws Exception {
            // should not be allowed
            onException(IllegalArgumentException.class).continued(true).handled(true);
            from("direct:start").to("mock:start").throwException(new IllegalArgumentException("Forced")).to("mock:result");
        }
    });
    try {
        context.start();
        fail("Should thrown an exception");
    } catch (FailedToCreateRouteException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertTrue(e.getCause().getMessage().startsWith("Only one of handled or continued is allowed to be configured"));
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException)

Example 54 with FailedToCreateRouteException

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

the class OnExceptionMisconfiguredTest method testOnExceptionMisconfigured4.

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

        @Override
        @SuppressWarnings("unchecked")
        public void configure() throws Exception {
            onException().end();
            from("direct:start").to("mock:result");
        }
    });
    try {
        context.start();
        fail("Should have thrown exception");
    } catch (FailedToCreateRouteException e) {
        IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("OnException[[class java.lang.Exception] -> []] is not configured.", iae.getMessage());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) SOAPException(javax.xml.soap.SOAPException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) IOException(java.io.IOException)

Example 55 with FailedToCreateRouteException

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

the class ClassComponentInvalidConfigurationTest method testPropertyNotFoundOnClass.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").to("class:org.apache.camel.component.bean.MyPrefixBean?bean.foo=bar").to("mock:result");
        }
    });
    try {
        context.start();
        fail("Should have thrown exception");
    } catch (FailedToCreateRouteException e) {
        ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
        assertTrue(cause.getMessage().contains("Unknown parameters"));
        assertTrue(cause.getMessage().contains("foo=bar"));
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException)

Aggregations

FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)66 RouteBuilder (org.apache.camel.builder.RouteBuilder)63 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)13 Test (org.junit.Test)9 IOException (java.io.IOException)6 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)6 SOAPException (javax.xml.soap.SOAPException)5 CamelContext (org.apache.camel.CamelContext)5 FileNotFoundException (java.io.FileNotFoundException)3 NoSuchBeanException (org.apache.camel.NoSuchBeanException)3 ArrayList (java.util.ArrayList)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 CamelExecutionException (org.apache.camel.CamelExecutionException)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 DefaultRouteContext (org.apache.camel.impl.DefaultRouteContext)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 RouteContext (org.apache.camel.spi.RouteContext)2 EventBus (com.google.common.eventbus.EventBus)1 HttpException (com.meterware.httpunit.HttpException)1