Author: buildbot Date: Wed Mar 6 09:19:24 2013 New Revision: 853240 Log: Production update by buildbot for camel
Modified: websites/production/camel/content/advicewith.html websites/production/camel/content/cache/main.pageCache Modified: websites/production/camel/content/advicewith.html ============================================================================== --- websites/production/camel/content/advicewith.html (original) +++ websites/production/camel/content/advicewith.html Wed Mar 6 09:19:24 2013 @@ -76,9 +76,10 @@ <tr> <td valign="top" width="100%"> <div class="wiki-content maincontent"><h2><a shape="rect" name="AdviceWith-AdviceWith"></a>AdviceWith</h2> + <p><b>Available as of Camel 2.1</b></p> -<p>AdviceWith is used for testing Camel routes where you can <em>advice</em> an existing route before its being tested. What <tt>adviceWith</tt> allows is to changes some factors on the route before the test is being run. </p> +<p>AdviceWith is used for testing Camel routes where you can <em>advice</em> an existing route before its being tested. What <tt>adviceWith</tt> allows is to changes some factors on the route before the test is being run.</p> <p>At current time you can <em>advice</em> an existing route by adding <a shape="rect" href="intercept.html" title="Intercept">Intercept</a>, <a shape="rect" href="exception-clause.html" title="Exception Clause">Exception Clause</a> etc. which then will apply for the route being advice.</p> @@ -114,6 +115,7 @@ The Camel team plan for Camel 3.0 to sup <div class="panelMacro"><table class="tipMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1"><b>Telling Camel you are using adviceWith</b><br clear="none">From <b>Camel 2.9</b> onwards its recommended to override the <tt>isUseAdviceWith</tt> method and return true to tell Camel you are using advice with in your unit tests. Then after you have done the adviceWith, then you must start <tt>CamelContext</tt> manually. See further below for an example.</td></tr></table></div> <h3><a shape="rect" name="AdviceWith-UsingAdviceWithRouteBuilder"></a>Using AdviceWithRouteBuilder</h3> + <p><b>Available as of Camel 2.7</b></p> <p>The <tt>AdviceWithRouteBuilder</tt> is a specialized <tt>RouteBuilder</tt> which has additional methods for advising routes. For example this allows you to manipulate the advised route, such as replacing a node with some other nodes.</p> @@ -136,7 +138,7 @@ The regular expression is more advanced <h3><a shape="rect" name="AdviceWith-UsingweaveById"></a>Using weaveById</h3> -<p>The <tt>weaveById</tt> allows you to manipulate the rote, for example by replacing a node with other nodes. The following methods is available:</p> +<p>The <tt>weaveById</tt> allows you to manipulate the route, for example by replacing a node with other nodes. The following methods is available:</p> <div class="table-wrap"> <table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Method </th><th colspan="1" rowspan="1" class="confluenceTh"> Description </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>remove</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> Removes the selected node(s). </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>replace</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> Replaces the selected node(s) with the following nodes. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>before</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> Before the selected node(s), the following nodes is added. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>after</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> After the selected node(s), the following nodes is added. </td></tr></tbody></table> @@ -145,8 +147,7 @@ The regular expression is more advanced <p>For example given the following route:</p> <div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Route</b></div><div class="codeContent panelContent"> -<pre class="code-java"> -from(<span class="code-quote">"direct:start"</span>) +<pre class="code-java">from(<span class="code-quote">"direct:start"</span>) .to(<span class="code-quote">"mock:foo"</span>) .to(<span class="code-quote">"mock:bar"</span>).id(<span class="code-quote">"bar"</span>) .to(<span class="code-quote">"mock:result"</span>); @@ -228,10 +229,11 @@ You have to be a bit more careful when u </pre> </div></div> -<p>Notice that we have to use <tt>".*foo.*"</tt> in the pattern to match that <tt>"foo"</tt> is present anywhere in the string.</p> +<p>Notice that we have to use <tt>".<b>foo.</b>"</tt> in the pattern to match that <tt>"foo"</tt> is present anywhere in the string.</p> <h3><a shape="rect" name="AdviceWith-UsingweaveByType"></a>Using weaveByType</h3> + <p><b>Available as of Camel 2.8</b></p> <p>The <tt>weaveByToType</tt> also allows you to manipulate the route, for example by replacing a node with other nodes. As opposed to <tt>weaveById</tt>, and <tt>weaveByToString</tt> this method uses the class type of the node(s) when matching. This allows you to match <a shape="rect" href="eip.html" title="EIP">EIP</a> pattern by its type.</p> @@ -261,6 +263,7 @@ You have to be a bit more careful when u <h3><a shape="rect" name="AdviceWith-Usingselectors"></a>Using selectors</h3> + <p><b>Available os of Camel 2.8</b></p> <p>The following methods <tt>weaveById(pattern)</tt>, <tt>weaveByToString(pattern)</tt> and <tt>weaveByType(Class)</tt> each match N+ nodes. By using optional selectors you can narrow down the nodes being used. For example if <tt>weaveByType(Class)</tt> returns 2 nodes. Then you can use a selector to indicate it should only select the first node.</p> @@ -272,8 +275,7 @@ You have to be a bit more careful when u <p>For example to remove the first <tt>.to</tt> node in route you can do as follows:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { +<pre class="code-java">context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { @Override <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception { <span class="code-comment">// only remove the first to node in the route @@ -285,14 +287,14 @@ context.getRouteDefinitions().get(0).adv <h3><a shape="rect" name="AdviceWith-UsingweaveAddFirst%2FweaveAddLast"></a>Using weaveAddFirst / weaveAddLast</h3> + <p><b>Available os of Camel 2.8</b></p> <p>The <tt>weaveAddFirst</tt> and <tt>weaveAddLast</tt> is a shorthand to easily add nodes to the route. These methods can only <b>add</b> to an existing routes. If you want to manipulate the route, then there are plenty of methods as already shown on this page.</p> <p>For example if you want to send a message to a <tt>mock:input</tt> endpoint you can do as follows:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { +<pre class="code-java">context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { @Override <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception { <span class="code-comment">// send the incoming message to mock:input @@ -304,8 +306,7 @@ context.getRouteDefinitions().get(0).adv <p>Likewise if you want to easily send a message to a <tt>mock:output</tt> endpoint you can do as follows:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { +<pre class="code-java">context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { @Override <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception { <span class="code-comment">// send the outgoing message to mock:output @@ -317,8 +318,7 @@ context.getRouteDefinitions().get(0).adv <p>You can of course combine those in the same advice with:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { +<pre class="code-java">context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { @Override <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception { weaveAddFirst().to(<span class="code-quote">"mock:input"</span>); @@ -329,12 +329,12 @@ context.getRouteDefinitions().get(0).adv </div></div> <h3><a shape="rect" name="AdviceWith-Replacefromwithanotherendpoint"></a>Replace from with another endpoint</h3> + <p><b>Available as of Camel 2.9</b></p> <p>You may have routes which consumes messages from endpoints which you want to substitute with another endpoint for easier unit testing. For example a <a shape="rect" href="jms.html" title="JMS">JMS</a> endpoint could be replaced with a <a shape="rect" href="seda.html" title="SEDA">SEDA</a> or <a shape="rect" href="direct.html" title="Direct">Direct</a> for unit testing a route, as shown below where we replace the input of the route to a "seda:foo" endpoint:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { +<pre class="code-java">context.getRouteDefinitions().get(0).adviceWith(context, <span class="code-keyword">new</span> AdviceWithRouteBuilder() { @Override <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span> Exception { replaceFromWith(<span class="code-quote">"seda:foo"</span>); @@ -350,8 +350,9 @@ context.getRouteDefinitions().get(0).adv <p>See more details at the section <em>Mocking existing endpoints using the camel-test component</em> at <a shape="rect" href="mock.html" title="Mock">Mock</a>.</p> <h3><a shape="rect" name="AdviceWith-UsingisUseAdviceWith"></a>Using isUseAdviceWith</h3> + <p><b>Available as of Camel 2.9</b><br clear="none"> -It is recommended to override the method <tt>isUseAdviceWith</tt> and return <tt>true</tt> to instruct Camel that you are using <tt>adviceWith</tt> in the unit tests. Then in your unit test methods, after you have done the <tt>adviceWith</tt> you <b>must</b> start <tt>CamelContext</tt> by invoke the <tt>start</tt> method on the <tt>context</tt> instance. In the following we have an example. The route is using <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a> to route messages. What we would like to do in a unit test is to test the route, but without having to set and use <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a>. We do not have <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a> on the classpath. So for that we need to advice the route and replace <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a> with for example a <a shape="rect" href="seda.html" title="SEDA">SEDA</a> endpoint instead. </p> +It is recommended to override the method <tt>isUseAdviceWith</tt> and return <tt>true</tt> to instruct Camel that you are using <tt>adviceWith</tt> in the unit tests. Then in your unit test methods, after you have done the <tt>adviceWith</tt> you <b>must</b> start <tt>CamelContext</tt> by invoke the <tt>start</tt> method on the <tt>context</tt> instance. In the following we have an example. The route is using <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a> to route messages. What we would like to do in a unit test is to test the route, but without having to set and use <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a>. We do not have <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a> on the classpath. So for that we need to advice the route and replace <a shape="rect" href="activemq.html" title="ActiveMQ">ActiveMQ</a> with for example a <a shape="rect" href="seda.html" title="SEDA">SEDA</a> endpoint instead.</p> <div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>isUseAdviceWith</b></div><div class="codeContent panelContent"> <pre class="code-java"><span class="code-keyword">public</span> class IsUseAdviceWithJUnit4Test <span class="code-keyword">extends</span> org.apache.camel.test.junit4.CamelTestSupport { Modified: websites/production/camel/content/cache/main.pageCache ============================================================================== Binary files - no diff available.