Modified: websites/production/camel/content/beanshell.html
==============================================================================
--- websites/production/camel/content/beanshell.html (original)
+++ websites/production/camel/content/beanshell.html Fri Aug 25 08:22:01 2017
@@ -41,7 +41,6 @@
<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/shBrushXml.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;
@@ -115,46 +114,19 @@
<p>You could follow the examples above to create an <a shape="rect"
href="predicate.html">Predicate</a> in a <a shape="rect"
href="message-filter.html">Message Filter</a> or as an <a shape="rect"
href="expression.html">Expression</a> for a <a shape="rect"
href="recipient-list.html">Recipient List</a></p>
-<h3 id="BeanShell-ScriptContextOptions"><code>ScriptContext</code>
Options</h3><p> </p><div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">The <code>JSR-223</code>
scripting language's <strong><code>ScriptContext</code></strong> is
pre-configured with the following attributes all set at
<strong><code>ENGINE_SCOPE</code></strong>.</div></div><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Attribute</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><span><code>camelContext</code><br
clear="none"></span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.cam
el.CamelContext</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The Camel Context.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>context</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel Context (cannot be
used in groovy).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Exchange</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The current
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>properties</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.builder.script.PropertiesFunction</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong>
Function with a <st
rong><code>resolve</code></strong> method to make it easier to use Camels <a
shape="rect" href="properties.html">Properties</a> component from scripts. See
further below for example.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>request</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
The <strong><code>OUT</code></strong> message.
The <strong><code>OUT</code></strong> message
is <strong><code>null</code></strong> by default. Use the
<strong><code>IN</code></strong> message instead.</p></td></tr></tbody>
</table></div><p>See <a shape="rect" href="scripting-languages.html">Scripting
Languages</a> for the list of languages with explicit DSL support.</p><h3
id="BeanShell-PassingAdditionalArgumentstotheScriptingEngine">Passing
Additional Arguments to
the <code>ScriptingEngine</code></h3><p><strong>Available from Camel
2.8</strong></p><p>You can provide additional arguments to the
<strong><code>ScriptingEngine</code></strong> using a header on the Camel
message with the key
<strong><code>CamelScriptArguments</code></strong>.</p><p>Example:</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[
-public void testArgumentsExample() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(0);
- getMockEndpoint("mock:unmatched").expectedMessageCount(1);
-
- // additional arguments to ScriptEngine
- Map<String, Object> arguments = new HashMap<String, Object>();
- arguments.put("foo", "bar");
- arguments.put("baz", 7);
-
- // those additional arguments is provided as a header on the Camel Message
- template.sendBodyAndHeader("direct:start", "hello",
ScriptBuilder.ARGUMENTS, arguments);
-
- assertMockEndpointsSatisfied();
-}
-]]></script>
-</div></div><h3 id="BeanShell-UsingPropertiesFunction">Using Properties
Function</h3><p><strong>Available from Camel 2.9</strong></p><p>If you need to
use the <a shape="rect" href="properties.html">Properties</a> component from a
script to lookup property placeholders, then its a bit cumbersome to do so. For
example, to set a header name <strong><code>myHeader</code></strong> with
a value from a property placeholder, whose key is taken from a header named
<strong><code>foo</code></strong>.</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[.setHeader("myHeader").groovy("context.resolvePropertyPlaceholders('{{'
+ request.headers.get('foo') + '}}')")
-]]></script>
-</div></div><p>From <strong>Camel 2.9</strong>: you can now use the properties
function and the same example is simpler:</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[.setHeader("myHeader").groovy("properties.resolve(request.headers.get('foo'))")
-]]></script>
-</div></div><h3 id="BeanShell-LoadingScriptFromExternalResource">Loading
Script From External Resource</h3><p><strong>Available from Camel
2.11</strong></p><p>You can externalize the script and have Camel load it from
a resource such as <strong><code>classpath:</code></strong>,
<strong><code>file:</code></strong>, or <strong><code>http:</code></strong>.
This is done using the following syntax:
<strong><code>resource:scheme:location</code></strong> e.g. to refer to a file
on the classpath you can do:</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[.setHeader("myHeader").groovy("resource:classpath:mygroovy.groovy")
-]]></script>
-</div></div><h3
id="BeanShell-HowtoGettheResultfromMultipleStatementsScript">How to Get the
Result from Multiple Statements Script</h3><p><strong>Available from Camel
2.14</strong></p><p>The script engine's eval method returns
a <strong><code>null</code></strong> when it runs a multi-statement
script. However, Camel can look up the value of a script's result by using the
key <strong><code>result</code></strong> from the value set. When writing a
multi-statement script set the value of
the <strong><code>result</code></strong> variable as the script return
value.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: text; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[bar = "baz";
+<h3 id="BeanShell-ScriptContextOptions"><code>ScriptContext</code>
Options</h3><p> </p><rich-text-body>The <code>JSR-223</code>
scripting language's <strong><code>ScriptContext</code></strong> is
pre-configured with the following attributes all set at
<strong><code>ENGINE_SCOPE</code></strong>.</rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Attribute</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><span><code>camelContext</code><br
clear="none"></span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel
Context.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>context</code></p></td><td co
lspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel Context (cannot be
used in groovy).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Exchange</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The current
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>properties</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.builder.script.PropertiesFunction</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong>
Function with a <strong><code>resolve</code></strong> method to make it easier
to use Camels <a shape="rect" href="properties.html">Properties</a> component
from scripts. See further below for example.</p></td></tr><tr><td co
lspan="1" rowspan="1" class="confluenceTd"><p><code>request</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
The <strong><code>OUT</code></strong> message.
The <strong><code>OUT</code></strong> message
is <strong><code>null</code></strong> by default. Use the
<strong><code>IN</code></strong> message
instead.</p></td></tr></tbody></table></div><p>See <a shape="rect"
href="scripting-languages.html">Scripting Languages</a> for the list of
languages with explicit DSL support.</p><h3
id="BeanShell-PassingAdditionalArgumentstotheScriptin
gEngine">Passing Additional Arguments to
the <code>ScriptingEngine</code></h3><p><strong>Available from Camel
2.8</strong></p><p>You can provide additional arguments to the
<strong><code>ScriptingEngine</code></strong> using a header on the Camel
message with the key
<strong><code>CamelScriptArguments</code></strong>.</p><p>Example:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptExpressionTest.java}</plain-text-body></p><h3
id="BeanShell-UsingPropertiesFunction">Using Properties
Function</h3><p><strong>Available from Camel 2.9</strong></p><p>If you need to
use the <a shape="rect" href="properties.html">Properties</a> component from a
script to lookup property placeholders, then its a bit cumbersome to do so. For
example, to set a header name <strong><code>myHeader</code></strong> with
a value from a property placeholder, whose key is taken from a header named
<strong><code>foo</code><
/strong>.</p><plain-text-body>.setHeader("myHeader").groovy("context.resolvePropertyPlaceholders('{{'
+ request.headers.get('foo') + '}}')")
+</plain-text-body><p>From <strong>Camel 2.9</strong>: you can now use the
properties function and the same example is simpler:</p><parameter
ac:name="language">java</parameter><plain-text-body>.setHeader("myHeader").groovy("properties.resolve(request.headers.get('foo'))")
+</plain-text-body><h3 id="BeanShell-LoadingScriptFromExternalResource">Loading
Script From External Resource</h3><p><strong>Available from Camel
2.11</strong></p><p>You can externalize the script and have Camel load it from
a resource such as <strong><code>classpath:</code></strong>,
<strong><code>file:</code></strong>, or <strong><code>http:</code></strong>.
This is done using the following syntax:
<strong><code>resource:scheme:location</code></strong> e.g. to refer to a file
on the classpath you can do:</p><parameter
ac:name="language">java</parameter><plain-text-body>.setHeader("myHeader").groovy("resource:classpath:mygroovy.groovy")
+</plain-text-body><h3
id="BeanShell-HowtoGettheResultfromMultipleStatementsScript">How to Get the
Result from Multiple Statements Script</h3><p><strong>Available from Camel
2.14</strong></p><p>The script engine's eval method returns
a <strong><code>null</code></strong> when it runs a multi-statement
script. However, Camel can look up the value of a script's result by using the
key <strong><code>result</code></strong> from the value set. When writing a
multi-statement script set the value of
the <strong><code>result</code></strong> variable as the script return
value.</p><parameter ac:name="language">text</parameter><plain-text-body>bar =
"baz";
# some other statements ...
# camel take the result value as the script evaluation result
result = body * 2 + 1
-]]></script>
-</div></div><p> </p><h3
id="BeanShell-Dependencies">Dependencies</h3><p>To use scripting languages in
your camel routes you need to add the a dependency on
<strong><code>camel-script</code></strong> which integrates the JSR-223
scripting engine.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</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[<dependency>
+</plain-text-body><p> </p><h3
id="BeanShell-Dependencies">Dependencies</h3><p>To use scripting languages in
your camel routes you need to add the a dependency on
<strong><code>camel-script</code></strong> which integrates the JSR-223
scripting engine.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
<version>x.x.x</version>
</dependency>
-]]></script>
-</div></div></div>
+</plain-text-body></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/blueprint-testing.html
==============================================================================
--- websites/production/camel/content/blueprint-testing.html (original)
+++ websites/production/camel/content/blueprint-testing.html Fri Aug 25
08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <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/shBrushXml.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;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Blueprint Testing
@@ -86,141 +75,48 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="BlueprintTesting-BlueprintTesting">Blueprint
Testing</h2><p><strong>Available as of Camel 2.10</strong></p><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p><strong>camel-test-blueprint</strong>
does only support testing <em>one</em> CamelContext. So if you have two or
more CamelContexts in your blueprint XML files, then only the CamelContext
first found is used during testing.</p></div></div><p><a shape="rect"
href="testing.html">Testing</a><span style="line-height: 1.4285715;"> is a
crucial part of any development or integration work. Camel supports the
definition of </span><a shape="rect"
href="using-osgi-blueprint-with-camel.html">Blueprint routes</a><span
style="line-height: 1.4285715;">, but given that Blueprint is an OSGi specific
technology, writing uni
t tests is quite difficult. This library leverages </span><a shape="rect"
class="external-link" href="http://code.google.com/p/pojosr/" rel="nofollow"
style="line-height: 1.4285715;">PojoSR</a><span style="line-height:
1.4285715;"> (now Felix Connect) which provides a service registry without
using a fully compliant OSGi container. This allows defining real unit tests
(as opposed to integration tests using </span><a shape="rect"
class="external-link"
href="http://team.ops4j.org/wiki/display/paxexam/Pax+Exam" rel="nofollow"
style="line-height: 1.4285715;">Pax Exam</a><span style="line-height:
1.4285715;">. Please make sure all test jars in your classpath are OSGi
bundles.</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[
-// tag::example[]
-// to use camel-test-blueprint, then extend the CamelBlueprintTestSupport
class,
-// and add your unit tests methods as shown below.
-public class DebugBlueprintTest extends CamelBlueprintTestSupport {
-
- private boolean debugBeforeMethodCalled;
- private boolean debugAfterMethodCalled;
-
- // override this method, and return the location of our Blueprint XML file
to be used for testing
- @Override
- protected String getBlueprintDescriptor() {
- return "org/apache/camel/test/blueprint/camelContext.xml";
- }
-
- // here we have regular JUnit @Test method
- @Test
- public void testRoute() throws Exception {
-
- // set mock expectations
- getMockEndpoint("mock:a").expectedMessageCount(1);
-
- // send a message
- template.sendBody("direct:start", "World");
-
- // assert mocks
- assertMockEndpointsSatisfied();
-
- // assert on the debugBefore/debugAfter methods below being called as
we've enabled the debugger
- assertTrue(debugBeforeMethodCalled);
- assertTrue(debugAfterMethodCalled);
- }
-
- @Override
- public boolean isUseDebugger() {
- // must enable debugger
- return true;
- }
-
- @Override
- protected void debugBefore(Exchange exchange, org.apache.camel.Processor
processor, ProcessorDefinition<?> definition, String id, String label) {
- log.info("Before " + definition + " with body " +
exchange.getIn().getBody());
- debugBeforeMethodCalled = true;
- }
-
- @Override
- protected void debugAfter(Exchange exchange, org.apache.camel.Processor
processor, ProcessorDefinition<?> definition, String id, String label,
long timeTaken) {
- log.info("After " + definition + " with body " +
exchange.getIn().getBody());
- debugAfterMethodCalled = true;
- }
-}
-// end::example[]
-]]></script>
-</div></div>Also notice the use of
<strong><code>getBlueprintDescriptor</code></strong> to specify the location of
the OSGi Blueprint XML file.<br clear="none"> If you have multiple OSGi
Blueprint XML files, then you can specify them with a comma-separated list in
the <strong><code>getBlueprintDescriptor</code></strong> method.<p>Here's the
<a shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml?view=markup">Blueprint
XML file</a>:</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[
-<!-- tag::example[] -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
-
- <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <transform>
- <simple>Hello ${body}</simple>
- </transform>
- <to uri="mock:a"/>
- </route>
-
- </camelContext>
-
-</blueprint>
-<!-- end::example[] -->
-]]></script>
-</div></div>In order to define blueprint tests, add the following dependency
to your pom:<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[<dependency>
+<div class="wiki-content maincontent"><h2
id="BlueprintTesting-BlueprintTesting">Blueprint
Testing</h2><p><strong>Available as of Camel
2.10</strong></p><rich-text-body><p><strong>camel-test-blueprint</strong> does
only support testing <em>one</em> CamelContext. So if you have two or more
CamelContexts in your blueprint XML files, then only the CamelContext first
found is used during testing.</p></rich-text-body><p><a shape="rect"
href="testing.html">Testing</a><span style="line-height: 1.4285715;"> is a
crucial part of any development or integration work. Camel supports the
definition of </span><a shape="rect"
href="using-osgi-blueprint-with-camel.html">Blueprint routes</a><span
style="line-height: 1.4285715;">, but given that Blueprint is an OSGi specific
technology, writing unit tests is quite difficult. This library leverages
</span><a shape="rect" class="external-link"
href="http://code.google.com/p/pojosr/" rel="nofollow" style="line-height:
1.4285715;">PojoSR</a><span style="
line-height: 1.4285715;"> (now Felix Connect) which provides a service
registry without using a fully compliant OSGi container. This allows defining
real unit tests (as opposed to integration tests using </span><a shape="rect"
class="external-link"
href="http://team.ops4j.org/wiki/display/paxexam/Pax+Exam" rel="nofollow"
style="line-height: 1.4285715;">Pax Exam</a><span style="line-height:
1.4285715;">. Please make sure all test jars in your classpath are OSGi
bundles.</span><plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java}</plain-text-body>Also
notice the use of <strong><code>getBlueprintDescriptor</code></strong> to
specify the location of the OSGi Blueprint XML file.<br clear="none"> If you
have multiple OSGi Blueprint XML files, then you can specify them with a
comma-separated list in the
<strong><code>getBlueprintDescriptor</code></strong> method.</p><p>Here'
s the <a shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml?view=markup">Blueprint
XML
file</a>:<plain-text-body>{snippet:lang=xml|id=example|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml}</plain-text-body>In
order to define blueprint tests, add the following dependency to your
pom:</p><parameter ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-blueprint</artifactId>
<version>2.10</version>
<scope>test</scope>
</dependency>
-]]></script>
-</div></div><h3 id="BlueprintTesting-Classpathscanning">Classpath
scanning</h3><p>By default PojoSR test container scans the test classpath for
all the OSGi bundles available there. All the bundles with Blueprint descriptor
files will be automatically started by the test container. If you would like to
prevent particular bundles from being started by the test container, override
the <code><strong>getBundleFilter</strong></code> method, just as demonstrated
in the snippet below. </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[@Override
+</plain-text-body><h3 id="BlueprintTesting-Classpathscanning">Classpath
scanning</h3><p>By default PojoSR test container scans the test classpath for
all the OSGi bundles available there. All the bundles with Blueprint descriptor
files will be automatically started by the test container. If you would like to
prevent particular bundles from being started by the test container, override
the <code><strong>getBundleFilter</strong></code> method, just as demonstrated
in the snippet below. </p><parameter
ac:name="language">java</parameter><plain-text-body>@Override
protected String getBundleFilter() {
- // I don't want test container to scan and load Logback bundle during
the test
- return "(!(Bundle-SymbolicName=ch.qos.logback.core))";
+ // I don't want test container to scan and load Logback bundle during the
test
+ return "(!(Bundle-SymbolicName=ch.qos.logback.core))";
}
-]]></script>
-</div></div><p class="caseCommentStyle privateComment"><br clear="none">Keep
in mind that not specifying the Blueprint descriptor in the
getBlueprintDescriptor method will not prevent the test container from loading
a given descriptor. The <code>getBundleFilter</code> method is the proper way
of filtering out bundles you don't want to start during the test.</p><h3
id="BlueprintTesting-SettingtimeoutwhengettingCamelContext">Setting timeout
when getting CamelContext</h3><p><strong>Available as of Camel
2.13.0/2.12.1/2.11.2</strong></p><p><code>CamelBlueprintTestSupport</code>
waits 30 seconds for Camel Context to be ready by default, now you can override
this value in two ways:</p><ul><li>Globally, by setting
<code>org.apache.camel.test.blueprint.camelContextCreationTimeout</code> system
property.</li><li>Locally for each test, by overriding
<em>getCamelContextCreationTimeout</em> method.</li></ul><h3
id="BlueprintTesting-Addingservicesonstartup">Adding services on
startup</h3><p><str
ong>Available as of Camel 2.11.2/2.12.0</strong></p><p>When using
<code>camel-test-blueprint</code> you may do unit tests which requires using
shared services which are not available during unit testing, but only in the
real OSGi container, for example a shared <code>DataSource</code>.</p><p>To
make it easier to register services on startup, such as a standalone
<code>DataSource</code> or any other service, you can override the method
<code>addServicesOnStartup</code> when your unit test class extends
<code>CamelBlueprintTestSupport</code>.</p><p>In the example below we register
a service <code>org.apache.camel.test.blueprint.MyService</code> using the name
<code>myService</code> having a property <code>beer=Carlsberg</code>, as shown
below:</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[ @Override
+</plain-text-body><p class="caseCommentStyle privateComment"><br
clear="none">Keep in mind that not specifying the Blueprint descriptor in the
getBlueprintDescriptor method will not prevent the test container from loading
a given descriptor. The <code>getBundleFilter</code> method is the proper way
of filtering out bundles you don't want to start during the test.</p><h3
id="BlueprintTesting-SettingtimeoutwhengettingCamelContext">Setting timeout
when getting CamelContext</h3><p><strong>Available as of Camel
2.13.0/2.12.1/2.11.2</strong></p><p><code>CamelBlueprintTestSupport</code>
waits 30 seconds for Camel Context to be ready by default, now you can override
this value in two ways:</p><ul><li>Globally, by setting
<code>org.apache.camel.test.blueprint.camelContextCreationTimeout</code> system
property.</li><li>Locally for each test, by overriding
<em>getCamelContextCreationTimeout</em> method.</li></ul><h3
id="BlueprintTesting-Addingservicesonstartup">Adding services on startup</h3><
p><strong>Available as of Camel 2.11.2/2.12.0</strong></p><p>When using
<code>camel-test-blueprint</code> you may do unit tests which requires using
shared services which are not available during unit testing, but only in the
real OSGi container, for example a shared <code>DataSource</code>.</p><p>To
make it easier to register services on startup, such as a standalone
<code>DataSource</code> or any other service, you can override the method
<code>addServicesOnStartup</code> when your unit test class extends
<code>CamelBlueprintTestSupport</code>.</p><p>In the example below we register
a service <code>org.apache.camel.test.blueprint.MyService</code> using the name
<code>myService</code> having a property <code>beer=Carlsberg</code>, as shown
below:</p><plain-text-body> @Override
protected void addServicesOnStartup(Map<String,
KeyValueHolder<Object, Dictionary>> services) {
- services.put("myService", asService(myService,
"beer", "Carlsberg"));
+ services.put("myService", asService(myService, "beer", "Carlsberg"));
}
-]]></script>
-</div></div><p>The asService is a builder method that makes it easy to
register a service with a single property. If you need more properties you can
use the <code>asService</code> method that takes a <code>Dictionary</code> as
argument. And if you do not need any properties, then just pass in
<code>null</code>, eg:</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[services.put("myService",
asService(myService, null));
-]]></script>
-</div></div><p>This allows us to use the service by calling a method on it
from a Camel <a shape="rect" href="bean.html">Bean</a> component in a route as
shown:</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[ <route>
- <from uri="direct:start"/>
- <to uri="bean:myService"/>
- <to uri="mock:result"/>
+</plain-text-body><p>The asService is a builder method that makes it easy to
register a service with a single property. If you need more properties you can
use the <code>asService</code> method that takes a <code>Dictionary</code> as
argument. And if you do not need any properties, then just pass in
<code>null</code>, eg:</p><plain-text-body>services.put("myService",
asService(myService, null));
+</plain-text-body><p>This allows us to use the service by calling a method on
it from a Camel <a shape="rect" href="bean.html">Bean</a> component in a route
as shown:</p><parameter ac:name="">xml</parameter><plain-text-body>
<route>
+ <from uri="direct:start"/>
+ <to uri="bean:myService"/>
+ <to uri="mock:result"/>
</route>
-]]></script>
-</div></div><p>Notice the bean endpoint uses the service name
<code>myService</code> which was the name we registered the service as. You can
also use the fully qualified class name instead, which is more common with
OSGi.</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[ @Override
+</plain-text-body><p>Notice the bean endpoint uses the service name
<code>myService</code> which was the name we registered the service as. You can
also use the fully qualified class name instead, which is more common with
OSGi.</p><plain-text-body> @Override
protected void addServicesOnStartup(Map<String,
KeyValueHolder<Object, Dictionary>> services) {
- services.put(MyService.class.getName(), asService(myService,
"beer", "Carlsberg"));
+ services.put(MyService.class.getName(), asService(myService, "beer",
"Carlsberg"));
}
-]]></script>
-</div></div><p>And in the route we use the FQN name:</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[ <route>
- <from uri="direct:start"/>
- <to
uri="bean:org.apache.camel.test.blueprint.MyService"/>
- <to uri="mock:result"/>
+</plain-text-body><p>And in the route we use the FQN name:</p><parameter
ac:name="">xml</parameter><plain-text-body> <route>
+ <from uri="direct:start"/>
+ <to uri="bean:org.apache.camel.test.blueprint.MyService"/>
+ <to uri="mock:result"/>
</route>
-]]></script>
-</div></div><p> </p><p><span>From </span><strong>Camel
2.16.0</strong><span>, an
additional </span><span><code>addServicesOnStartup</code> method is
available to be overridden making it ideal for when needing to specify multiple
services with the same interface.</span><span> </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[ @Override
+</plain-text-body><p> </p><p><span>From </span><strong>Camel
2.16.0</strong><span>, an
additional </span><span><code>addServicesOnStartup</code> method is
available to be overridden making it ideal for when needing to specify multiple
services with the same interface.</span><span> </span></p><parameter
ac:name="language">java</parameter><plain-text-body> @Override
protected void addServicesOnStartup(List<KeyValueHolder<String,
KeyValueHolder<Object, Dictionary>>> services) {
Dictionary<String, String> dict1 = new Hashtable<String,
String>();
- dict1.put("osgi.jndi.service.name", "jdbc/db1");
- Â
+ dict1.put("osgi.jndi.service.name", "jdbc/db1");
+  
Dictionary<String, String> dict2 = new Hashtable<String,
String>();
- dict2.put("osgi.jndi.service.name", "jdbc/db2");
- Â
+ dict2.put("osgi.jndi.service.name", "jdbc/db2");
+  
services.add(asKeyValueService(javax.sql.DataSource.class.getName(),
mockService1, dict1));
services.add(asKeyValueService(javax.sql.DataSource.class.getName(),
mockService2, dict2));
}
-]]></script>
-</div></div><p><span>The <code>asKeyValueService</code> builder method can be
used to construct the necessary parameters to create the service. The method
takes in the name of the registered service, the object, and and a
<code><span>Dictionary</span></code> as arguments.</span></p></div>
+</plain-text-body><p><span>The <code>asKeyValueService</code> builder method
can be used to construct the necessary parameters to create the service. The
method takes in the name of the registered service, the object, and and a
<code><span>Dictionary</span></code> as arguments.</span></p></div>
</td>
<td valign="top">
<div class="navigation">