Author: davsclaus
Date: Sun Apr 10 14:38:16 2011
New Revision: 1090809

URL: http://svn.apache.org/viewvc?rev=1090809&view=rev
Log:
CAMEL-3556: Added test for using wire tap in CBR.

Added:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithWireTapTest.java
      - copied, changed from r1090751, 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1090809&r1=1090808&r2=1090809&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 Sun Apr 10 14:38:16 2011
@@ -1928,8 +1928,8 @@ public abstract class ProcessorDefinitio
      * @param uri  the destination
      * @return the builder
      */
-    public WireTapDefinition wireTap(String uri) {
-        WireTapDefinition answer = new WireTapDefinition();
+    public WireTapDefinition<Type> wireTap(String uri) {
+        WireTapDefinition<Type> answer = new WireTapDefinition<Type>();
         answer.setUri(uri);
         addOutput(answer);
         return answer;
@@ -1945,11 +1945,11 @@ public abstract class ProcessorDefinitio
      * @param      executorService a custom {@link ExecutorService} to use as 
thread pool
      *             for sending tapped exchanges
      * @return the builder
-     * @deprecated use the fluent builder from {@link WireTapDefinition}
+     * @deprecated use the fluent builder from {@link WireTapDefinition}, will 
be removed in Camel 3.0
      */
     @Deprecated
-    public WireTapDefinition wireTap(String uri, ExecutorService 
executorService) {
-        WireTapDefinition answer = new WireTapDefinition();
+    public WireTapDefinition<Type> wireTap(String uri, ExecutorService 
executorService) {
+        WireTapDefinition<Type> answer = new WireTapDefinition<Type>();
         answer.setUri(uri);
         answer.setExecutorService(executorService);
         addOutput(answer);
@@ -1966,11 +1966,11 @@ public abstract class ProcessorDefinitio
      * @param      executorServiceRef reference to lookup a custom {@link 
ExecutorService}
      *             to use as thread pool for sending tapped exchanges
      * @return the builder
-     * @deprecated use the fluent builder from {@link WireTapDefinition}
+     * @deprecated use the fluent builder from {@link WireTapDefinition}, will 
be removed in Camel 3.0
      */
     @Deprecated
-    public WireTapDefinition wireTap(String uri, String executorServiceRef) {
-        WireTapDefinition answer = new WireTapDefinition();
+    public WireTapDefinition<Type> wireTap(String uri, String 
executorServiceRef) {
+        WireTapDefinition<Type> answer = new WireTapDefinition<Type>();
         answer.setUri(uri);
         answer.setExecutorServiceRef(executorServiceRef);
         addOutput(answer);
@@ -1988,10 +1988,10 @@ public abstract class ProcessorDefinitio
      * @param uri  the destination
      * @param body expression that creates the body to send
      * @return the builder
-     * @deprecated use the fluent builder from {@link WireTapDefinition}
+     * @deprecated use the fluent builder from {@link WireTapDefinition}, will 
be removed in Camel 3.0
      */
     @Deprecated
-    public WireTapDefinition wireTap(String uri, Expression body) {
+    public WireTapDefinition<Type> wireTap(String uri, Expression body) {
         return wireTap(uri, true, body);
     }
 
@@ -2004,11 +2004,11 @@ public abstract class ProcessorDefinitio
      * @param copy whether or not use a copy of the original exchange or a new 
empty exchange
      * @param body expression that creates the body to send
      * @return the builder
-     * @deprecated use the fluent builder from {@link WireTapDefinition}
+     * @deprecated use the fluent builder from {@link WireTapDefinition}, will 
be removed in Camel 3.0
      */
     @Deprecated
-    public WireTapDefinition wireTap(String uri, boolean copy, Expression 
body) {
-        WireTapDefinition answer = new WireTapDefinition();
+    public WireTapDefinition<Type> wireTap(String uri, boolean copy, 
Expression body) {
+        WireTapDefinition<Type> answer = new WireTapDefinition<Type>();
         answer.setUri(uri);
         answer.setCopy(copy);
         answer.setNewExchangeExpression(body);
@@ -2027,10 +2027,10 @@ public abstract class ProcessorDefinitio
      * @param uri  the destination
      * @param processor  processor preparing the new exchange to send
      * @return the builder
-     * @deprecated use the fluent builder from {@link WireTapDefinition}
+     * @deprecated use the fluent builder from {@link WireTapDefinition}, will 
be removed in Camel 3.0
      */
     @Deprecated
-    public WireTapDefinition wireTap(String uri, Processor processor) {
+    public WireTapDefinition<Type> wireTap(String uri, Processor processor) {
         return wireTap(uri, true, processor);
     }
 
@@ -2043,11 +2043,11 @@ public abstract class ProcessorDefinitio
      * @param copy whether or not use a copy of the original exchange or a new 
empty exchange
      * @param processor  processor preparing the new exchange to send
      * @return the builder
-     * @deprecated use the fluent builder from {@link WireTapDefinition}
+     * @deprecated use the fluent builder from {@link WireTapDefinition}, will 
be removed in Camel 3.0
      */
     @Deprecated
-    public WireTapDefinition wireTap(String uri, boolean copy, Processor 
processor) {
-        WireTapDefinition answer = new WireTapDefinition();
+    public WireTapDefinition<Type> wireTap(String uri, boolean copy, Processor 
processor) {
+        WireTapDefinition<Type> answer = new WireTapDefinition<Type>();
         answer.setUri(uri);
         answer.setCopy(copy);
         answer.setNewExchangeProcessor(processor);

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java?rev=1090809&r1=1090808&r2=1090809&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
 Sun Apr 10 14:38:16 2011
@@ -38,9 +38,16 @@ import org.apache.camel.util.concurrent.
  */
 @XmlRootElement(name = "wireTap")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class WireTapDefinition extends SendDefinition<WireTapDefinition> 
implements ExecutorServiceAwareDefinition<ProcessorDefinition> {
+public class WireTapDefinition<Type extends ProcessorDefinition> extends 
NoOutputDefinition implements 
ExecutorServiceAwareDefinition<ProcessorDefinition> {
+    @XmlAttribute
+    protected String uri;
+    @XmlAttribute
+    protected String ref;
+    @XmlTransient
+    protected Endpoint endpoint;
     @XmlTransient
     private Processor newExchangeProcessor;
+    // TODO: Should be named newExchangeRef instead of processorRef (Camel 3.0)
     @XmlAttribute(name = "processorRef")
     private String newExchangeProcessorRef;
     @XmlElement(name = "body")
@@ -110,11 +117,31 @@ public class WireTapDefinition extends S
     }
 
     @Override
+    @SuppressWarnings("unchecked")
+    public Type end() {
+        // allow end() to return to previous type so you can continue in the 
DSL
+        return (Type) super.end();
+    }
+
+    @Override
     public void addOutput(ProcessorDefinition output) {
         // add outputs on parent as this wiretap does not support outputs
         getParent().addOutput(output);
     }
 
+    public Endpoint resolveEndpoint(RouteContext context) {
+        if (endpoint == null) {
+            return context.resolveEndpoint(getUri(), getRef());
+        } else {
+            return endpoint;
+        }
+    }
+
+    @Override
+    public String getLabel() {
+        return FromDefinition.description(getUri(), getRef(), getEndpoint());
+    }
+
     // Fluent API
     // 
-------------------------------------------------------------------------
 
@@ -125,7 +152,7 @@ public class WireTapDefinition extends S
      *                        for sending tapped exchanges
      * @return the builder
      */
-    public WireTapDefinition executorService(ExecutorService executorService) {
+    public WireTapDefinition<Type> executorService(ExecutorService 
executorService) {
         setExecutorService(executorService);
         return this;
     }
@@ -137,7 +164,7 @@ public class WireTapDefinition extends S
      *                           to use as thread pool for sending tapped 
exchanges
      * @return the builder
      */
-    public WireTapDefinition executorServiceRef(String executorServiceRef) {
+    public WireTapDefinition<Type> executorServiceRef(String 
executorServiceRef) {
         setExecutorServiceRef(executorServiceRef);
         return this;
     }
@@ -147,7 +174,7 @@ public class WireTapDefinition extends S
      *
      * @return the builder
      */
-    public WireTapDefinition copy() {
+    public WireTapDefinition<Type> copy() {
         setCopy(true);
         return this;
     }
@@ -158,7 +185,7 @@ public class WireTapDefinition extends S
      * @param expression expression that creates the new body to send
      * @return the builder
      */
-    public WireTapDefinition newExchange(Expression expression) {
+    public WireTapDefinition<Type> newExchange(Expression expression) {
         setNewExchangeExpression(expression);
         return this;
     }
@@ -169,7 +196,7 @@ public class WireTapDefinition extends S
      * @param processor  processor preparing the new exchange to send
      * @return the builder
      */
-    public WireTapDefinition newExchange(Processor processor) {
+    public WireTapDefinition<Type> newExchange(Processor processor) {
         setNewExchangeProcessor(processor);
         return this;
     }
@@ -181,7 +208,7 @@ public class WireTapDefinition extends S
      *            be used for preparing the new exchange to send
      * @return the builder
      */
-    public WireTapDefinition newExchangeRef(String ref) {
+    public WireTapDefinition<Type> newExchangeRef(String ref) {
         setNewExchangeProcessorRef(ref);
         return this;
     }
@@ -194,7 +221,7 @@ public class WireTapDefinition extends S
      * @param onPrepare the processor
      * @return the builder
      */
-    public WireTapDefinition onPrepare(Processor onPrepare) {
+    public WireTapDefinition<Type> onPrepare(Processor onPrepare) {
         setOnPrepare(onPrepare);
         return this;
     }
@@ -207,11 +234,35 @@ public class WireTapDefinition extends S
      * @param onPrepareRef reference to the processor to lookup in the {@link 
org.apache.camel.spi.Registry}
      * @return the builder
      */
-    public WireTapDefinition onPrepareRef(String onPrepareRef) {
+    public WireTapDefinition<Type> onPrepareRef(String onPrepareRef) {
         setOnPrepareRef(onPrepareRef);
         return this;
     }
 
+    public String getUri() {
+        return uri;
+    }
+
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
+    public String getRef() {
+        return ref;
+    }
+
+    public void setRef(String ref) {
+        this.ref = ref;
+    }
+
+    public Endpoint getEndpoint() {
+        return endpoint;
+    }
+
+    public void setEndpoint(Endpoint endpoint) {
+        this.endpoint = endpoint;
+    }
+
     public Processor getNewExchangeProcessor() {
         return newExchangeProcessor;
     }

Copied: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithWireTapTest.java
 (from r1090751, 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithWireTapTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithWireTapTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java&r1=1090751&r2=1090809&rev=1090809&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithWireTapTest.java
 Sun Apr 10 14:38:16 2011
@@ -22,32 +22,32 @@ import org.apache.camel.builder.RouteBui
 /**
  * @version 
  */
-public class CBRWithRecipientListTest extends ContextTestSupport {
+public class CBRWithWireTapTest extends ContextTestSupport {
 
-    public void testCBRWithRecipientListFoo() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(0);
-        getMockEndpoint("mock:foo").expectedMessageCount(1);
-        getMockEndpoint("mock:bar").expectedMessageCount(0);
+    public void testCBRWithWireTapCamel() throws Exception {
+        getMockEndpoint("mock:other").expectedMessageCount(0);
+        getMockEndpoint("mock:camel").expectedMessageCount(1);
+        getMockEndpoint("mock:donkey").expectedMessageCount(0);
 
-        template.sendBodyAndHeader("direct:start", "Camel rules", "foo", 
"mock:foo");
+        template.sendBody("direct:start", "Camel rules");
 
         assertMockEndpointsSatisfied();
     }
 
-    public void testCBRWithRecipientListBar() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(0);
-        getMockEndpoint("mock:foo").expectedMessageCount(0);
-        getMockEndpoint("mock:bar").expectedMessageCount(1);
+    public void testCBRWithWireTapDonkey() throws Exception {
+        getMockEndpoint("mock:other").expectedMessageCount(0);
+        getMockEndpoint("mock:camel").expectedMessageCount(0);
+        getMockEndpoint("mock:donkey").expectedMessageCount(1);
 
-        template.sendBodyAndHeader("direct:start", "Donkey Kong", "bar", 
"mock:bar");
+        template.sendBody("direct:start", "Donkey kong");
 
         assertMockEndpointsSatisfied();
     }
 
-    public void testCBRWithRecipientListResult() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(1);
-        getMockEndpoint("mock:foo").expectedMessageCount(0);
-        getMockEndpoint("mock:bar").expectedMessageCount(0);
+    public void testCBRWithWireTapOther() throws Exception {
+        getMockEndpoint("mock:other").expectedMessageCount(1);
+        getMockEndpoint("mock:camel").expectedMessageCount(0);
+        getMockEndpoint("mock:donkey").expectedMessageCount(0);
 
         template.sendBody("direct:start", "Hello World");
 
@@ -62,11 +62,11 @@ public class CBRWithRecipientListTest ex
                 from("direct:start")
                     .choice()
                         .when(body().contains("Camel"))
-                            .recipientList(header("foo")).end()
+                            .wireTap("mock:camel").end()
                         .when(body().contains("Donkey"))
-                            .recipientList(header("bar")).end()
+                            .wireTap("mock:donkey").copy().end()
                         .otherwise()
-                            .to("mock:result");
+                            .to("mock:other");
             }
         };
     }


Reply via email to