Author: buildbot
Date: Wed Nov 26 20:18:18 2014
New Revision: 930648

Log:
Production update by buildbot for camel

Modified:
    websites/production/camel/content/building.html
    websites/production/camel/content/cache/main.pageCache
    websites/production/camel/content/camel-and-scr.html

Modified: websites/production/camel/content/building.html
==============================================================================
--- websites/production/camel/content/building.html (original)
+++ websites/production/camel/content/building.html Wed Nov 26 20:18:18 2014
@@ -153,6 +153,8 @@
 </div></div><p>From Camel 2.12.0 onwards, Spring 3.2 is the default.</p><h3 
id="Building-Workingwithfeatures">Working with features</h3><p>If you change 
anything in the features.xml from <code>platform/karaf</code> you can run a 
validation step to ensure the generated features.xml file is correct. You can 
do this running the following maven goal from the <code>platform</code> 
directory.</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
 <script class="theme: Default; brush: text; gutter: false" 
type="syntaxhighlighter"><![CDATA[mvn clean install -Pvalidate
 ]]></script>
+</div></div><h3 id="Building-ExecutingunittestsusingEkstazi">Executing unit 
tests using Ekstazi</h3><p>Normally, when you execute the unit tests during 
your development cycle for a particular component, you are executing all the 
tests each time. This may become inefficient, when you are changing one class 
and the effect of this change is limited within the component having many unit 
tests. Ekstazi is a regression testing tool that can keep track of the test 
results and the changed classes so that unaffected tests can be skipped during 
the subsequent testing. For more details of Ekstazi, please refer to the 
Ekstazi page at&#160;<a shape="rect" class="external-link" 
href="http://www.ekstazi.org"; 
rel="nofollow">http://www.ekstazi.org</a>.</p><p><span style="line-height: 
1.4285715;">To use Ekstazi, you can run the tests with the maven profile 
ekstazi.</span></p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: text; gutter: false" 
type="syntaxhighlighter"><![CDATA[mvn test -Pekstazi]]></script>
 </div></div><h3 id="Building-SeeAlso">See Also</h3><ul><li><a shape="rect" 
href="running-unit-tests.html">Running Unit Tests</a></li><li><a shape="rect" 
href="source.html">Source</a></li><li><a shape="rect" 
href="examples.html">Examples</a></li></ul></div>
         </td>
         <td valign="top">

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

Modified: websites/production/camel/content/camel-and-scr.html
==============================================================================
--- websites/production/camel/content/camel-and-scr.html (original)
+++ websites/production/camel/content/camel-and-scr.html Wed Nov 26 20:18:18 
2014
@@ -40,6 +40,7 @@
   <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/shBrushPlain.js' 
type='text/javascript'></script>
   
   <script type="text/javascript">
   SyntaxHighlighter.defaults['toolbar'] = false;
@@ -84,21 +85,236 @@
        <tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 
