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/08 16:19:38 UTC

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

Author: buildbot
Date: Tue Mar  8 15:19:38 2016
New Revision: 982220

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 Tue Mar  8 15:19:38 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><strong>Available as of Camel 2.17</strong></p><p>The Camel CDI test module (<code>camel-test-cdi</code>) provides a JUnit runner that bootstraps a test environment using CDI so that you don't have to be familiar with any CDI testing frameworks and can concentrate on the testing logic of your Camel CDI 
 applications.</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"><a shape="rect" class="external-link" href="http://arquillian.org/" rel="nofollow">Arquillian</a> is a testing platform that handles all the plumbing of in-container testing with support for a wide range of <a shape="rect" class="external-link" href="http://arquillian.org/modules/" rel="nofollow">target containers</a>. Arquillian can be configured to run your test classes in <em>embedded</em> (in JVM CDI), <em>managed</em> (a real Web server or Java EE application server instance started in a separate process) or <em>remote</em> (the lifecycle of the container isn't managed by Arquillian) modes. You have to create the System Under Test (SUT) in your test classes using <a shape="rect" class="external-link" href="http://arquillian.org/guides/shrinkw
 rap_introduction/" rel="nofollow">ShrinkWrap Descriptors</a>. The benefit is that you have a very fine-grained control over the application configuration that you want to test. The downside is more code and more complex <em>classpath</em> / class loading structure.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">PAX Exam</td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4</li><li>TestNG 6</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4" rel="nofollow">PAX Exam</a> lets you test your Camel applications in OSGi, Java EE or standalone CDI containers with the ability to finely configured your <span>System Under Test (SUT),</span> <span>Similarly to Arquillian. You can use it to test your Camel CDI applications that target OSGi environments like Karaf with <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXCDI/Pax+CDI" re
 l="nofollow">PAX CDI</a>, but you can use it as well to test your Camel CDI applications in standalone <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4/CDI+Containers" rel="nofollow">CDI containers</a>, <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4/Web+Containers" rel="nofollow">Web containers</a> and <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4/Java+EE+Containers" rel="nofollow">Java EE containers</a>.</span></td></tr></tbody></table></div><h3 id="CDITesting-CamelCDITest">Camel CDI Test</h3><p>With this approach, your test classes use the JUnit 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 a number of 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"><a shape="rect" href="#CDITesting-CamelCDITest">Camel CDI Test</a></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 runner that bootstraps a test environment using CDI so that you don't have to be familiar with any CDI testing frameworks
  and can concentrate on the testing logic of your Camel CDI applications.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><a shape="rect" href="#CDITesting-Arquillian">Arquillian</a></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"><a shape="rect" class="external-link" href="http://arquillian.org/" rel="nofollow">Arquillian</a> is a testing platform that handles all the plumbing of in-container testing with support for a wide range of <a shape="rect" class="external-link" href="http://arquillian.org/modules/" rel="nofollow">target containers</a>. Arquillian can be configured to run your test classes in <em>embedded</em> (in JVM CDI), <em>managed</em> (a real Web server or Java EE application server instance started in a separate process) or <em>remote</em> (the lifecycle of the container isn't managed by Arquillian) modes. You have to create the System Under Test (SU
 T) in your test classes using <a shape="rect" class="external-link" href="http://arquillian.org/guides/shrinkwrap_introduction/" rel="nofollow">ShrinkWrap descriptors</a>. The benefit is that you have a very fine-grained control over the application configuration that you want to test. The downside is more code and more complex <em>classpath</em> / class loading structure.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><a shape="rect" href="#CDITesting-PAXExam">PAX Exam</a></td><td colspan="1" rowspan="1" class="confluenceTd"><ul><li>JUnit 4</li><li>TestNG 6</li></ul></td><td colspan="1" rowspan="1" class="confluenceTd"><a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4" rel="nofollow">PAX Exam</a> lets you test your Camel applications in OSGi, Java EE or standalone CDI containers with the ability to finely configure your <span>System Under Test (SUT),</span> s<span>imilarly to Arquillian. You can use it to test your Camel CDI ap
 plications that target OSGi environments like Karaf with <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXCDI/Pax+CDI" rel="nofollow">PAX CDI</a>, but you can use it as well to test your Camel CDI applications in standalone <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4/CDI+Containers" rel="nofollow">CDI containers</a>, <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4/Web+Containers" rel="nofollow">Web containers</a> and <a shape="rect" class="external-link" href="https://ops4j1.jira.com/wiki/display/PAXEXAM4/Java+EE+Containers" rel="nofollow">Java EE containers</a>.</span></td></tr></tbody></table></div><h3 id="CDITesting-CamelCDITest">Camel CDI Test</h3><p>With this approach, your test classes use the JUnit 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;
