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/10 16:19:08 UTC
svn commit: r982395 - in /websites/production/camel/content:
cache/main.pageCache cdi-testing.html
Author: buildbot
Date: Thu Mar 10 15:19:06 2016
New Revision: 982395
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 Thu Mar 10 15:19:06 2016
@@ -95,7 +95,7 @@
</dependency>]]></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 </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 {
+public class CamelCdiTest {
@Inject
CamelContext context;
@@ -109,7 +109,7 @@ public class CamelCdiRunnerTest {
}]]></script>
</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 {
+public class CamelCdiTest {
@Test
public void test(@Uri("direct:foo") ProducerTemplate producer) {
@@ -118,7 +118,7 @@ public class CamelCdiRunnerTest {
}]]></script>
</div></div><p><span style="color: rgb(0,0,0);">Camel CDI test provides the </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);"> </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 {
+public class CamelCdiTest {
Â
@Test
@Order(1)
@@ -133,7 +133,7 @@ public class CamelCdiRunnerTest {
</div></div><p><span style="color: rgb(0,0,0);">One CDI container is bootstrapped for the entire execution of the test class. </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 <code>@Dependent</code> CDI scope), or one test class instance for the entire test class execution using the <code>@ApplicationScoped</code> 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 {
+public class CamelCdiTest {
Â
int counter;
@@ -149,6 +149,20 @@ public class CamelCdiRunnerTest {
assertEquals(counter, 1);
}
}]]></script>
+</div></div><p>In case you need to add additional test beans, you can use the <code>@Beans</code> annotation provided by Camel CDI test. For example, if you need to add a route to your Camel context, instead of declaring a <code>RouteBuilder</code> bean with a nested class, you can declare a managed bean, 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[class TestRoute extends RouteBuilder {
+
+ @Override
+ public void configure() {
+ from("direct:foo").to("mock:bar");
+ }
+}]]></script>
+</div></div><p>And add it with the <code>@Beans</code> annotation, 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(CamelCdiRunner.class)
+@Beans(classes = TestRoute.class)
+public class CamelCdiTest {
+
+}]]></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 <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 {
@@ -385,6 +399,29 @@ public class CamelCdiTest {
}
}
}]]></script>
+</div></div><p>If you're using Arquillian as testing framework, you need to activate the alternative in your deployment method, e.g.:<span style="color: rgb(0,0,0);font-weight: bold;"> </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 CamelCdiTest {
+
+ @Deployment
+ public static Archive deployment() {
+ return ShrinkWrap.create(JavaArchive.class)
+ // Camel CDI
+ .addPackage(CdiCamelExtension.class.getPackage())
+ // Test classes
+ .addPackage(Application.class.getPackage())
+ // Bean archive deployment descriptor
+ .addAsManifestResource(
+ new StringAsset(
+ Descriptors.create(BeansDescriptor.class)
+ .getOrCreateAlternatives()
+ .stereotype(MockAlternative.class.getName()).up()
+ .exportAsString()),
+ "beans.xml");
+ }
+
+ //...
+}]]></script>
</div></div><h4 id="CDITesting-Camelcontextcustomisation"><span style="color: rgb(0,0,0);">Camel context customisation</span></h4><p><span style="color: rgb(0,0,0);">You may need to customise your Camel contexts for testing purpose, for example disabling JMX management to avoid TCP port allocation conflict. You can do that by declaring a custom Camel context bean in your test class, 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 CamelCdiTest {