id="CamelandSCR-WorkingwithCamelusingSCR">Working with Camel using 
SCR</h2><p><span style="font-size: 14.0px;line-height: 1.4285715;">SCR stands 
for Service Component Runtime and is an implementation of OSGi Declarative 
Services specification (TODO: add a link to spec here). SCR enables any plain 
old Java object to expose and use OSGi services with no boilerplate 
code.</span></p><p>OSGi framework knows your object by looking at SCR 
descriptor files in your bundle which are typically generated from annotations 
in your code by a plugin such as org.apache.felix:maven-scr-plugin (<a 
shape="rect" class="external-link" 
href="https://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html";>https://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html</a>).</p><p>Running
 Camel in an SCR bundle is a great alternative for Spring DM and Blueprint 
based solutions having significantly fewer lines of code betw
 een you and the OSGi framework. Using SCR your bundle can remain completely in 
Java world; there is no need to edit XML or properties files. This offers you 
full control over everything and means your IDE of choice knows exactly what is 
going on in your project.</p><h3 id="CamelandSCR-CamelSCRsupport">Camel SCR 
support</h3><p><strong>Available as of Camel 2.15.0</strong></p><p><span 
style="line-height: 1.4285715;"><code>org.apache.camel/camel-scr</code> bundle 
provides a base class, <code>AbstractCamelRunner</code>, which manages a Camel 
context for you and a helper class, <code>ScrHelper</code>, for using your SCR 
properties in unit tests. Camel-scr feature for Apache Karaf&#160;</span><span 
style="line-height: 1.4285715;">defines all features and bundles required for 
running Camel in SCR 
bundles.</span></p><p><code>AbstractCamelRunner</code>&#160;class ties 
CamelContext's lifecycle to Service Component's lifecycle and handles 
configuration with help of Camel's PropertiesComponent.
  All you have to do to make a Service Component out of your java class is to 
extend it from <code>AbstractCamelRunner</code>&#160;and add the following 
<code>org.apache.felix.scr.annotations</code> on class level:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<div class="wiki-content maincontent"><h2 
id="CamelandSCR-WorkingwithCamelusingSCR">Working with Camel using 
SCR</h2><p><span style="font-size: 14.0px;line-height: 1.4285715;">SCR stands 
for Service Component Runtime and is an implementation of OSGi Declarative 
Services specification (TODO: add a link to spec here). SCR enables any plain 
old Java object to expose and use OSGi services with no boilerplate 
code.</span></p><p>OSGi framework knows your object by looking at SCR 
descriptor files in your bundle which are typically generated from annotations 
in your code by a plugin such as org.apache.felix:maven-scr-plugin (<a 
shape="rect" class="external-link" 
href="https://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html";>https://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html</a>).</p><p>Running
 Camel in an SCR bundle is a great alternative for Spring DM and Blueprint 
based solutions having significantly fewer lines of code betw
 een you and the OSGi framework. Using SCR your bundle can remain completely in 
Java world; there is no need to edit XML or properties files. This offers you 
full control over everything and means your IDE of choice knows exactly what is 
going on in your project.</p><h3 id="CamelandSCR-CamelSCRsupport">Camel SCR 
support</h3><p><strong>Available as of Camel 2.15.0</strong></p><p><span 
style="line-height: 1.4285715;"><code>org.apache.camel/camel-scr</code> bundle 
provides a base class, <code>AbstractCamelRunner</code>, which manages a Camel 
context for you and a helper class, <code>ScrHelper</code>, for using your SCR 
properties in unit tests. Camel-scr feature for Apache Karaf&#160;</span><span 
style="line-height: 1.4285715;">defines all features and bundles required for 
running Camel in SCR 
bundles.</span></p><p><code>AbstractCamelRunner</code>&#160;class ties 
CamelContext's lifecycle to Service Component's lifecycle and handles 
configuration with help of Camel's PropertiesComponent.
  All you have to do to make a Service Component out of your java class is to 
extend it from <code>AbstractCamelRunner</code>&#160;and add the following 
<code>org.apache.felix.scr.annotations</code> on class level:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader 
panelHeader pdl" style="border-bottom-width: 1px;"><b>Required 
annotations</b></div><div class="codeContent panelContent pdl">
 <script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[@Component
 @References({
     @Reference(name = &quot;camelComponent&quot;,referenceInterface = 
ComponentResolver.class,
         cardinality = ReferenceCardinality.MANDATORY_MULTIPLE, policy = 
ReferencePolicy.DYNAMIC,
         policyOption = ReferencePolicyOption.GREEDY, bind = 
&quot;gotCamelComponent&quot;, unbind = &quot;lostCamelComponent&quot;)
 })]]></script>
-</div></div><p>Then implement <code>getRouteBuilders()</code> method which 
returns the Camel routes you want to run. And finally provide the default 
configuration with:</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeContent panelContent pdl">
+</div></div><p>Then implement <code>getRouteBuilders()</code> method which 
returns the Camel routes you want to run. And finally provide the default 
configuration with:</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 
1px;"><b>Configuration in annotations</b></div><div class="codeContent 
panelContent pdl">
 <script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[@Properties({
    @Property(name = &quot;camelContextId&quot;, value = &quot;my-test&quot;),
    @Property(name = &quot;active&quot;, value = &quot;true&quot;),
    @Property(name = &quot;...&quot;, value = &quot;...&quot;),
    ...
 })]]></script>