@@ -149,7 +149,7 @@ public class CamelCdiRunnerTest {
         assertEquals(counter, 1);
     }
 }]]></script>
-</div></div><h3 id="CDITesting-Arquillian"><span style="color: rgb(0,0,0);">Arquillian</span></h3><p><span style="color: rgb(0,0,0);">With this approach, you use the JUnit runner or TestNG support provided by Arquillian to delegate the bootstrap of the CDI container. You need to declare a&#160;<code>@Deployment</code> method to create your application configuration to be deployed in the container using <a shape="rect" class="external-link" href="http://arquillian.org/modules/descriptors-shrinkwrap/" rel="nofollow">ShrinkWrap Descriptors</a>, e.g.:</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);">With this approach, you use the JUnit runner or TestNG support provided by Arquillian to delegate the bootstrap of the CDI container. You need to declare a&#160;<code>@Deployment</code> method to create your application configuration to be deployed in the container using <a shape="rect" class="external-link" href="http://arquillian.org/guides/shrinkwrap_introduction/" rel="nofollow">ShrinkWrap descriptors</a>, 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[@RunWith(Arquillian.class)
 public class CamelCdiJavaSeTest {
 
@@ -174,6 +174,35 @@ public class CamelCdiJavaSeTest {
             is(equalTo(ServiceStatus.Started)));
     }
 }]]></script>
+</div></div><p>In that example, you can use any Java SE Arquillian embedded container adapter, like the <a shape="rect" class="external-link" href="http://arquillian.org/modules/arquillian-weld-se-embedded-1.1-container-adapter/" rel="nofollow">Weld embedded container adapter</a> e.g. with Maven you need that complete set of dependencies:</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;dependencies&gt;
+
+    &lt;dependency&gt;
+      &lt;groupId&gt;org.jboss.arquillian.junit&lt;/groupId&gt;
+      &lt;artifactId&gt;arquillian-junit-container&lt;/artifactId&gt;
+      &lt;scope&gt;test&lt;/scope&gt;
+    &lt;/dependency&gt;
+
+    &lt;dependency&gt;
+      &lt;groupId&gt;org.jboss.shrinkwrap.descriptors&lt;/groupId&gt;
+      &lt;artifactId&gt;shrinkwrap-descriptors-depchain&lt;/artifactId&gt;
+      &lt;type&gt;pom&lt;/type&gt;
+      &lt;scope&gt;test&lt;/scope&gt;
+    &lt;/dependency&gt;
+
+    &lt;dependency&gt;
+      &lt;groupId&gt;org.jboss.arquillian.container&lt;/groupId&gt;
+      &lt;artifactId&gt;arquillian-weld-se-embedded-1.1&lt;/artifactId&gt;
+      &lt;scope&gt;test&lt;/scope&gt;
+    &lt;/dependency&gt;
+
+    &lt;dependency&gt;
+      &lt;groupId&gt;org.jboss.weld&lt;/groupId&gt;
+      &lt;artifactId&gt;weld-core&lt;/artifactId&gt;
+      &lt;scope&gt;test&lt;/scope&gt;
+    &lt;/dependency&gt;
+
+&lt;/dependencies&gt;]]></script>
 </div></div><p>Using ShrinkWarp Descriptors, you have a complete control over the configuration and kind of Camel CDI applications you want to test. For example, to test a Camel CDI application that uses the Camel <a shape="rect" href="rest-dsl.html">REST DSL</a> configured with the <a shape="rect" href="servlet.html">Servlet component</a>, you need to create a Web archive, e.g.:</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 CamelCdiWebTest {
@@ -193,7 +222,54 @@ public class CamelCdiWebTest {
             is(equalTo(&quot;Hello World!\n&quot;)));
     }
 }]]></script>
