camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bibr...@apache.org
Subject git commit: Added replaceRouteFromWith helper method to CamelTestSupport for replacing route's consumer endpoints
Date Tue, 23 Jul 2013 18:59:54 GMT
Updated Branches:
  refs/heads/master a3806a7ab -> 5c952100a


Added replaceRouteFromWith helper method to CamelTestSupport for replacing route's consumer
endpoints


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5c952100
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5c952100
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5c952100

Branch: refs/heads/master
Commit: 5c952100a8b830c6616bf65040f35f35bc7f62a1
Parents: a3806a7
Author: bibryam <bibryam@apache.org>
Authored: Tue Jul 23 19:38:54 2013 +0100
Committer: bibryam <bibryam@apache.org>
Committed: Tue Jul 23 19:59:47 2013 +0100

----------------------------------------------------------------------
 .../camel/test/junit4/CamelTestSupport.java     | 21 +++++++++++
 .../apache/camel/test/CamelTestSupportTest.java | 37 ++++++++++++++++++++
 2 files changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5c952100/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
index 9702810..3beb9af 100644
--- a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
+++ b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
@@ -17,6 +17,7 @@
 package org.apache.camel.test.junit4;
 
 import java.io.InputStream;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
@@ -35,6 +36,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Service;
 import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.component.properties.PropertiesComponent;
@@ -76,6 +78,7 @@ public abstract class CamelTestSupport extends TestSupport {
     private boolean useRouteBuilder = true;
     private final DebugBreakpoint breakpoint = new DebugBreakpoint();
     private final StopWatch watch = new StopWatch();
+    private final Map<String, String> fromEndpoints = new HashMap<String, String>();
 
     /**
      * Use the RouteBuilder or not
@@ -146,6 +149,10 @@ public abstract class CamelTestSupport extends TestSupport {
         return null;
     }
 
+    public void replaceRouteFromWith(String routeId, String fromEndpoint) {
+        fromEndpoints.put(routeId, fromEndpoint);
+    }
+
     /**
      * Override to enable debugger
      * <p/>
@@ -293,6 +300,7 @@ public abstract class CamelTestSupport extends TestSupport {
                 log.debug("Using created route builder: " + builder);
                 context.addRoutes(builder);
             }
+            replaceFromEndpoints();
             boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
             if (skip) {
                 log.info("Skipping starting CamelContext as system property skipStartingCamelContext
is set to be true.");
@@ -302,6 +310,7 @@ public abstract class CamelTestSupport extends TestSupport {
                 startCamelContext();
             }
         } else {
+            replaceFromEndpoints();
             log.debug("Using route builder from the created context: " + context);
         }
         log.debug("Routing Rules are: " + context.getRoutes());
@@ -311,6 +320,18 @@ public abstract class CamelTestSupport extends TestSupport {
         INIT.set(true);
     }
 
+    private void replaceFromEndpoints() throws Exception {
+        for (final Map.Entry<String, String> entry : fromEndpoints.entrySet()) {
+            context.getRouteDefinition(
+                    entry.getKey()).adviceWith(context, new AdviceWithRouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    replaceFromWith(entry.getValue());
+                }
+            });
+        }
+    }
+
     @After
     public void tearDown() throws Exception {
         long time = watch.stop();

http://git-wip-us.apache.org/repos/asf/camel/blob/5c952100/components/camel-test/src/test/java/org/apache/camel/test/CamelTestSupportTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test/src/test/java/org/apache/camel/test/CamelTestSupportTest.java
b/components/camel-test/src/test/java/org/apache/camel/test/CamelTestSupportTest.java
new file mode 100644
index 0000000..9e77bc0
--- /dev/null
+++ b/components/camel-test/src/test/java/org/apache/camel/test/CamelTestSupportTest.java
@@ -0,0 +1,37 @@
+package org.apache.camel.test;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CamelTestSupportTest extends CamelTestSupport {
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        replaceRouteFromWith("routeId", "direct:start");
+        super.setUp();
+    }
+
+    @Test
+    public void replacesFromEndpoint() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:something")
+                        .id("routeId")
+                        .to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message