-</div></div><p>That's all. And if you used <code>camel-archetype-scr</code> to 
generate a project all this is already taken care 
of.</p><p><code>CamelContextId</code>&#160;and 
<code>active</code>&#160;properties control the CamelContext's name (defaults 
to "camel-runner-default") and whether it will be started or not (defaults to 
"false"), respectively. In addition to these you can add and use as many 
properties as you like. Camel's PropertiesComponent handles recursive 
properties and prefixing with fallback without 
problem.</p><p><code>AbstractCamelRunner</code>&#160;will make these properties 
available to your RouteBuilders through Camel's PropertiesComponent and it will 
also inject these values into your Service Component's and RouteBuilder's 
fields when their names match. The fields can be declared with any visibility 
level, and many types are supported (String, int, boolean, URL, ...).</p><h4 
id="CamelandSCR-AbstractCamelRunner'slifecycleinSCR">AbstractCamelRunner's 
lifecycle i
 n SCR</h4><ol><li>When component's configuration policy and mandatory 
references are satisfied SCR calls <code>activate()</code>. This creates and 
sets up a CamelContext through the following call chain: 
<code>activate()</code>&#160;&#8594;&#160;<code><em>prepare</em>()</code>&#160;&#8594;&#160;<code>createCamelContext()</code>
 &#8594;&#160;<code>setupPropertiesComponent()</code> 
&#8594;&#160;<code>configure()</code> 
&#8594;&#160;<code>setupCamelContext()</code>. Finally, the context is 
scheduled to start after a delay defined in 
<code>AbstractCamelRunner.START_DELAY</code>&#160;with 
<code>runWithDelay()</code>.</li><li><span style="line-height: 1.4285715;">When 
Camel components (<code>ComponentResolver</code> services, to be exact) are 
registered in OSGi, SCR calls </span><code>gotCamelComponent</code><span 
style="line-height: 1.4285715;"><code>()</code> which reschedules/delays the 
CamelContext start further by the same 
</span><code>AbstractCamelRunner.START_DELAY</code><span styl
 e="line-height: 1.4285715;">. This in effect makes CamelContext wait until all 
Camel components are loaded or there is a sufficient gap between them. The same 
logic will tell a failed-to-start CamelContext to try again whenever we add 
more Camel components.</span></li><li><span style="line-height: 
1.4285715;">When Camel components are unregistered SCR calls 
</span><code>lostCamelComponent</code><span style="line-height: 
1.4285715;"><code>()</code>. This call does nothing.</span></li><li><span 
style="line-height: 1.4285715;">When one of the requirements that caused the 
call to </span><code>activate</code><span style="line-height: 
1.4285715;"><code>()</code> is lost SCR will call 
</span><code>deactivate</code><span style="line-height: 
1.4285715;"><code>()</code>. This will shutdown the 
CamelContext.</span></li></ol><p>In (non-OSGi) unit tests you should use 
<code>prepare()</code> &#8594;&#160;<code>run()</code> 
&#8594;&#160;<code>stop()</code> instead of <code>activate()</code> &#8594
 ;&#160;<code>deactivate()</code> for more fine-grained control. Also, this 