-</div></div><h3 id="CDITesting-PAXExam">PAX Exam</h3><p>If your target OSGi as runtime environment for your Camel CDI applications, you can use PAX Exam to automate the deployment of your tests into an OSGi container, for example into Karaf, e.g.:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>In the example above,&#160;you can use any Arquillian Web container adapter, like the&#160;<a shape="rect" class="external-link" href="http://arquillian.org/modules/arquillian-jetty-embedded-9-container-adapter/" rel="nofollow">Jetty embedded container adapter</a>&#160;e.g. with Maven you need the complete&#160;following set of dependencies:</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;/dependencies&gt;
+ 
+  &lt;dependency&gt;
+    &lt;groupId&gt;org.jboss.arquillian.junit&lt;/groupId&gt;
+    &lt;artifactId&gt;arquillian-junit-container&lt;/artifactId&gt;
+    &lt;scope&gt;test&lt;/scope&gt;
+  &lt;/dependency&gt;
+
+  &lt;dependency&gt;
+    &lt;groupId&gt;org.jboss.arquillian.testenricher&lt;/groupId&gt;
+    &lt;artifactId&gt;arquillian-testenricher-resource&lt;/artifactId&gt;
+    &lt;scope&gt;test&lt;/scope&gt;
+  &lt;/dependency&gt;
+
+  &lt;dependency&gt;
+    &lt;groupId&gt;org.jboss.shrinkwrap.descriptors&lt;/groupId&gt;
+    &lt;artifactId&gt;shrinkwrap-descriptors-depchain&lt;/artifactId&gt;
+    &lt;type&gt;pom&lt;/type&gt;
+    &lt;scope&gt;test&lt;/scope&gt;
+  &lt;/dependency&gt;
+
+  &lt;dependency&gt;
+    &lt;groupId&gt;org.jboss.weld.servlet&lt;/groupId&gt;
+    &lt;artifactId&gt;weld-servlet&lt;/artifactId&gt;
+    &lt;scope&gt;test&lt;/scope&gt;
+  &lt;/dependency&gt;
+ 
+  &lt;dependency&gt;
+    &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
+    &lt;artifactId&gt;jetty-webapp&lt;/artifactId&gt;
+    &lt;scope&gt;test&lt;/scope&gt;
+  &lt;/dependency&gt;
+
+  &lt;dependency&gt;
+    &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
+    &lt;artifactId&gt;jetty-annotations&lt;/artifactId&gt;
+    &lt;scope&gt;test&lt;/scope&gt;
+  &lt;/dependency&gt;
+
+  &lt;dependency&gt;
+    &lt;groupId&gt;org.jboss.arquillian.container&lt;/groupId&gt;
+    &lt;artifactId&gt;arquillian-jetty-embedded-9&lt;/artifactId&gt;
+    &lt;scope&gt;test&lt;/scope&gt;
+  &lt;/dependency&gt;
+
+&lt;/dependencies&gt;]]></script>
+</div></div><p>You can see the tests in<span style="color: rgb(0,0,0);">&#160;the&#160;</span><span style="color: rgb(0,0,0);"><code>camel-example-cdi-rest-servlet</code>&#160;example for a complete working example of testing a Camel CDI application using the REST DSL and deployed as a WAR in Jetty.</span></p><h3 id="CDITesting-PAXExam">PAX Exam</h3><p>If you target OSGi as runtime environment for your Camel CDI applications, you can use PAX Exam to automate the deployment of your tests into an OSGi container, for example into Karaf, e.g.:</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(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class PaxCdiOsgiTest {
@@ -239,7 +315,7 @@ public class PaxCdiOsgiTest {
 }
 
 ]]></script>
-</div></div><p>You can see the tests in<span style="color: rgb(0,0,0);">&#160;the&#160;</span><span style="color: rgb(0,0,0);"><code>camel-example-cdi-osgi</code>&#160;example for a complete working example of testing a Camel CDI application deployed in an OSGi container using PAX Exam.</span></p><h3 id="CDITesting-Testing">Testing</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 <code>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">
+</div></div><p>You can see the tests in<span style="color: rgb(0,0,0);">&#160;the&#160;</span><span style="color: rgb(0,0,0);"><code>camel-example-cdi-osgi</code>&#160;example for a complete working example of testing a Camel CDI application deployed in an OSGi container using PAX Exam.</span></p><h3 id="CDITesting-Testing">Testing</h3><p>You can see the tests in<span style="color: rgb(0,0,0);">&#160;the&#160;</span><span style="color: rgb(0,0,0);"><code>camel-example-cdi-test</code>&#160;example for a thorough overview of the following testing patterns for Camel CDI applications.</span></p><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 <code>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 {