camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r982196 - in /websites/production/camel/content: cache/main.pageCache cdi-testing.html
Date Tue, 08 Mar 2016 10:19:20 GMT
Author: buildbot
Date: Tue Mar  8 10:19:20 2016
New Revision: 982196

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 10:19:20 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 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">
+<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 a target containers. 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/modules/descriptors-shrinkwrap/" rel="nofollow">ShrinkWrap
Descriptors</a>. The benefit is that you have a ver
 y 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></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;
@@ -107,7 +107,49 @@ public class CamelCdiRunnerTest {
             is(equalTo(ServiceStatus.Started)));
     }
 }]]></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);"><br clear="none"></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);">CDI injection is
also available for test method parameters, 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(CamelCdiRunner.class)
+public class CamelCdiRunnerTest {
+
+    @Test
+    public void test(@Uri(&quot;direct:foo&quot;) ProducerTemplate producer) {
+        producer.sendBody(&quot;bar&quot;);
+    }
+}]]></script>
+</div></div><p><span style="color: rgb(0,0,0);">Camel CDI test provides
the&#160;</span><code style="color: rgb(0,0,0);">@Order</code><span
style="color: rgb(0,0,0);"> annotation that you can use to execute the test methods in
a particular sequence, e.g.:</span><span style="color: rgb(0,0,0);">&#160;</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(CamelCdiRunner.class)
+public class CamelCdiRunnerTest {
+ 
+    @Test
+    @Order(1)
+    public void firstTestMethod() {
+    }
+ 
+    @Test
+    @Order(2)
+    public void secondTestMethod() {
+    }
+}]]></script>
+</div></div><p><span style="color: rgb(0,0,0);">One CDI container
is bootstrapped for the entire execution of the test class.&#160;</span></p><p><span
style="color: rgb(0,0,0);">Besides, the test class is deployed as a CDI bean, so that you
can control how the runner instantiate the test class, either one test class instance for
each test method (the default, depending on the built-in default&#160;<code>@Dependent</code>&#160;CDI
scope), or one test class instance for the entire test class execution using the&#160;<code>@ApplicationScoped</code>&#160;scope,
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[@ApplicationScoped
+@RunWith(CamelCdiRunner.class)
+public class CamelCdiRunnerTest {
+ 
+    int counter;
+
+    @Test
+    @Order(1)
+    public void firstTestMethod() {
+        counter++;
+    }
+ 
+    @Test
+    @Order(2)
+    public void secondTestMethod() {
+        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">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@RunWith(Arquillian.class)
 public class CamelCdiJavaSeTest {
 
@@ -132,7 +174,7 @@ public class CamelCdiJavaSeTest {
             is(equalTo(ServiceStatus.Started)));
     }
 }]]></script>
-</div></div><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</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 {
 
@@ -151,7 +193,7 @@ public class CamelCdiWebTest {
             is(equalTo(&quot;Hello World!\n&quot;)));
     }
 }]]></script>
-</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">
+</div></div><p>&#160;</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>adviceWit
 h</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 {
@@ -164,7 +206,7 @@ public class CamelCdiWebTest {
             }
         });
 }]]></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>
+</div></div><h4 id="CDITesting-JUnitrules"><span style="color: rgb(0,0,0);">JUnit
rules</span></h4><p><span style="color: rgb(0,0,0);">Camel CDI test
starts the CDI container after all the JUnit class rules.</span></p><h3 id="CDITesting-SeeAlso">See
Also</h3><ul><li><a shape="rect" href="cdi.html">CDI component</a></li><li><a
shape="rect" class="external-link" href="http://arquillian.org" rel="nofollow">Arquillian
Web site</a></li><li><a shape="rect" class="external-link" href="http://arquillian.org/modules/descriptors-shrinkwrap/"
rel="nofollow">ShrinkWrap Descriptors</a></li></ul></div>
         </td>
         <td valign="top">
           <div class="navigation">



Mime
View raw message