You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/06/18 09:00:07 UTC

[2/4] git commit: Added an unit test for camel-http redirect according to the mailing list

Added an unit test for camel-http redirect according to the mailing list


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

Branch: refs/heads/master
Commit: b6a87991c7049e21d8b7249d69101c8584ab4d7d
Parents: a7cd3b7
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Jun 17 11:57:15 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Jun 18 14:56:15 2014 +0800

----------------------------------------------------------------------
 .../camel/component/jetty/HttpRedirectTest.java | 48 ++++++++++++++++----
 1 file changed, 38 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b6a87991/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
index e139e47..cd26dae 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java
@@ -21,10 +21,11 @@ import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.http.HttpOperationFailedException;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Test;
 
 /**
- * @version 
+ * @version
  */
 public class HttpRedirectTest extends BaseJettyTest {
 
@@ -34,7 +35,8 @@ public class HttpRedirectTest extends BaseJettyTest {
             template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class);
             fail("Should have thrown an exception");
         } catch (RuntimeCamelException e) {
-            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class,
+                                                                    e.getCause());
             assertEquals(301, cause.getStatusCode());
             assertEquals(true, cause.isRedirectError());
             assertEquals(true, cause.hasRedirectLocation());
@@ -43,19 +45,45 @@ public class HttpRedirectTest extends BaseJettyTest {
         }
     }
 
+    @Test
+    public void testHttpRedirectFromCamelRoute() throws Exception {
+        MockEndpoint errorEndpoint = context.getEndpoint("mock:error", MockEndpoint.class);
+        errorEndpoint.expectedMessageCount(1);
+        MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
+        resultEndpoint.expectedMessageCount(0);
+        try {
+            template.requestBody("direct:start", "Hello World", String.class);
+            fail("Should have thrown an exception");
+        } catch (RuntimeCamelException e) {
+            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class,
+                                                                    e.getCause());
+            assertEquals(302, cause.getStatusCode());
+        }
+        errorEndpoint.assertIsSatisfied();
+        resultEndpoint.assertIsSatisfied();
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("jetty://http://localhost:{{port}}/test")
-                    .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301);
-                            exchange.getOut().setHeader("location", "http://localhost:" + getPort() + "/newtest");
-                        }
-                    });
+                from("jetty://http://localhost:{{port}}/test").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301);
+                        exchange.getOut().setHeader("location", "http://localhost:" + getPort() + "/newtest");
+                    }
+                });
+                from("jetty://http://localhost:{{port}}/remove").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302);
+                    }
+                });
+                
+                from("direct:start").onException(HttpOperationFailedException.class).to("mock:error").end()
+                    .to("http://localhost:{{port}}/remove?throwExceptionOnFailure=true").to("mock:result");
+
             }
         };
     }
-}
\ No newline at end of file
+}