camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Test
Date Sun, 07 Aug 2011 19:01:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Test">Test</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >So you can use, for example, an expected
set of message bodies as files. This will then set up a properly configured [Mock] endpoint,
which is only valid if the received messages match the number of expected messages and their
message payloads are equal. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Maven
users will need to add the following dependency to their {{pom.xml}} for this component when
using *Camel 2.8* or older: <br>{code:xml} <br>&lt;dependency&gt; <br>
   &lt;groupId&gt;org.apache.camel&lt;/groupId&gt; <br>    &lt;artifactId&gt;camel-spring&lt;/artifactId&gt;
<br>    &lt;version&gt;x.x.x&lt;/version&gt; <br>    &lt;!--
use the same version as your Camel core version --&gt; <br>&lt;/dependency&gt;
<br>{code} <br>From Camel 2.9 onwards the [Test] component is provided directly
in the camel-core. <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Test-TestComponent"></a>Test Component</h2>

<p><a href="/confluence/display/CAMEL/Testing" title="Testing">Testing</a>
of distributed and asynchronous processing is notoriously difficult. The <a href="/confluence/display/CAMEL/Mock"
title="Mock">Mock</a>, <a href="/confluence/display/CAMEL/Test" title="Test">Test</a>
and <a href="/confluence/display/CAMEL/DataSet" title="DataSet">DataSet</a> endpoints
work great with the <a href="/confluence/display/CAMEL/Testing" title="Testing">Camel
Testing Framework</a> to simplify your unit and integration testing using <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns"
title="Enterprise Integration Patterns">Enterprise Integration Patterns</a> and Camel's
large range of <a href="/confluence/display/CAMEL/Components" title="Components">Components</a>
together with the powerful <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean
Integration">Bean Integration</a>.</p>

<p>The <b>test</b> component extends the <a href="/confluence/display/CAMEL/Mock"
title="Mock">Mock</a> component to support pulling messages from another endpoint
on startup to set the expected message bodies on the underlying <a href="/confluence/display/CAMEL/Mock"
title="Mock">Mock</a> endpoint. That is, you use the test endpoint in a route and
messages arriving on it will be implicitly compared to some expected messages extracted from
some other location.</p>

<p>So you can use, for example, an expected set of message bodies as files. This will
then set up a properly configured <a href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a>
endpoint, which is only valid if the received messages match the number of expected messages
and their message payloads are equal.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component when using <b>Camel 2.8</b> or older:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-spring<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>
<p>From Camel 2.9 onwards the <a href="/confluence/display/CAMEL/Test" title="Test">Test</a>
component is provided directly in the camel-core.</p>


<h3><a name="Test-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
test:expectedMessagesEndpointUri
</pre>
</div></div>

<p>Where <b>expectedMessagesEndpointUri</b> refers to some other <a href="/confluence/display/CAMEL/Component"
title="Component">Component</a> URI that the expected message bodies are pulled from
before starting the test. </p>


<h3><a name="Test-Example"></a>Example</h3>

<p>For example, you could write a test case as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"seda:someEndpoint"</span>).
  to(<span class="code-quote">"test:file:<span class="code-comment">//data/expectedOutput?noop=<span
class="code-keyword">true</span>"</span>);</span>
</pre>
</div></div>

<p>If your test then invokes the <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#assertIsSatisfied(org.apache.camel.CamelContext)"
class="external-link" rel="nofollow">MockEndpoint.assertIsSatisfied(camelContext) method</a>,
your test case will perform the necessary assertions.</p>


<p>To see how you can set other expectations on the test endpoint, see the <a href="/confluence/display/CAMEL/Mock"
title="Mock">Mock</a> component.</p>

<h3><a name="Test-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Spring+Testing" title="Spring Testing">Spring
Testing</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Test">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=76577&revisedVersion=11&originalVersion=10">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Test?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message