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 2016/03/07 16:19:46 UTC

svn commit: r982097 - in /websites/production/camel/content: cache/main.pageCache cdi-testing.html

Author: buildbot
Date: Mon Mar  7 15:19:46 2016
New Revision: 982097

Log:
Production update by buildbot for camel

Modified:
    websites/production/camel/content/cache/main.pageCache
    websites/production/camel/content/cdi-testing.html

Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/camel/content/cdi-testing.html
==============================================================================
--- websites/production/camel/content/cdi-testing.html (original)
+++ websites/production/camel/content/cdi-testing.html Mon Mar  7 15:19:46 2016
@@ -85,7 +85,7 @@
 	<tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><p><a shape="rect" class="external-link" href="http://camel.apache.org/testing.html">Testing</a><span style="color: rgb(0,0,0);">&#160;is a crucial part of any development or integration work. In case you're using the Camel CDI integration for your applications, you have a number of options to ease testing.</span></p><p><span style="color: rgb(0,0,0);">You can use CDI for IoC and the Camel testing endpoints like <code><a shape="rect" href="dataset.html">DataSet</a></code>,&#160;</span><code><a shape="rect" class="external-link" href="http://camel.apache.org/mock.html">Mock</a></code><span style="color: rgb(0,0,0);">,&#160;</span><code><a shape="rect" class="external-link" href="http://camel.apache.org/test.html">Test</a></code>&#160;and testing API like&#160;<code><a shape="rect" href="advicewith.html">AdviceWith</a></code> and&#160;<code><a shape="rect" href="notifybuilder.html">NotifyBuilder</a></code>&#160;<span style="color: rgb(0,0,0);">to 
 create sophisticated integration/unit tests that are easy to run and debug inside your IDE.</span></p><p><span style="color: rgb(0,0,0);">There are two supported approaches for testing with CDI in Camel:</span></p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Name</th><th colspan="1" rowspan="1" class="confluenceTh">Testing Frameworks Supported</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">Camel CDI Test</td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The Camel CDI test module ({{camel-test-cdi}}) comes with a JUnit that you can use to delegate all</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">Arquillian</td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4</li><li>TestNG 5</li></ul></td><td colspan="1" rowspan="1" 
 class="confluenceTd">Arquillian is a testing platform that handles all the plumbing of in-container testing with support for a wide range a target runtime</td></tr></tbody></table></div><h3 id="CDITesting-CamelCDITest">Camel CDI Test</h3><p>With this approach, your test classes use the JUnit test runner provided in Camel CDI test. This runner manages the lifecycle of a standalone CDI container and automatically assemble and deploy the System Under Test (SUT) based on the <em>classpath</em> into the container.</p><p>It deploys the test class as a CDI bean so that dependency injection and any CDI features is available within the test class.</p><p><span style="color: rgb(0,0,0);">Maven users will need to add the following dependency to their&#160;</span><code>pom.xml</code><span style="color: rgb(0,0,0);">&#160;for this component:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<div class="wiki-content maincontent"><p><a shape="rect" class="external-link" href="http://camel.apache.org/testing.html">Testing</a><span style="color: rgb(0,0,0);">&#160;is a crucial part of any development or integration work. In case you're using the Camel CDI integration for your applications, you have a number of options to ease testing.</span></p><p><span style="color: rgb(0,0,0);">You can use CDI for IoC and the Camel testing endpoints like <code><a shape="rect" href="dataset.html">DataSet</a></code>,&#160;</span><code><a shape="rect" class="external-link" href="http://camel.apache.org/mock.html">Mock</a></code><span style="color: rgb(0,0,0);">,&#160;</span><code><a shape="rect" class="external-link" href="http://camel.apache.org/test.html">Test</a></code>&#160;and testing API like&#160;<code><a shape="rect" href="advicewith.html">AdviceWith</a></code> and&#160;<code><a shape="rect" href="notifybuilder.html">NotifyBuilder</a></code>&#160;<span style="color: rgb(0,0,0);">to 
 create sophisticated integration/unit tests that are easy to run and debug inside your IDE.</span></p><p><span style="color: rgb(0,0,0);">There are two supported approaches for testing with CDI in Camel:</span></p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Name</th><th colspan="1" rowspan="1" class="confluenceTh">Testing Frameworks Supported</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">Camel CDI Test</td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Available as of Camel 2.17</strong></p><p>The Camel CDI test module (<code>camel-test-cdi</code>) provides a JUnit that you can use to</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">Arquillian</td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4</li><li>TestNG 
 5</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd">Arquillian is a testing platform that handles all the plumbing of in-container testing with support for a wide range a target containers.</td></tr></tbody></table></div><h3 id="CDITesting-CamelCDITest">Camel CDI Test</h3><p>With this approach, your test classes use the JUnit test runner provided in Camel CDI test. This runner manages the lifecycle of a standalone CDI container and automatically assemble and deploy the System Under Test (SUT) based on the <em>classpath</em> into the container.</p><p>It deploys the test class as a CDI bean so that dependency injection and any CDI features is available within the test class.</p><p><span style="color: rgb(0,0,0);">Maven users will need to add the following dependency to their&#160;</span><code>pom.xml</code><span style="color: rgb(0,0,0);">&#160;for this component:</span></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[&lt;dependency&gt;
     &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
     &lt;artifactId&gt;camel-test-cdi&lt;/artifactId&gt;