allows us to avoid possible SCR specific operations in tests.</p><h4 
id="CamelandSCR-ExampleCamelSCRbundle">Example Camel SCR bundle</h4><p>The 
easiest way to create an Camel SCR bundle is to use camel-archetype-scr Maven 
archetype.</p><p><code>mvn archetype:generate 
-Dfilter=org.apache.camel.archetypes:camel-archetype-scr</code></p><p>Choose 
archetype:<br clear="none">1: local -&gt; 
org.apache.camel.archetypes:camel-archetype-scr (Creates a new Camel SCR bundle 
project for Karaf)<br clear="none">Choose a number or apply filter (format: 
[groupId:]artifactId, case sensitive contains): : 1<br clear="none">Define 
value for property 'groupId': : my.example<br clear="none">[INFO] Using 
property: groupId = my.example<br clear="none">Define value for property 
'artifactId': : my-test<br clear="none">Define value for property 'version': 
1.0-SNAPSHOT: :<br clear="none">Define value for property 'package': 
my.example: :
 <br clear="none">[INFO] Using property: archetypeArtifactId = 
camel-archetype-scr<br clear="none">[INFO] Using property: archetypeGroupId = 
org.apache.camel.archetypes<br clear="none">[INFO] Using property: 
archetypeVersion = 2.15-SNAPSHOT<br clear="none">Define value for property 
'className': : MyTest<br clear="none">Confirm properties configuration:<br 
clear="none">groupId: my.example<br clear="none">artifactId: my-test<br 
clear="none">version: 1.0-SNAPSHOT<br clear="none">package: my.example<br 
clear="none">archetypeArtifactId: camel-archetype-scr<br 
clear="none">archetypeGroupId: org.apache.camel.archetypes<br 
clear="none">archetypeVersion: 2.15-SNAPSHOT<br clear="none">className: 
MyTest<br clear="none"> Y: :</p><p>All done! Check ReadMe.txt in the generated 
project folder for the next steps.</p><p>To deploy a Camel SCR bundle project 
in Apache Karaf:</p><p>On Karaf command line:</p><p># Add Camel feature 
repository<br clear="none">features:chooseurl camel 2.15-SNAPSHOT</p><p># 
 Install camel-scr feature<br clear="none">features:install camel-scr</p><p># 
