You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bu...@apache.org on 2017/08/25 08:22:03 UTC
svn commit: r1017260 [32/40] - in /websites/production/camel/content: ./
cache/
Modified: websites/production/camel/content/spring-testing.html
==============================================================================
--- websites/production/camel/content/spring-testing.html (original)
+++ websites/production/camel/content/spring-testing.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css' rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css' rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js' type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Spring Testing
@@ -86,169 +75,51 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="SpringTesting-SpringTesting">Spring Testing</h2><p><a shape="rect" href="testing.html">Testing</a> is a crucial part of any development or integration work. The Spring Framework offers a number of features that makes it easy to test while using Spring for Inversion of Control which works with JUnit 3.x, JUnit 4.x, and <a shape="rect" class="external-link" href="http://testng.org" rel="nofollow">TestNG</a>.</p><p>We can use Spring for IoC and the Camel <a shape="rect" href="mock.html">Mock</a> and <a shape="rect" href="test.html">Test</a> endpoints to create sophisticated integration/unit tests that are easy to run and debug inside your IDE.  There are three supported approaches for testing with Spring in Camel.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Testing Frameworks Supported</p></th><t
h colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Required Camel Test Dependencies</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><strong><code>CamelSpringTestSupport</code></strong></p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x (deprecated)</li><li>JUnit 4.x</li><li>TestNG - <strong>Camel 2.8</strong></li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Provided by:</p><ul><li><strong><code>org.apache.camel.test.CamelSpringTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelSpringTestSupport</code></strong></li><li><strong><code>org.apache.camel.testng.CamelSpringTestSupport</code></strong></li></ul><p>These base classes provide <a shape="rect" href="camel-test.html#CamelTest-FeaturesProvidedbyCamelTestSupport">feature parity</a> with the simple <strong><code>CamelTestSupport</code></strong> classes from
60;<a shape="rect" href="camel-test.html">Camel Test</a> but do not support Spring annotations on the test class such as <strong><code>@Autowired</code></strong>, <strong><code>@DirtiesContext</code></strong>, and <strong><code>@ContextConfiguration</code></strong>.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x (deprecated) - <code>camel-test-spring</code></li><li>JUnit 4.x - <code>camel-test-spring</code></li><li>TestNG - <code>camel-test-ng</code></li></ul></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Plain Spring Test</p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x</li><li>JUnit 4.x</li><li>TestNG</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Either extend the abstract base classes:</p><ul><li><strong><code>org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests</code></strong></li><li><strong><code>org.springframework.test.context.
junit38.AbstractJUnit4SpringContextTests</code></strong></li><li>etc.</li></ul><p>provided in Spring Test or use the Spring Test JUnit4 runner.  </p><p>These approaches support both the Camel annotations and Spring annotations. However, they do NOT have <a shape="rect" href="camel-test.html#CamelTest-FeaturesProvidedbyCamelTestSupport">feature parity</a> with:</p><ul><li><strong><code>org.apache.camel.test.CamelTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong></li><li><strong><code>org.apache.camel.testng.CamelSpringTestSupport</code></strong></li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x (deprecated) - None</li><li>JUnit 4.x - None</li><li>TestNG - None</li></ul></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Camel Enhanced Spring Test</p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4.x - <strong>Camel 2.10</strong></li><li>TestNG - <st
rong>Camel 2.10</strong></li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Either:</p><ul><li>use the <strong><code>org.apache.camel.test.junit4.CamelSpringJUnit4ClassRunner</code></strong> runner with the <strong><code>@RunWith</code></strong> annotation,</li><li>or extend <strong><code>org.apache.camel.testng.AbstractCamelTestNGSpringContextTests</code></strong> to enable <a shape="rect" href="camel-test.html#CamelTest-FeaturesProvidedbyCamelTestSupport">feature parity</a> with <strong><code>org.apache.camel.test.CamelTestSupport</code></strong> and <strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong>. These classes support the full suite of Spring Test annotations such as <strong><code>@Autowired</code></strong>, <strong><code>@DirtiesContext</code></strong>, and <strong><code>@ContextConfiguration</code></strong>.</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JUnit 3.x (deprecated)
- <code>camel-test-spring</code></p><p>JUnit 4.x - <code>camel-test-spring</code></p><p>TestNG - <code>camel-test-ng</code></p></td></tr></tbody></table></div><h3 id="SpringTesting-CamelSpringTestSupport">CamelSpringTestSupport</h3><p>The following Spring test support classes:</p><ul><li><strong><code>org.apache.camel.test.CamelSpringTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelSpringTestSupport</code></strong>, and</li><li><strong><code>org.apache.camel.testng.CamelSpringTestSupport</code></strong></li></ul><p>extend their non-Spring aware counterparts:</p><ul><li><strong><code>org.apache.camel.test.CamelTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong>, and </li><li><strong><code>org.apache.camel.testng.CamelTestSupport</code></strong></li></ul><p>and deliver integration with Spring into your test classes.  </p><p>Instead of instantiating th
e <strong><code>CamelContext</code></strong> and routes programmatically, these classes rely on a Spring context to wire the needed components together.  If your test extends one of these classes, you must provide the Spring context by implementing the following method.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[protected abstract AbstractApplicationContext createApplicationContext();
-]]></script>
-</div></div><p>You are responsible for the instantiation of the Spring context in the method implementation.  All of the features available in the non-Spring aware counterparts from <a shape="rect" href="camel-test.html">Camel Test</a> are available in your test.</p><h3 id="SpringTesting-PlainSpringTest">Plain Spring Test</h3><p>In this approach, your test classes directly inherit from the Spring Test abstract test classes or use the JUnit 4.x test runner provided in Spring Test.  This approach supports dependency injection into your test class and the full suite of Spring Test annotations. However, it does not support the features provided by the <strong><code>CamelSpringTestSupport</code></strong> classes.</p><h4 id="SpringTesting-PlainSpringTestusingJUnit3.xwithXMLConfigExample">Plain Spring Test using JUnit 3.x with XML Config Example</h4><p>Here is a simple unit test using JUnit 3.x support from Spring Test using <a shape="rect" class="external-lin
k" href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java">XML Config</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-// tag::example[]
-@ContextConfiguration
-public class FilterTest extends SpringRunWithTestSupport {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @DirtiesContext
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
- resultEndpoint.expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader(expectedBody, "foo", "bar");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @DirtiesContext
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
-
- template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
-
- resultEndpoint.assertIsSatisfied();
- }
-}
-// end::example[]
-]]></script>
-</div></div>Notice that we use <strong><code>@DirtiesContext</code></strong> on the test methods to force <a shape="rect" href="spring-testing.html">Spring Testing</a> to automatically reload the <a shape="rect" href="camelcontext.html">CamelContext</a> after each test method - this ensures that the tests don't clash with each other, e.g., one test method sending to an endpoint that is then reused in another test method.<p>Also notice the use of <strong><code>@ContextConfiguration</code></strong> to indicate that by default we should look for the file <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml">FilterTest-context.xml on the classpath</a> to configure the test case. The test context looks like:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<!-- tag::example[] -->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
- ">
-
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <filter>
- <xpath>$foo = 'bar'</xpath>
- <to uri="mock:result"/>
- </filter>
- </route>
- </camelContext>
-
-</beans>
-<!-- end::example[] -->
-]]></script>
-</div></div>This test will load a Spring XML configuration file called <strong><code>FilterTest-context.xml</code></strong> from the classpath in the same package structure as the <strong><code>FilterTest</code></strong> class and initialize it along with any Camel routes we define inside it, then inject the <strong><code>CamelContext </code></strong>instance into our test case.<p>For instance, like this maven folder layout:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[src/test/java/org/apache/camel/spring/patterns/FilterTest.java
+<div class="wiki-content maincontent"><h2 id="SpringTesting-SpringTesting">Spring Testing</h2><p><a shape="rect" href="testing.html">Testing</a> is a crucial part of any development or integration work. The Spring Framework offers a number of features that makes it easy to test while using Spring for Inversion of Control which works with JUnit 3.x, JUnit 4.x, and <a shape="rect" class="external-link" href="http://testng.org" rel="nofollow">TestNG</a>.</p><p>We can use Spring for IoC and the Camel <a shape="rect" href="mock.html">Mock</a> and <a shape="rect" href="test.html">Test</a> endpoints to create sophisticated integration/unit tests that are easy to run and debug inside your IDE.  There are three supported approaches for testing with Spring in Camel.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Testing Frameworks Supported</p></th><t
h colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Required Camel Test Dependencies</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><strong><code>CamelSpringTestSupport</code></strong></p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x (deprecated)</li><li>JUnit 4.x</li><li>TestNG - <strong>Camel 2.8</strong></li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Provided by:</p><ul><li><strong><code>org.apache.camel.test.CamelSpringTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelSpringTestSupport</code></strong></li><li><strong><code>org.apache.camel.testng.CamelSpringTestSupport</code></strong></li></ul><p>These base classes provide <a shape="rect" href="camel-test.html#CamelTest-FeaturesProvidedbyCamelTestSupport">feature parity</a> with the simple <strong><code>CamelTestSupport</code></strong> classes from
60;<a shape="rect" href="camel-test.html">Camel Test</a> but do not support Spring annotations on the test class such as <strong><code>@Autowired</code></strong>, <strong><code>@DirtiesContext</code></strong>, and <strong><code>@ContextConfiguration</code></strong>.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x (deprecated) - <code>camel-test-spring</code></li><li>JUnit 4.x - <code>camel-test-spring</code></li><li>TestNG - <code>camel-test-ng</code></li></ul></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Plain Spring Test</p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x</li><li>JUnit 4.x</li><li>TestNG</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Either extend the abstract base classes:</p><ul><li><strong><code>org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests</code></strong></li><li><strong><code>org.springframework.test.context.
junit38.AbstractJUnit4SpringContextTests</code></strong></li><li>etc.</li></ul><p>provided in Spring Test or use the Spring Test JUnit4 runner.  </p><p>These approaches support both the Camel annotations and Spring annotations. However, they do NOT have <a shape="rect" href="camel-test.html#CamelTest-FeaturesProvidedbyCamelTestSupport">feature parity</a> with:</p><ul><li><strong><code>org.apache.camel.test.CamelTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong></li><li><strong><code>org.apache.camel.testng.CamelSpringTestSupport</code></strong></li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 3.x (deprecated) - None</li><li>JUnit 4.x - None</li><li>TestNG - None</li></ul></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Camel Enhanced Spring Test</p></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4.x - <strong>Camel 2.10</strong></li><li>TestNG - <st
rong>Camel 2.10</strong></li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Either:</p><ul><li>use the <strong><code>org.apache.camel.test.junit4.CamelSpringJUnit4ClassRunner</code></strong> runner with the <strong><code>@RunWith</code></strong> annotation,</li><li>or extend <strong><code>org.apache.camel.testng.AbstractCamelTestNGSpringContextTests</code></strong> to enable <a shape="rect" href="camel-test.html#CamelTest-FeaturesProvidedbyCamelTestSupport">feature parity</a> with <strong><code>org.apache.camel.test.CamelTestSupport</code></strong> and <strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong>. These classes support the full suite of Spring Test annotations such as <strong><code>@Autowired</code></strong>, <strong><code>@DirtiesContext</code></strong>, and <strong><code>@ContextConfiguration</code></strong>.</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JUnit 3.x (deprecated)
- <code>camel-test-spring</code></p><p>JUnit 4.x - <code>camel-test-spring</code></p><p>TestNG - <code>camel-test-ng</code></p></td></tr></tbody></table></div><h3 id="SpringTesting-CamelSpringTestSupport">CamelSpringTestSupport</h3><p>The following Spring test support classes:</p><ul><li><strong><code>org.apache.camel.test.CamelSpringTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelSpringTestSupport</code></strong>, and</li><li><strong><code>org.apache.camel.testng.CamelSpringTestSupport</code></strong></li></ul><p>extend their non-Spring aware counterparts:</p><ul><li><strong><code>org.apache.camel.test.CamelTestSupport</code></strong></li><li><strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong>, and </li><li><strong><code>org.apache.camel.testng.CamelTestSupport</code></strong></li></ul><p>and deliver integration with Spring into your test classes.  </p><p>Instead of instantiating th
e <strong><code>CamelContext</code></strong> and routes programmatically, these classes rely on a Spring context to wire the needed components together.  If your test extends one of these classes, you must provide the Spring context by implementing the following method.</p><parameter ac:name="language">java</parameter><plain-text-body>protected abstract AbstractApplicationContext createApplicationContext();
+</plain-text-body><p>You are responsible for the instantiation of the Spring context in the method implementation.  All of the features available in the non-Spring aware counterparts from <a shape="rect" href="camel-test.html">Camel Test</a> are available in your test.</p><h3 id="SpringTesting-PlainSpringTest">Plain Spring Test</h3><p>In this approach, your test classes directly inherit from the Spring Test abstract test classes or use the JUnit 4.x test runner provided in Spring Test.  This approach supports dependency injection into your test class and the full suite of Spring Test annotations. However, it does not support the features provided by the <strong><code>CamelSpringTestSupport</code></strong> classes.</p><h4 id="SpringTesting-PlainSpringTestusingJUnit3.xwithXMLConfigExample">Plain Spring Test using JUnit 3.x with XML Config Example</h4><p>Here is a simple unit test using JUnit 3.x support from Spring Test using <a shape="rect" class="extern
al-link" href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java">XML Config</a>.<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java}</plain-text-body>Notice that we use <strong><code>@DirtiesContext</code></strong> on the test methods to force <a shape="rect" href="spring-testing.html">Spring Testing</a> to automatically reload the <a shape="rect" href="camelcontext.html">CamelContext</a> after each test method - this ensures that the tests don't clash with each other, e.g., one test method sending to an endpoint that is then reused in another test method.</p><p>Also notice the use of <strong><code>@ContextConfiguration</code></strong> to indicate that by default we should look for the file <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/camel/trunk
/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml">FilterTest-context.xml on the classpath</a> to configure the test case. The test context looks like:<plain-text-body>{snippet:lang=xml|id=example|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml}</plain-text-body>This test will load a Spring XML configuration file called <strong><code>FilterTest-context.xml</code></strong> from the classpath in the same package structure as the <strong><code>FilterTest</code></strong> class and initialize it along with any Camel routes we define inside it, then inject the <strong><code>CamelContext </code></strong>instance into our test case.</p><p>For instance, like this maven folder layout:</p><plain-text-body>src/test/java/org/apache/camel/spring/patterns/FilterTest.java
src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml
-]]></script>
-</div></div><h4 id="SpringTesting-PlainSpringTestUsingJUnit4.xWithJavaConfigExample">Plain Spring Test Using JUnit 4.x With Java Config Example</h4><p>You can completely avoid using an XML configuration file by using <a shape="rect" href="spring-java-config.html">Spring Java Config</a>.  Here is a unit test using JUnit 4.x support from Spring Test using <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java">Java Config</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-// tag::example[]
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {FilterTest.ContextConfig.class}, loader = CamelSpringDelegatingTestContextLoader.class)
-public class FilterTest extends AbstractJUnit4SpringContextTests {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @DirtiesContext
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
- resultEndpoint.expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader(expectedBody, "foo", "bar");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @DirtiesContext
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
-
- template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @Configuration
- public static class ContextConfig extends SingleRouteCamelConfiguration {
- @Bean
- public RouteBuilder route() {
- return new RouteBuilder() {
- public void configure() {
- from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
- }
- };
- }
- }
-}
-// end::example[]
-]]></script>
-</div></div>This is similar to the XML Config example above except that there is no XML file and instead the nested <strong><code>ContextConfig</code></strong> class does all of the configuration; so your entire test case is contained in a single Java class. We currently have to reference by class name this class in the <strong><code>@ContextConfiguration</code></strong> which is a bit ugly. Please vote for <a shape="rect" class="external-link" href="http://jira.springframework.org/browse/SJC-238" rel="nofollow">SJC-238</a> to address this and make Spring Test work more cleanly with Spring JavaConfig.<h4 id="SpringTesting-PlainSpringTestUsingJUnit4.0.xRunnerWithXMLConfig">Plain Spring Test Using JUnit 4.0.x Runner With XML Config</h4><p>You can avoid extending Spring classes by using the <strong><code>SpringJUnit4ClassRunner</code></strong> provided by Spring Test.  This custom JUnit runner means you are free to choose your own class hierarchy while retaining all the capab
ilities of Spring Test.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>This is for Spring 4.0.x. If you use Spring 4.1 or newer, then see the next section.</p></div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@RunWith(SpringJUnit4ClassRunner.class)
+</plain-text-body><h4 id="SpringTesting-PlainSpringTestUsingJUnit4.xWithJavaConfigExample">Plain Spring Test Using JUnit 4.x With Java Config Example</h4><p>You can completely avoid using an XML configuration file by using <a shape="rect" href="spring-java-config.html">Spring Java Config</a>.  Here is a unit test using JUnit 4.x support from Spring Test using <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java">Java Config</a>.<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java}</plain-text-body>This is similar to the XML Config example above except that there is no XML file and instead the nested <strong><code>ContextConfig</code></strong> class does all of the configuration; so your entire test case is containe
d in a single Java class. We currently have to reference by class name this class in the <strong><code>@ContextConfiguration</code></strong> which is a bit ugly. Please vote for <a shape="rect" class="external-link" href="http://jira.springframework.org/browse/SJC-238" rel="nofollow">SJC-238</a> to address this and make Spring Test work more cleanly with Spring JavaConfig.</p><h4 id="SpringTesting-PlainSpringTestUsingJUnit4.0.xRunnerWithXMLConfig">Plain Spring Test Using JUnit 4.0.x Runner With XML Config</h4><p>You can avoid extending Spring classes by using the <strong><code>SpringJUnit4ClassRunner</code></strong> provided by Spring Test.  This custom JUnit runner means you are free to choose your own class hierarchy while retaining all the capabilities of Spring Test.</p><rich-text-body><p>This is for Spring 4.0.x. If you use Spring 4.1 or newer, then see the next section.</p></rich-text-body><parameter ac:name="language">java</parameter><plain-text-body>@RunWith(Spring
JUnit4ClassRunner.class)
@ContextConfiguration
public class MyCamelTest {
-Â Â @Autowired
-Â Â protected CamelContext camelContext;
+    @Autowired
+    protected CamelContext camelContext;
-Â Â @EndpointInject(uri = "mock:foo")
-Â Â protected MockEndpoint foo;
+    @EndpointInject(uri = "mock:foo")
+    protected MockEndpoint foo;
@Test
@DirtiesContext
-Â Â public void testMocksAreValid() throws Exception {
- // ...   Â
+    public void testMocksAreValid() throws Exception {
+ // ...       
-Â Â Â Â foo.message(0).header("bar").isEqualTo("ABC");
-Â Â Â Â MockEndpoint.assertIsSatisfied(camelContext);
-Â Â }
+        foo.message(0).header("bar").isEqualTo("ABC");
+        MockEndpoint.assertIsSatisfied(camelContext);
+    }
}
-]]></script>
-</div></div><h4 id="SpringTesting-PlainSpringTestUsingJUnit4.1.xRunnerWithXMLConfig">Plain Spring Test Using JUnit 4.1.x Runner With XML Config</h4><p>You can avoid extending Spring classes by using the <strong><code>SpringJUnit4ClassRunner</code></strong> provided by Spring Test.  This custom JUnit runner means you are free to choose your own class hierarchy while retaining all the capabilities of Spring Test.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Spring 4.1</strong>, you need to use the <strong><code>@BootstrapWith</code></strong> annotation to configure it to use Camel testing, as shown below.</p></div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@RunWith(CamelSpringJUnit4ClassRunner.class)
+</plain-text-body><h4 id="SpringTesting-PlainSpringTestUsingJUnit4.1.xRunnerWithXMLConfig">Plain Spring Test Using JUnit 4.1.x Runner With XML Config</h4><p>You can avoid extending Spring classes by using the <strong><code>SpringJUnit4ClassRunner</code></strong> provided by Spring Test.  This custom JUnit runner means you are free to choose your own class hierarchy while retaining all the capabilities of Spring Test.</p><rich-text-body><p>From <strong>Spring 4.1</strong>, you need to use the <strong><code>@BootstrapWith</code></strong> annotation to configure it to use Camel testing, as shown below.</p></rich-text-body><parameter ac:name="language">java</parameter><plain-text-body>@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class MyCamelTest {
-Â Â @Autowired
-Â Â protected CamelContext camelContext;
+    @Autowired
+    protected CamelContext camelContext;
-Â Â @EndpointInject(uri = "mock:foo")
-Â Â protected MockEndpoint foo;
+    @EndpointInject(uri = "mock:foo")
+    protected MockEndpoint foo;
@Test
@DirtiesContext
-Â Â public void testMocksAreValid() throws Exception {
- // ...   Â
+    public void testMocksAreValid() throws Exception {
+ // ...       
-Â Â Â Â foo.message(0).header("bar").isEqualTo("ABC");
-Â Â Â Â MockEndpoint.assertIsSatisfied(camelContext);
-Â Â }
+        foo.message(0).header("bar").isEqualTo("ABC");
+        MockEndpoint.assertIsSatisfied(camelContext);
+    }
}
-]]></script>
-</div></div><h3 id="SpringTesting-CamelEnhancedSpringTest"><span style="line-height: 1.5625;">Camel Enhanced Spring Test</span></h3><p>Using the <strong><code>org.apache.camel.test.junit4.CamelSpringJUnit4ClassRunner</code></strong> runner with the <strong><code>@RunWith</code></strong> annotation or extending <strong><code>org.apache.camel.testng.AbstractCamelTestNGSpringContextTests</code></strong> provides the full feature set of Spring Test with support for the feature set provided in the <strong><code>CamelTestSupport</code></strong> classes.  </p><p>A number of Camel specific annotations have been developed in order to provide for declarative manipulation of the Camel context(s) involved in the test.  These annotations free your test classes from having to inherit from the <strong><code>CamelSpringTestSupport</code></strong> classes and also reduce the amount of code required to customize the tests.</p><div class="table-wrap"><table class="conflue
nceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Annotation Class</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Applies To</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default Behavioir If Not Present</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default Behavior If Present</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.DisableJmx</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates if JMX should be globally disabled in the CamelContexts that are bootstrapped  during the test through the use of Spring Test loaded application contexts.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JMX is disabled</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JMX is disabled<
/p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.ExcludeRoutes</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates if certain route builder classes should be excluded from discovery.  Initializes a <strong><code>org.apache.camel.spi.PackageScanClassResolver</code></strong> to exclude a set of given classes from being resolved. Typically this is used at test time to exclude certain routes, which might otherwise be just noisy, from being discovered and initialized.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Not enabled and no routes are excluded</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>No routes are excluded</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.LazyLoadTypeConverters</code></p></td><td colspan="1" rowspan="1" cla
ss="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><span style="color: rgb(255,0,0);"><strong>Deprecated.</strong> </span></p><p>Indicates if the CamelContexts that are bootstrapped during the test through the use of Spring Test loaded application contexts should use lazy loading of type converters.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Type converters are not lazy loaded</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Type converters are not lazy loaded</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.MockEndpoints</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Triggers the auto-mocking of endpoints whose URIs match the provided filter.  The default filter is <strong><code>"*"</code></strong> which matches all endpoints. 
60;See <strong><code>org.apache.camel.impl.InterceptSendToMockEndpointStrategy</code></strong> for more details on the registration of the mock endpoints.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Not enabled</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>All endpoints are sniffed and recorded in a mock endpoint.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.MockEndpointsAndSkip</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Triggers the auto-mocking of endpoints whose URIs match the provided filter.  The default filter is <strong><code>"*"</code></strong>, which matches all endpoints.  See <a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java?view=mar
kup">org.apache.camel.impl.InterceptSendToMockEndpointStrategy</a> for more details on the registration of the mock endpoints.  This annotation will also skip sending the message to matched endpoints as well.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Not enabled</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>All endpoints are sniffed and recorded in a mock endpoint.  The original endpoint is not invoked.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.ProvidesBreakpoint</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Method</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates that the annotated method returns an <strong><code>org.apache.camel.spi.Breakpoint</code></strong> for use in the test.  Useful for intercepting traffic to all endpoints or simply for setting a break point in an IDE for debugging.  The me
thod must be public, static, take no arguments, and return <strong><code>org.apache.camel.spi.Breakpoint</code></strong>.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>N/A</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The returned <strong><code>Breakpoint</code></strong> is registered in the CamelContext(s)</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.ShutdownTimeout</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates to set the shutdown timeout of all CamelContexts instantiated through the use of Spring Test loaded application contexts.  If no annotation is used, the timeout is automatically reduced to 10 seconds by the test framework.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>10 seconds</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>10 se
conds</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.UseAdviceWith</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates the use of <strong><code>adviceWith()</code></strong> within the test class.  If a class is annotated with this annotation and <strong><code>UseAdviceWith#value()</code></strong> returns true, any CamelContexts bootstrapped during the test through the use of Spring Test loaded application contexts will not be started automatically. </p><p>The test author is responsible for injecting the Camel contexts into the test and executing <strong><code>CamelContext#start()</code></strong> on them at the appropriate time after any advice has been applied to the routes in the CamelContext(s).</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>CamelContexts do no
t automatically start.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>CamelContexts do not automatically start.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.UseOverridePropertiesWithPropertiesComponent</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Method</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.16:</strong>Indicates that the annotated method returns a <strong><code>java.util.Properties</code></strong> for use in the test, and that those properties override any existing properties configured on the <strong><code>PropertiesComponent</code></strong>.</p></td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd"><p>Override properties</p></td></tr></tbody></table></div><p>The following example illustrates the use of the <strong><code>@MockEndpoints</code></strong> annotation in order to se
tup mock endpoints as interceptors on all endpoints using the Camel Log component and the <strong><code>@DisableJmx</code></strong> annotation to enable JMX which is disabled during tests by default.  </p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body">Note: we still use the <strong><code>@DirtiesContext</code></strong> annotation to ensure that the CamelContext, routes, and mock endpoints are reinitialized between test methods.</div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@RunWith(CamelSpringJUnit4ClassRunner.class)
+</plain-text-body><h3 id="SpringTesting-CamelEnhancedSpringTest"><span style="line-height: 1.5625;">Camel Enhanced Spring Test</span></h3><p>Using the <strong><code>org.apache.camel.test.junit4.CamelSpringJUnit4ClassRunner</code></strong> runner with the <strong><code>@RunWith</code></strong> annotation or extending <strong><code>org.apache.camel.testng.AbstractCamelTestNGSpringContextTests</code></strong> provides the full feature set of Spring Test with support for the feature set provided in the <strong><code>CamelTestSupport</code></strong> classes.  </p><p>A number of Camel specific annotations have been developed in order to provide for declarative manipulation of the Camel context(s) involved in the test.  These annotations free your test classes from having to inherit from the <strong><code>CamelSpringTestSupport</code></strong> classes and also reduce the amount of code required to customize the tests.</p><div class="table-wrap"><table class="c
onfluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Annotation Class</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Applies To</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default Behavioir If Not Present</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default Behavior If Present</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.DisableJmx</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates if JMX should be globally disabled in the CamelContexts that are bootstrapped  during the test through the use of Spring Test loaded application contexts.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JMX is disabled</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JMX is dis
abled</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.ExcludeRoutes</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates if certain route builder classes should be excluded from discovery.  Initializes a <strong><code>org.apache.camel.spi.PackageScanClassResolver</code></strong> to exclude a set of given classes from being resolved. Typically this is used at test time to exclude certain routes, which might otherwise be just noisy, from being discovered and initialized.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Not enabled and no routes are excluded</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>No routes are excluded</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.LazyLoadTypeConverters</code></p></td><td colspan="1" rowspan="
1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><span style="color: rgb(255,0,0);"><strong>Deprecated.</strong> </span></p><p>Indicates if the CamelContexts that are bootstrapped during the test through the use of Spring Test loaded application contexts should use lazy loading of type converters.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Type converters are not lazy loaded</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Type converters are not lazy loaded</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.MockEndpoints</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Triggers the auto-mocking of endpoints whose URIs match the provided filter.  The default filter is <strong><code>"*"</code></strong> which matches all endpoint
s.  See <strong><code>org.apache.camel.impl.InterceptSendToMockEndpointStrategy</code></strong> for more details on the registration of the mock endpoints.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Not enabled</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>All endpoints are sniffed and recorded in a mock endpoint.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.MockEndpointsAndSkip</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Triggers the auto-mocking of endpoints whose URIs match the provided filter.  The default filter is <strong><code>"*"</code></strong>, which matches all endpoints.  See <a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToMockEndpointStrategy.java?vi
ew=markup">org.apache.camel.impl.InterceptSendToMockEndpointStrategy</a> for more details on the registration of the mock endpoints.  This annotation will also skip sending the message to matched endpoints as well.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Not enabled</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>All endpoints are sniffed and recorded in a mock endpoint.  The original endpoint is not invoked.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.ProvidesBreakpoint</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Method</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates that the annotated method returns an <strong><code>org.apache.camel.spi.Breakpoint</code></strong> for use in the test.  Useful for intercepting traffic to all endpoints or simply for setting a break point in an IDE for debugging. 
The method must be public, static, take no arguments, and return <strong><code>org.apache.camel.spi.Breakpoint</code></strong>.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>N/A</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The returned <strong><code>Breakpoint</code></strong> is registered in the CamelContext(s)</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.ShutdownTimeout</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates to set the shutdown timeout of all CamelContexts instantiated through the use of Spring Test loaded application contexts.  If no annotation is used, the timeout is automatically reduced to 10 seconds by the test framework.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>10 seconds</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p
>10 seconds</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.UseAdviceWith</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Class</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Indicates the use of <strong><code>adviceWith()</code></strong> within the test class.  If a class is annotated with this annotation and <strong><code>UseAdviceWith#value()</code></strong> returns true, any CamelContexts bootstrapped during the test through the use of Spring Test loaded application contexts will not be started automatically. </p><p>The test author is responsible for injecting the Camel contexts into the test and executing <strong><code>CamelContext#start()</code></strong> on them at the appropriate time after any advice has been applied to the routes in the CamelContext(s).</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>CamelContexts
do not automatically start.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>CamelContexts do not automatically start.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.test.spring.UseOverridePropertiesWithPropertiesComponent</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Method</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.16:</strong>Indicates that the annotated method returns a <strong><code>java.util.Properties</code></strong> for use in the test, and that those properties override any existing properties configured on the <strong><code>PropertiesComponent</code></strong>.</p></td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd"><p>Override properties</p></td></tr></tbody></table></div><p>The following example illustrates the use of the <strong><code>@MockEndpoints</code></strong> annotation in order
to setup mock endpoints as interceptors on all endpoints using the Camel Log component and the <strong><code>@DisableJmx</code></strong> annotation to enable JMX which is disabled during tests by default.  </p><rich-text-body>Note: we still use the <strong><code>@DirtiesContext</code></strong> annotation to ensure that the CamelContext, routes, and mock endpoints are reinitialized between test methods.</rich-text-body><parameter ac:name="language">java</parameter><plain-text-body>@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
-@MockEndpoints("log:*")
+@MockEndpoints("log:*")
@DisableJmx(false)
public class CamelSpringJUnit4ClassRunnerPlainTest {
@Autowired
@@ -256,49 +127,45 @@ public class CamelSpringJUnit4ClassRunne
protected MockEndpoint mockB;
- @EndpointInject(uri = "mock:c", context = "camelContext2")
+ @EndpointInject(uri = "mock:c", context = "camelContext2")
protected MockEndpoint mockC;
- @Produce(uri = "direct:start2", context = "camelContext2")
+ @Produce(uri = "direct:start2", context = "camelContext2")
protected ProducerTemplate start2;
- @EndpointInject(uri = "mock:log:org.apache.camel.test.junit4.spring", context = "camelContext2")
+ @EndpointInject(uri = "mock:log:org.apache.camel.test.junit4.spring", context = "camelContext2")
protected MockEndpoint mockLog;
@Test
public void testPositive() throws Exception {
- mockC.expectedBodiesReceived("David");
- mockLog.expectedBodiesReceived("Hello David");
+ mockC.expectedBodiesReceived("David");
+ mockLog.expectedBodiesReceived("Hello David");
- start2.sendBody("David");
+ start2.sendBody("David");
MockEndpoint.assertIsSatisfied(camelContext);
}
-]]></script>
-</div></div><h3 id="SpringTesting-AddingMoreMockExpectations">Adding More Mock Expectations</h3><p>If you wish to programmatically add any new assertions to your test you can easily do so with the following. Notice how we use <strong><code>@EndpointInject</code></strong> to inject a Camel endpoint into our code then the <a shape="rect" href="mock.html">Mock</a> API to add an expectation on a specific message.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@ContextConfiguration
+</plain-text-body><h3 id="SpringTesting-AddingMoreMockExpectations">Adding More Mock Expectations</h3><p>If you wish to programmatically add any new assertions to your test you can easily do so with the following. Notice how we use <strong><code>@EndpointInject</code></strong> to inject a Camel endpoint into our code then the <a shape="rect" href="mock.html">Mock</a> API to add an expectation on a specific message.</p><parameter ac:name="language">java</parameter><plain-text-body>@ContextConfiguration
public class MyCamelTest extends AbstractJUnit38SpringContextTests {
@Autowired
protected CamelContext camelContext;
- @EndpointInject(uri = "mock:foo")
+ @EndpointInject(uri = "mock:foo")
protected MockEndpoint foo;
public void testMocksAreValid() throws Exception {
// lets add more expectations
- foo.message(0).header("bar").isEqualTo("ABC");
+ foo.message(0).header("bar").isEqualTo("ABC");
MockEndpoint.assertIsSatisfied(camelContext);
}
}
-]]></script>
-</div></div><h3 id="SpringTesting-FurtherProcessingtheReceivedMessages">Further Processing the Received Messages</h3><p>Sometimes once a <a shape="rect" href="mock.html">Mock</a> endpoint has received some messages you want to then process them further to add further assertions that your test case worked as you expect.</p><p>So you can then process the received message exchanges if you like...</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@ContextConfiguration
+</plain-text-body><h3 id="SpringTesting-FurtherProcessingtheReceivedMessages">Further Processing the Received Messages</h3><p>Sometimes once a <a shape="rect" href="mock.html">Mock</a> endpoint has received some messages you want to then process them further to add further assertions that your test case worked as you expect.</p><p>So you can then process the received message exchanges if you like...</p><parameter ac:name="language">java</parameter><plain-text-body>@ContextConfiguration
public class MyCamelTest extends AbstractJUnit38SpringContextTests {
@Autowired
protected CamelContext camelContext;
- @EndpointInject(uri = "mock:foo")
+ @EndpointInject(uri = "mock:foo")
protected MockEndpoint foo;
public void testMocksAreValid() throws Exception {
@@ -314,25 +181,22 @@ public class MyCamelTest extends Abstrac
}
}
}
-]]></script>
-</div></div><h3 id="SpringTesting-SendingandReceivingMessages">Sending and Receiving Messages</h3><p>It might be that the <a shape="rect" href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a> you have defined in either <a shape="rect" href="spring.html">Spring</a> XML or using the Java <a shape="rect" href="dsl.html">DSL</a> do all of the sending and receiving and you might just work with the <a shape="rect" href="mock.html">Mock</a> endpoints as described above. However sometimes in a test case its useful to explicitly send or receive messages directly.</p><p>To send or receive messages you should use the <a shape="rect" href="bean-integration.html">Bean Integration</a> mechanism. For example to send messages inject a <strong><code>ProducerTemplate</code></strong> using the <strong><code>@EndpointInject</code></strong> annotation then call the various send methods on this object to send a message to an endpoint. To consume messages use the <
strong><code>@MessageDriven</code></strong> annotation on a method to have the method invoked when a message is received.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class Foo {
- @EndpointInject(uri = "activemq:foo.bar")
+</plain-text-body><h3 id="SpringTesting-SendingandReceivingMessages">Sending and Receiving Messages</h3><p>It might be that the <a shape="rect" href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a> you have defined in either <a shape="rect" href="spring.html">Spring</a> XML or using the Java <a shape="rect" href="dsl.html">DSL</a> do all of the sending and receiving and you might just work with the <a shape="rect" href="mock.html">Mock</a> endpoints as described above. However sometimes in a test case its useful to explicitly send or receive messages directly.</p><p>To send or receive messages you should use the <a shape="rect" href="bean-integration.html">Bean Integration</a> mechanism. For example to send messages inject a <strong><code>ProducerTemplate</code></strong> using the <strong><code>@EndpointInject</code></strong> annotation then call the various send methods on this object to send a message to an endpoint. To consume messages use the&
#160;<strong><code>@MessageDriven</code></strong> annotation on a method to have the method invoked when a message is received.</p><parameter ac:name="language">java</parameter><plain-text-body>public class Foo {
+ @EndpointInject(uri = "activemq:foo.bar")
ProducerTemplate producer;
public void doSomething() {
// lets send a message!
- producer.sendBody("<hello>world!</hello>");
+ producer.sendBody("<hello>world!</hello>");
}
- // lets consume messages from the 'cheese' queue
- @MessageDriven(uri="activemq:cheese")
+ // lets consume messages from the 'cheese' queue
+ @MessageDriven(uri="activemq:cheese")
public void onCheese(String name) {
// ...
}
}
-]]></script>
-</div></div><h3 id="SpringTesting-SeeAlso">See Also</h3><ul><li>A <a shape="rect" class="external-link" href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.java">real example test case using Mock and Spring</a> along with its <a shape="rect" class="external-link" href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml">Spring XML</a></li><li><a shape="rect" href="bean-integration.html">Bean Integration</a></li><li><a shape="rect" href="mock.html">Mock</a> endpoint</li><li><a shape="rect" href="test.html">Test</a> endpoint</li></ul></div>
+</plain-text-body><h3 id="SpringTesting-SeeAlso">See Also</h3><ul><li>A <a shape="rect" class="external-link" href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.java">real example test case using Mock and Spring</a> along with its <a shape="rect" class="external-link" href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml">Spring XML</a></li><li><a shape="rect" href="bean-integration.html">Bean Integration</a></li><li><a shape="rect" href="mock.html">Mock</a> endpoint</li><li><a shape="rect" href="test.html">Test</a> endpoint</li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/springintegration.html
==============================================================================
--- websites/production/camel/content/springintegration.html (original)
+++ websites/production/camel/content/springintegration.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css' rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css' rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js' type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: SpringIntegration
@@ -91,35 +80,28 @@
<p>The <strong>spring-integration:</strong> component provides a bridge for Camel components to talk to <a shape="rect" class="external-link" href="http://www.springsource.org/spring-integration" rel="nofollow">spring integration endpoints</a>.</p>
<p>Maven users will need to add the following dependency to their <code>pom.xml</code> for this component:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+<parameter ac:name="">xml</parameter><plain-text-body>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-integration</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></script>
-</div></div>
+</plain-text-body>
<h3 id="SpringIntegration-URIformat">URI format</h3>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+<plain-text-body>
spring-integration:defaultChannelName[?options]
-]]></script>
-</div></div>
+</plain-text-body>
<p>Where <strong>defaultChannelName</strong> represents the default channel name which is used by the Spring Integration Spring context. It will equal to the <code>inputChannel</code> name for the Spring Integration consumer and the <code>outputChannel</code> name for the Spring Integration provider.</p>
<p>You can append query options to the URI in the following format, <code>?option=value&option=value&...</code></p>
<h3 id="SpringIntegration-Options">Options</h3>
-<div class="confluenceTableSmall">
+<parameter ac:name="class">confluenceTableSmall</parameter><rich-text-body>
<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Name </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Type </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>inputChannel</code> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> String </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The Spring integration input channel name that this endpoint wants to consume from, where the specified channel name is defined in the Spring context. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>outputChannel</code> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> String </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The Spring integration output channel name that is used to send messages to the Spring integration context. </p></td></tr><t
r><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>inOut</code> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> String </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The exchange pattern that the Spring integration endpoint should use. If <code>inOut=true</code> then a reply channel is expected, either from the Spring Integration Message header or configured on the endpoint. </p></td></tr></tbody></table></div>
-</div>
-
-
-
+</rich-text-body>
<h3 id="SpringIntegration-Usage">Usage</h3>
@@ -130,83 +112,13 @@ spring-integration:defaultChannelName[?o
<h4 id="SpringIntegration-UsingtheSpringintegrationendpoint">Using the Spring integration endpoint</h4>
<p>You can set up a Spring integration endpoint using a URI, as follows: </p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<beans:beans xmlns="http://www.springframework.org/schema/integration"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
-
- <!-- spring integration channels -->
- <channel id="inputChannel"/>
- <channel id="outputChannel"/>
- <channel id="onewayChannel"/>
-
- <!-- spring integration service activators -->
- <service-activator input-channel="inputChannel" ref="helloService" method="sayHello"/>
- <service-activator input-channel="onewayChannel" ref="helloService" method="greet"/>
-
- <!-- custom bean -->
- <beans:bean id="helloService" class="org.apache.camel.component.spring.integration.HelloWorldService"/>
-
- <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:twowayMessage"/>
- <to uri="spring-integration:inputChannel?inOut=true&amp;inputChannel=outputChannel"/>
- </route>
- <route>
- <from uri="direct:onewayMessage"/>
- <to uri="spring-integration:onewayChannel?inOut=false"/>
- </route>
- </camelContext>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring-integration/src/test/resources/org/apache/camel/component/spring/integration/producer.xml}</plain-text-body>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<!-- spring integration channels -->
-<channel id="requestChannel"/>
-<channel id="responseChannel"/>
-
-<!-- cusom Camel processor -->
-<beans:bean id="myProcessor" class="org.apache.camel.component.spring.integration.MyProcessor"/>
-
-<!-- Camel route -->
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="spring-integration://requestChannel?outputChannel=responseChannel&amp;inOut=true"/>
- <process ref="myProcessor"/>
- </route>
-</camelContext>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring-integration/src/test/resources/org/apache/camel/component/spring/integration/twoWayConsumer.xml}</plain-text-body>
<p>Or directly using a Spring integration channel name:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<beans:beans xmlns="http://www.springframework.org/schema/integration"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
-
- <!-- spring integration channel -->
- <channel id="outputChannel"/>
-
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="outputChannel"/>
- <to uri="mock:result"/>
- </route>
- </camelContext>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring-integration/src/test/resources/org/apache/camel/component/spring/integration/springChannelConverter.xml}</plain-text-body>
<h4 id="SpringIntegration-TheSourceandTargetadapter">The Source and Target adapter</h4>
@@ -214,97 +126,16 @@ spring-integration:defaultChannelName[?o
<p>This example uses the following namespaces:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<beans:beans xmlns="http://www.springframework.org/schema/integration"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:camel-si="http://camel.apache.org/schema/spring/integration"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
- http://camel.apache.org/schema/spring/integration http://camel.apache.org/schema/spring/integration/camel-spring-integration.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
- ">
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=header|lang=xml|url=camel/trunk/components/camel-spring-integration/src/test/resources/org/apache/camel/component/spring/integration/adapter/CamelTarget.xml}</plain-text-body>
<p>You can bind your source or target to a Camel endpoint as follows:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<!-- Create the camel context here -->
-<camelContext id="camelTargetContext" xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:EndpointA" />
- <to uri="mock:result" />
- </route>
- <route>
- <from uri="direct:EndpointC"/>
- <process ref="myProcessor"/>
- </route>
-</camelContext>
-
-<!-- We can bind the camelTarget to the camel context's endpoint by specifying the camelEndpointUri attribute -->
-<camel-si:camelTarget id="camelTargetA" camelEndpointUri="direct:EndpointA" expectReply="false">
- <camel-si:camelContextRef>camelTargetContext</camel-si:camelContextRef>
-</camel-si:camelTarget>
-
-<camel-si:camelTarget id="camelTargetB" camelEndpointUri="direct:EndpointC" replyChannel="channelC" expectReply="true">
- <camel-si:camelContextRef>camelTargetContext</camel-si:camelContextRef>
-</camel-si:camelTarget>
-
-<camel-si:camelTarget id="camelTargetD" camelEndpointUri="direct:EndpointC" expectReply="true">
- <camel-si:camelContextRef>camelTargetContext</camel-si:camelContextRef>
-</camel-si:camelTarget>
+<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring-integration/src/test/resources/org/apache/camel/component/spring/integration/adapter/CamelTarget.xml}</plain-text-body>
-<beans:bean id="myProcessor" class="org.apache.camel.component.spring.integration.MyProcessor"/>
-]]></script>
-</div></div>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<!-- spring integration channels -->
-<channel id="channelA"/>
-<channel id="channelB"/>
-<channel id="channelC"/>
-
-<!-- spring integration service activator -->
-<service-activator input-channel="channelB" output-channel="channelC" ref="helloService" method="sayHello"/>
-
-<!-- custom bean -->
-<beans:bean id="helloService" class="org.apache.camel.component.spring.integration.HelloWorldService"/>
-
-<camelContext id="camelSourceContext" xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:OneWay"/>
- <to uri="direct:EndpointB"/>
- </route>
- <route>
- <from uri="direct:TwoWay"/>
- <to uri="direct:EndpointC"/>
- </route>
-</camelContext>
-
-<!-- camelSource will redirect the message coming for direct:EndpointB to the spring requestChannel channelA -->
-<camel-si:camelSource id="camelSourceA" camelEndpointUri="direct:EndpointB"
- requestChannel="channelA" expectReply="false">
- <camel-si:camelContextRef>camelSourceContext</camel-si:camelContextRef>
-</camel-si:camelSource>
-
-<!-- camelSource will redirect the message coming for direct:EndpointC to the spring requestChannel channelB
- then it will pull the response from channelC and put the response message back to direct:EndpointC -->
-
-<camel-si:camelSource id="camelSourceB" camelEndpointUri="direct:EndpointC"
- requestChannel="channelB" replyChannel="channelC" expectReply="true">
- <camel-si:camelContextRef>camelSourceContext</camel-si:camelContextRef>
-</camel-si:camelSource>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring-integration/src/test/resources/org/apache/camel/component/spring/integration/adapter/CamelSource.xml}</plain-text-body>
-<h3 id="SpringIntegration-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a shape="rect" href="component.html">Component</a></li><li><a shape="rect" href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li></ul></div>
+<parameter ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See Also</a></parameter></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/sql-example.html
==============================================================================
--- websites/production/camel/content/sql-example.html (original)
+++ websites/production/camel/content/sql-example.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css' rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css' rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js' type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js' type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: SQL Example
@@ -93,11 +82,9 @@
There is a <code>README.txt</code> file with instructions how to run it.</p>
<p>If you use maven then you can easily compile and install the example from the command line:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+<plain-text-body>
mvn install
-]]></script>
-</div></div>
+</plain-text-body>
<h3 id="SQLExample-About">About</h3>
@@ -110,93 +97,26 @@ The second route pickup the newly insert
<p>In the <code>camel-context.xml</code> file in the <code>src/main/resources/META-INF/spring</code> folder we have the Spring XML file to setup and configure the database, as well the <a shape="rect" href="camelcontext.html">CamelContext</a>.</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Setting up database</b></div><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<!-- this is the JDBC data source which uses an in-memory only Apache Derby database -->
-<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
- <property name="url" value="jdbc:derby:memory:orders;create=true"/>
- <property name="username" value=""/>
- <property name="password" value=""/>
-</bean>
-
-<!-- bean which creates/destroys the database table for this example -->
-<bean id="initDatabase" class="org.apache.camel.example.sql.DatabaseBean"
- init-method="create" destroy-method="destroy">
- <property name="dataSource" ref="dataSource"/>
-</bean>
-
-<!-- configure the Camel SQL component to use the JDBC data source -->
-<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
- <property name="dataSource" ref="dataSource"/>
-</bean>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e1|lang=xml|title=Setting up database|url=camel/trunk/examples/camel-example-sql/src/main/resources/META-INF/spring/camel-context.xml}</plain-text-body>
<p>And then in the same file we setup our Camel application. At first we have a orderBean that we use in the routes to generate new orders and process orders as well.</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Camel application</b></div><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<!-- order bean is our business logic bean that creates new orders -->
-<bean id="orderBean" class="org.apache.camel.example.sql.OrderBean"/>
-
-<!-- here is Camel configured with a number of routes -->
-<camelContext xmlns="http://camel.apache.org/schema/spring">
-
- <!-- use Camel property placeholder loaded from the given file -->
- <propertyPlaceholder id="placeholder" location="classpath:sql.properties"/>
-
- <!-- route that generate new orders and insert them in the database -->
- <route id="generateOrder-route">
- <from uri="timer:foo?period=5s"/>
- <transform>
- <method ref="orderBean" method="generateOrder"/>
- </transform>
- <to uri="sql:{{sql.insertOrder}}"/>
- <log message="Inserted new order ${body[id]}"/>
- </route>
-
- <!-- route that process the orders by picking up new rows from the database
- and when done processing then update the row to mark it as processed -->
- <route id="processOrder-route">
- <from uri="sql:{{sql.selectOrder}}?onConsume={{sql.markOrder}}"/>
- <to uri="bean:orderBean?method=processOrder"/>
- <log message="${body}"/>
- </route>
-
-</camelContext>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e2|lang=xml|title=Camel application|url=camel/trunk/examples/camel-example-sql/src/main/resources/META-INF/spring/camel-context.xml}</plain-text-body>
<p>Notice how we have externalized the SQL queries, and use Camels <a shape="rect" href="using-propertyplaceholder.html">property placeholder</a> to refer to the <code>sql.properties</code> file.</p>
-<div class="confluence-information-macro confluence-information-macro-information"><p class="title">Using named query parameters</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
+<parameter ac:name="title">Using named query parameters</parameter><rich-text-body>
<p>Notice in the SQL queries below we use named parameters which must start with prefix ':#' and then the name, eg :#amount. Then Camel will bind that parameter with the given name, from the<br clear="none">
-message body (if its a <code>java.util.Map</code>) or from a message header with the name. If none parameter could be found, Camel throws an exception.</p></div></div>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>SQL queries</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-## notice we use named parameters in the queries, eg :#name. A named query parameter must start with :#
-## sql that insert new orders
-sql.insertOrder=insert into orders (id, item, amount, description, processed) values (:#id, :#item, :#amount, :#description, false)
+message body (if its a <code>java.util.Map</code>) or from a message header with the name. If none parameter could be found, Camel throws an exception.</p></rich-text-body>
-## sql that select all unprocessed orders
-sql.selectOrder=select * from orders where processed = false
-
-## sql that update the order as being processed
-sql.markOrder=update orders set processed = true where id = :#id
-
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e1|title=SQL queries|url=camel/trunk/examples/camel-example-sql/src/main/resources/sql.properties}</plain-text-body>
<h3 id="SQLExample-Runningtheexample">Running the example</h3>
<p>This example can be run from the command line</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+<plain-text-body>
mvn camel:run
-]]></script>
-</div></div>
+</plain-text-body>
<p>Press ctrl + c to stop the example.</p>