@@ -93,7 +93,7 @@
     &lt;version&gt;x.x.x&lt;/version&gt;
     &lt;!-- use the same version as your Camel core version --&gt;
 &lt;/dependency&gt;]]></script>
-</div></div><p><span style="color: rgb(0,0,0);"><span style="color: rgb(0,0,0);">Here is a simple unit test using the&#160;</span></span><code>CamelCdiRunner</code>:</p><p><span style="color: rgb(0,0,0);"><span style="color: rgb(0,0,0);">&#160;</span></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p><span style="color: rgb(0,0,0);"><span style="color: rgb(0,0,0);">Here is a simple unit test using the&#160;</span></span><code>CamelCdiRunner</code>:</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[@RunWith(CamelCdiRunner.class)
 public class CamelCdiRunnerTest {
 
@@ -107,7 +107,7 @@ public class CamelCdiRunnerTest {
             is(equalTo(ServiceStatus.Started)));
     }
 }]]></script>
-</div></div><p><span style="color: rgb(0,0,0);"><br clear="none"></span></p><p><span style="color: rgb(0,0,0);"><br clear="none"></span></p><h3 id="CDITesting-Arquillian"><span style="color: rgb(0,0,0);">Arquillian</span></h3><p><span style="color: rgb(0,0,0);"><br clear="none"></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h3 id="CDITesting-Arquillian"><span style="color: rgb(0,0,0);">Arquillian</span></h3><p><span style="color: rgb(0,0,0);"><br clear="none"></span></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[@RunWith(Arquillian.class)
 public class CamelCdiJavaSeTest {
 
@@ -151,7 +151,20 @@ public class CamelCdiWebTest {
             is(equalTo(&quot;Hello World!\n&quot;)));
     }
 }]]></script>
-</div></div><p>&#160;</p><p>&#160;</p></div>
+</div></div><p>&#160;</p><h3 id="CDITesting-Testpatterns">Test patterns</h3><h4 id="CDITesting-RoutesadvisingwithadviceWith"><span style="color: rgb(0,0,0);">Routes advising with <code>adviceWith</code></span></h4><p><span style="color: rgb(0,0,0);"><span><code><a shape="rect" href="advicewith.html">AdviceWith</a></code> is used for testing Camel routes where you can&#160;</span><em>advice</em><span>&#160;an existing route before its being tested. It allows to add&#160;<a shape="rect" class="external-link" href="http://camel.apache.org/intercept.html">Intercept</a>&#160;or <em>weave</em> routes for testing purpose, for example using the&#160;<a shape="rect" href="mock.html">Mock</a>&#160;component</span><span>.</span></span></p><p><span style="color: rgb(0,0,0);">It is recommended to only advice routes which are not started already. To meet that requirement, you can use the&#160;</span><code>CamelContextStartingEvent</code> event by declaring an observer method in which you use <cod
 e>adviceWith</code> to add a <code>mock</code> endpoint at the end of your Camel route<span style="color: rgb(0,0,0);">, e.g.:</span></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[void advice(@Observes CamelContextStartingEvent event,
+            @Uri(&quot;mock:test&quot;) MockEndpoint messages,
+            ModelCamelContext context) throws Exception {
+
+    context.getRouteDefinition(&quot;route&quot;)
+        .adviceWith(context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() {
+                weaveAddLast().to(&quot;mock:test&quot;);
+            }
+        });
+}]]></script>
+</div></div><p><span style="color: rgb(0,0,0);"><br clear="none"></span></p><h3 id="CDITesting-SeeAlso">See Also</h3><ul><li><a shape="rect" class="external-link" href="http://www.cdi-spec.org" rel="nofollow">CDI Web site</a></li><li><a shape="rect" class="external-link" href="http://www.cdi-spec.org/ecosystem/" rel="nofollow">CDI ecosystem</a></li><li><a shape="rect" class="external-link" href="https://github.com/astefanutti/further-cdi" rel="nofollow">Going further with CDI</a>&#160;(See Camel CDI section)</li></ul></div>
         </td>
         <td valign="top">
           <div class="navigation">