Install commons-lang, used in the example route to validate parameters<br 
clear="none"> osgi:install mvn:commons-lang/commons-lang/2.6</p><p># Install 
and start your bundle<br clear="none"> osgi:install -s 
mvn:your.company/your-bundle/version</p><p># See how it's running<br 
clear="none">log:tail -n 10</p><p>Press ctrl-c to stop watching the 
log.</p></div>
+</div></div><p>That's all. And if you used <code>camel-archetype-scr</code> to 
generate a project all this is already taken care of.</p><p>Below is an example 
of a complete Service Component class, generated by 
<code>camel-archetype-scr:</code></p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 
style="border-bottom-width: 1px;"><b>CamelScrExample.java</b></div><div 
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[// This file was generated from 
org.apache.camel.archetypes/camel-archetype-scr/2.15-SNAPSHOT
+package example;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.scr.AbstractCamelRunner;
+import example.internal.CamelScrExampleRoute;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.spi.ComponentResolver;
+import org.apache.felix.scr.annotations.*;
+
+@Component(label = CamelScrExample.COMPONENT_LABEL, description = 
CamelScrExample.COMPONENT_DESCRIPTION, immediate = true, metatype = true)
+@Properties({
+    @Property(name = &quot;camelContextId&quot;, value = 
&quot;camel-scr-example&quot;),
+    @Property(name = &quot;camelRouteId&quot;, value = 
&quot;foo/timer-log&quot;),
+    @Property(name = &quot;active&quot;, value = &quot;true&quot;),
+    @Property(name = &quot;from&quot;, value = 
&quot;timer:foo?period=5000&quot;),
+    @Property(name = &quot;to&quot;, value = 
&quot;log:foo?showHeaders=true&quot;),
+    @Property(name = &quot;messageOk&quot;, value = &quot;Success: {{from}} 
-&gt; {{to}}&quot;),
+    @Property(name = &quot;messageError&quot;, value = &quot;Failure: {{from}} 
-&gt; {{to}}&quot;),
+    @Property(name = &quot;maximumRedeliveries&quot;, value = &quot;0&quot;),
+    @Property(name = &quot;redeliveryDelay&quot;, value = &quot;5000&quot;),
+    @Property(name = &quot;backOffMultiplier&quot;, value = &quot;2&quot;),
+    @Property(name = &quot;maximumRedeliveryDelay&quot;, value = 
&quot;60000&quot;)
+})
+@References({
+    @Reference(name = &quot;camelComponent&quot;,referenceInterface = 
ComponentResolver.class,
+        cardinality = ReferenceCardinality.MANDATORY_MULTIPLE, policy = 
ReferencePolicy.DYNAMIC,
+        policyOption = ReferencePolicyOption.GREEDY, bind = 
&quot;gotCamelComponent&quot;, unbind = &quot;lostCamelComponent&quot;)
+})
+public class CamelScrExample extends AbstractCamelRunner {
+
+    public static final String COMPONENT_LABEL = 
&quot;example.CamelScrExample&quot;;
+    public static final String COMPONENT_DESCRIPTION = &quot;This is the 
description for camel-scr-example.&quot;;
+
+    @Override
+    protected List&lt;RoutesBuilder&gt; getRouteBuilders() {
+        List&lt;RoutesBuilder&gt; routesBuilders = new ArrayList&lt;&gt;();
+        routesBuilders.add(new CamelScrExampleRoute(registry));
+        return routesBuilders;
+    }
+}]]></script>
+</div></div><p><code style="font-size: 14.0px;line-height: 
1.4285715;">CamelContextId</code><span style="font-size: 14.0px;line-height: 
1.4285715;">&#160;and </span><code style="font-size: 14.0px;line-height: 
1.4285715;">active</code><span style="font-size: 14.0px;line-height: 
1.4285715;">&#160;properties control the CamelContext's name (defaults to 
"camel-runner-default") and whether it will be started or not (defaults to 
"false"), respectively. In addition to these you can add and use as many 
properties as you like. Camel's PropertiesComponent handles recursive 
properties and prefixing with fallback without 
problem.</span></p><p><code>AbstractCamelRunner</code>&#160;will make these 
properties available to your RouteBuilders with help of Camel's 
PropertiesComponent and it will also inject these values into your Service 
Component's and RouteBuilder's fields when their names match. The fields can be 
declared with any visibility level, and many types are supported (String, int, 
boolea
 n, URL, ...).</p><h4 
id="CamelandSCR-AbstractCamelRunner'slifecycleinSCR">AbstractCamelRunner's 
lifecycle in SCR</h4><ol><li>When component's configuration policy and 
mandatory references are satisfied SCR calls <code>activate()</code>. This 
creates and sets up a CamelContext through the following call chain: 
<code>activate()</code>&#160;&#8594;&#160;<code>prepare()</code>&#160;&#8594;&#160;<code>createCamelContext()</code>
 &#8594;&#160;<code>setupPropertiesComponent()</code> 
&#8594;&#160;<code>configure()</code> 
&#8594;&#160;<code>setupCamelContext()</code>. Finally, the context is 
scheduled to start after a delay defined in 
<code>AbstractCamelRunner.START_DELAY</code>&#160;with 
<code>runWithDelay()</code>.</li><li><span style="line-height: 1.4285715;">When 
Camel components (<code>ComponentResolver</code> services, to be exact) are 
registered in OSGi, SCR calls </span><code>gotCamelComponent</code><span 
style="line-height: 1.4285715;"><code>()</code> which reschedules/delays the Ca
 melContext start further by the same 
</span><code>AbstractCamelRunner.START_DELAY</code><span style="line-height: 
1.4285715;">. This in effect makes CamelContext wait until all Camel components 
are loaded or there is a sufficient gap between them. The same logic will tell 
a failed-to-start CamelContext to try again whenever we add more Camel 
components.</span></li><li><span style="line-height: 1.4285715;">When Camel 
components are unregistered SCR calls 
</span><code>lostCamelComponent</code><span style="line-height: 
1.4285715;"><code>()</code>. This call does nothing.</span></li><li><span 
style="line-height: 1.4285715;">When one of the requirements that caused the 
call to </span><code>activate</code><span style="line-height: 
1.4285715;"><code>()</code> is lost SCR will call 
</span><code>deactivate</code><span style="line-height: 
1.4285715;"><code>()</code>. This will shutdown the 
CamelContext.</span></li></ol><p>In (non-OSGi) unit tests you should use 
<code>prepare()</code> &#8594;&
 #160;<code>run()</code> &#8594;&#160;<code>stop()</code> instead of 
