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 Wed, 05 Jun 2013 09:22: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 (2)</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" >Where *expectedMessagesEndpointUri*
refers to some other [Component] URI that the expected message bodies are pulled from before
starting the test.  <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
URI Options <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div:class=confluenceTableSmall}
<br>|| Name || Default Value || Description || <br>| {{timeout}} | {{2000}} |
*Camel 2.12:* The timeout to use when polling for message bodies from the URI. | <br>{div}
<br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Example <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-URIOptions"></a>URI Options</h3>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>2000</tt> </td>
<td class='confluenceTd'> <b>Camel 2.12:</b> The timeout to use when polling
for message bodies from the URI. </td>
</tr>
</tbody></table>
</div>
</div>


<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=12&originalVersion=11">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