Repository: camel Updated Branches: refs/heads/master 7558e631e -> fbf0ffad6
http://git-wip-us.apache.org/repos/asf/camel/blob/fbf0ffad/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java index 15a4974..395f7d0 100644 --- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java @@ -18,31 +18,36 @@ package org.apache.camel.spring.processor; import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; +import org.apache.camel.RuntimeCamelException; import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; public class SpringRouteTopLevelMisconfiguredTest extends ContextTestSupport { + @Override protected CamelContext createCamelContext() throws Exception { try { createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringRouteTopLevelOnExceptionMisconfiguredTest.xml"); fail("Should have thrown exception"); - } catch (Exception e) { - assertTrue(e.getCause().getMessage().startsWith("The output must be added as top-level on the route.")); + } catch (RuntimeCamelException e) { + IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertTrue(iae.getMessage().startsWith("The output must be added as top-level on the route.")); } try { createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringRouteTopLevelOnCompletionMisconfiguredTest.xml"); fail("Should have thrown exception"); - } catch (Exception e) { - assertTrue(e.getCause().getMessage().startsWith("The output must be added as top-level on the route.")); + } catch (RuntimeCamelException e) { + IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertTrue(iae.getMessage().startsWith("The output must be added as top-level on the route.")); } try { createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringRouteTopLevelTransactedMisconfiguredTest.xml"); fail("Should have thrown exception"); - } catch (Exception e) { - assertTrue(e.getCause().getMessage().startsWith("The output must be added as top-level on the route.")); + } catch (RuntimeCamelException e) { + IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertTrue(iae.getMessage().startsWith("The output must be added as top-level on the route.")); } http://git-wip-us.apache.org/repos/asf/camel/blob/fbf0ffad/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMisconfiguredTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMisconfiguredTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMisconfiguredTest.java index 4364b8c..964321f 100644 --- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMisconfiguredTest.java +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMisconfiguredTest.java @@ -19,28 +19,30 @@ package org.apache.camel.spring.processor; import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; import org.apache.camel.FailedToCreateRouteException; +import org.apache.camel.RuntimeCamelException; import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; public class SpringTryCatchMisconfiguredTest extends ContextTestSupport { + @Override protected CamelContext createCamelContext() throws Exception { try { createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringTryCatchMisconfiguredTest.xml"); fail("Should have thrown exception"); - } catch (Exception e) { - assertIsInstanceOf(FailedToCreateRouteException.class, e.getCause()); - assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause()); - assertEquals("This doCatch should have a doTry as its parent on DoCatch[ [class java.io.IOException] -> [To[mock:fail]]]", e.getCause().getCause().getMessage()); + } catch (RuntimeCamelException e) { + FailedToCreateRouteException ftce = assertIsInstanceOf(FailedToCreateRouteException.class, e.getCause()); + IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, ftce.getCause()); + assertEquals("This doCatch should have a doTry as its parent on DoCatch[ [class java.io.IOException] -> [To[mock:fail]]]", iae.getMessage()); } try { createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringTryCatchMisconfiguredFinallyTest.xml"); fail("Should have thrown exception"); - } catch (Exception e) { - assertIsInstanceOf(FailedToCreateRouteException.class, e.getCause()); - assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause()); - assertEquals("This doFinally should have a doTry as its parent on DoFinally[[To[mock:finally]]]", e.getCause().getCause().getMessage()); + } catch (RuntimeCamelException e) { + FailedToCreateRouteException ftcre = assertIsInstanceOf(FailedToCreateRouteException.class, e.getCause()); + IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, ftcre.getCause()); + assertEquals("This doFinally should have a doTry as its parent on DoFinally[[To[mock:finally]]]", iae.getMessage()); } // return a working context instead, to let this test pass http://git-wip-us.apache.org/repos/asf/camel/blob/fbf0ffad/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java index 75d52fa..f3cbe2e 100644 --- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java @@ -19,6 +19,7 @@ package org.apache.camel.spring.processor; import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; import org.apache.camel.FailedToCreateRouteException; +import org.apache.camel.RuntimeCamelException; import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; @@ -28,10 +29,10 @@ public class SpringTryCatchMustHaveExceptionConfiguredTest extends ContextTestSu try { createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.xml"); fail("Should have thrown exception"); - } catch (Exception e) { - assertIsInstanceOf(FailedToCreateRouteException.class, e.getCause()); - assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause()); - assertEquals("At least one Exception must be configured to catch", e.getCause().getCause().getMessage()); + } catch (RuntimeCamelException e) { + FailedToCreateRouteException ftcre = assertIsInstanceOf(FailedToCreateRouteException.class, e.getCause()); + IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, ftcre.getCause()); + assertEquals("At least one Exception must be configured to catch", iae.getMessage()); } // return a working context instead, to let this test pass http://git-wip-us.apache.org/repos/asf/camel/blob/fbf0ffad/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootExecutionListener.java ---------------------------------------------------------------------- diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootExecutionListener.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootExecutionListener.java index c17a421..546462d 100644 --- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootExecutionListener.java +++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootExecutionListener.java @@ -16,6 +16,8 @@ */ package org.apache.camel.test.spring; +import org.apache.camel.CamelContext; +import org.apache.camel.spring.SpringCamelContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ConfigurableApplicationContext; @@ -31,6 +33,12 @@ public class CamelSpringBootExecutionListener extends AbstractTestExecutionListe LOG.info("@RunWith(CamelSpringBootJUnit4ClassRunner.class) preparing: {}", testContext.getTestClass()); Class<?> testClass = testContext.getTestClass(); + // we are customizing the Camel context with + // CamelAnnotationsHandler so we do not want to start it + // automatically, which would happen when SpringCamelContext + // is added to Spring ApplicationContext, so we set the flag + // not to start it just yet + SpringCamelContext.setNoStart(true); ConfigurableApplicationContext context = (ConfigurableApplicationContext) testContext.getApplicationContext(); // Post CamelContext(s) instantiation but pre CamelContext(s) start setup @@ -39,6 +47,11 @@ public class CamelSpringBootExecutionListener extends AbstractTestExecutionListe CamelAnnotationsHandler.handleMockEndpoints(context, testClass); CamelAnnotationsHandler.handleMockEndpointsAndSkip(context, testClass); CamelAnnotationsHandler.handleUseOverridePropertiesWithPropertiesComponent(context, testClass); + SpringCamelContext.setNoStart(false); + CamelContext camelContext = context.getBean(CamelContext.class); + + // after our customizations we should start the CamelContext + camelContext.start(); } @Override