<code>activate()</code> &#8594;&#160;<code>deactivate()</code> for more 
fine-grained control. Also, this allows us to avoid possible SCR specific 
operations in tests.</p><h3 id="CamelandSCR-Usingcamel-archetype-scr">Using 
camel-archetype-scr</h3><p>The easiest way to create an Camel SCR bundle 
project is to use <code>camel-archetype-scr</code>&#160;and Maven.</p><p>You 
can generate a project with the following steps:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 
style="border-bottom-width: 1px;"><b>Generating a project</b></div><div 
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: text; gutter: false" 
type="syntaxhighlighter"><![CDATA[$ mvn archetype:generate 
-Dfilter=org.apache.camel.archetypes:camel-archetype-scr
+ 
+Choose archetype:
+1: local -&gt; org.apache.camel.archetypes:camel-archetype-scr (Creates a new 
Camel SCR bundle project for Karaf)
+Choose a number or apply filter (format: [groupId:]artifactId, case sensitive 
contains): : 1
+Define value for property &#39;groupId&#39;: : example
+[INFO] Using property: groupId = example
+Define value for property &#39;artifactId&#39;: : camel-scr-example
+Define value for property &#39;version&#39;: 1.0-SNAPSHOT: :
+Define value for property &#39;package&#39;: example: :
+[INFO] Using property: archetypeArtifactId = camel-archetype-scr
+[INFO] Using property: archetypeGroupId = org.apache.camel.archetypes
+[INFO] Using property: archetypeVersion = 2.15-SNAPSHOT
+Define value for property &#39;className&#39;: : CamelScrExample
+Confirm properties configuration:
+groupId: example
+artifactId: camel-scr-example
+version: 1.0-SNAPSHOT
+package: example
+archetypeArtifactId: camel-archetype-scr
+archetypeGroupId: org.apache.camel.archetypes
+archetypeVersion: 2.15-SNAPSHOT
+className: CamelScrExample
+Y: :]]></script>
+</div></div><p>All done! Let's check ReadMe.txt in the generated project 
folder for the next steps:</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 
1px;"><b>ReadMe.txt</b></div><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: text; gutter: false" 
type="syntaxhighlighter"><![CDATA[Camel SCR bundle project
+========================
+
+To build this project run
+
+    mvn install
+
+To deploy this project in Apache Karaf (2.4.0)
+
+    On Karaf command line:
+
+    # Add Camel feature repository
+    features:chooseurl camel 2.15-SNAPSHOT
+
+    # Install camel-scr feature
+    features:install camel-scr
+
+    # Install commons-lang, used in the example route to validate parameters
+    osgi:install mvn:commons-lang/commons-lang/2.6
+
+    # Install and start your bundle
+    osgi:install -s mvn:example/camel-scr-example/1.0-SNAPSHOT
+
+    # See how it&#39;s running
+    log:tail -n 10
+
+    Press ctrl-c to stop watching the log.
+
+For more help see the Apache Camel documentation
+
+    http://camel.apache.org/]]></script>
+</div></div><h3 id="CamelandSCR-UnittestingCamelroutes">Unit testing Camel 
routes</h3><p>Service Component is a POJO and has no special requirements for 
(non-OSGi) unit testing. There are however some techniques that are specific to 
Camel SCR and make testing easier. Below is an example unit test, generated by 
<code>camel-archetype-scr</code>:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 
style="border-bottom-width: 1px;"><b>CamelScrExampleTest.java</b></div><div 
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[// This file was generated from 
org.apache.camel.archetypes/camel-archetype-scr/2.15-SNAPSHOT
+package example;
+
+import java.util.List;
+
+import org.apache.camel.scr.internal.ScrHelper;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.component.mock.MockComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.RouteDefinition;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class CamelScrExampleTest {
+
+    Logger log = LoggerFactory.getLogger(getClass());
+
+    @Rule
+    public TestName testName = new TestName();
+
+    CamelScrExample integration;
+    ModelCamelContext context;
+
+    @Before
+    public void setUp() throws Exception {
+        
log.info(&quot;*******************************************************************&quot;);
+        log.info(&quot;Test: &quot; + testName.getMethodName());
+        
log.info(&quot;*******************************************************************&quot;);
+
+        // Set property prefix for unit testing
+        System.setProperty(CamelScrExample.PROPERTY_PREFIX, &quot;unit&quot;);
+
+        // Prepare the integration
+        integration = new CamelScrExample();
+        integration.prepare(null, 
ScrHelper.getScrProperties(integration.getClass().getName()));
+        context = integration.getContext();
+
+        // Disable JMX for test
+        context.disableJMX();
+
+        // Fake a component for test
+        // context.addComponent(&quot;amq&quot;, new MockComponent());
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        integration.stop();
+    }
+
+       @Test
+       public void testRoutes() throws Exception {
+        // Adjust routes
+        List&lt;RouteDefinition&gt; routes = context.getRouteDefinitions();
+
+        routes.get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // Replace &quot;from&quot; endpoint with direct:start
+                replaceFromWith(&quot;direct:start&quot;);
+                // Mock and skip result endpoint
+                mockEndpoints(&quot;log:*&quot;);
+            }
+        });
+
+        MockEndpoint resultEndpoint = 
context.getEndpoint(&quot;mock:log:foo&quot;, MockEndpoint.class);
+        // resultEndpoint.expectedMessageCount(1); // If you want to just 
check the number of messages
+        resultEndpoint.expectedBodiesReceived(&quot;hello&quot;); // If you 
want to check the contents
+
+        // Start the integration
+        integration.run();
+
+        // Send the test message
+        context.createProducerTemplate().sendBody(&quot;direct:start&quot;, 
&quot;hello&quot;);
+
+        resultEndpoint.assertIsSatisfied();
+       }
+}]]></script>
+</div></div><p>Now, let's take a look at the interesting bits one by 
one.</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using 
property prefixing</b></div><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[        // Set property prefix for unit 
testing
+        System.setProperty(CamelScrExample.PROPERTY_PREFIX, 
&quot;unit&quot;);]]></script>
+</div></div><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Getting 
test configuration from annotations</b></div><div class="codeContent 
panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[        integration.prepare(null, 
ScrHelper.getScrProperties(integration.getClass().getName()));]]></script>
+</div></div><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Mock 
components that are not available for test</b></div><div class="codeContent 
panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[        // Fake a component for test
+        // context.addComponent(&quot;amq&quot;, new 
MockComponent());]]></script>
+</div></div><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeHeader panelHeader pdl" style="border-bottom-width: 
1px;"><b>Adjusting routes for test</b></div><div class="codeContent 
panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[        // Adjust routes
+        List&lt;RouteDefinition&gt; routes = context.getRouteDefinitions();
+
+        routes.get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // Replace &quot;from&quot; endpoint with direct:start
+                replaceFromWith(&quot;direct:start&quot;);
+                // Mock and skip result endpoint
+                mockEndpoints(&quot;log:*&quot;);
+            }
+        });]]></script>
+</div></div><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeHeader panelHeader pdl" style="border-bottom-width: 
1px;"><b>Starting the routes</b></div><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[        // Start the integration
+        integration.run();]]></script>
+</div></div><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Sending 
a test message</b></div><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[        // Send the test message
+        context.createProducerTemplate().sendBody(&quot;direct:start&quot;, 
&quot;hello&quot;);]]></script>
+</div></div></div>
         </td>
         <td valign="top">
           <div class="navigation">


Reply via email to