You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/10/20 12:24:08 UTC

svn commit: r827025 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/util/ components/camel-http/src/main/java/org/apache/camel/component/http/ components/camel-jetty/src/test/java/org/apache/camel...

Author: davsclaus
Date: Tue Oct 20 10:24:06 2009
New Revision: 827025

URL: http://svn.apache.org/viewvc?rev=827025&view=rev
Log:
MR-194: Added more unit tests.

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java   (with props)
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java   (with props)
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExecutionException.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExecutionException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExecutionException.java?rev=827025&r1=827024&r2=827025&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExecutionException.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExecutionException.java Tue Oct 20 10:24:06 2009
@@ -17,7 +17,7 @@
 package org.apache.camel;
 
 /**
- * Exception occured during execution/processing of an {@link Exchange}.
+ * Exception occurred during execution/processing of an {@link Exchange}.
  * <p/>
  * Is usually thrown to the caller when using the {@link org.apache.camel.ProducerTemplate}
  * to send messages to Camel.

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=827025&r1=827024&r2=827025&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Tue Oct 20 10:24:06 2009
@@ -1050,7 +1050,7 @@
             // don't double wrap
             return (CamelExecutionException)e;
         } else {
-            return new CamelExecutionException("Exception occured during execution", exchange, e);
+            return new CamelExecutionException("Exception occurred during execution", exchange, e);
         }
     }
 

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java?rev=827025&r1=827024&r2=827025&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java Tue Oct 20 10:24:06 2009
@@ -50,14 +50,6 @@
         }
     }
 
-    public HttpMethod createMethod() {
-        try {
-            return clazz.newInstance();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     public final boolean isEntityEnclosing() {
         return entity;
     }

Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java?rev=827025&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java Tue Oct 20 10:24:06 2009
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import java.io.InputStream;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpConverter;
+import org.apache.camel.component.http.HttpMessage;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpConverterTest extends CamelTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testToServletInputStream() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty://http://localhost:9080/test").
+                        process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                HttpMessage msg = exchange.getIn(HttpMessage.class);
+
+                                ServletInputStream sis = HttpConverter.toServletInputStream(msg);
+                                assertNotNull(sis);
+                                String s = exchange.getContext().getTypeConverter().convertTo(String.class, sis);
+
+                                assertEquals("Hello World", s);
+                            }
+                        }).transform(constant("Bye World"));
+            }
+        });
+        context.start();
+
+        String out = template.requestBody("http://localhost:9080/test", "Hello World", String.class);
+        assertEquals("Bye World", out);
+    }
+
+    @Test
+    public void testToInputStream() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty://http://localhost:9080/test").
+                        process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                HttpMessage msg = exchange.getIn(HttpMessage.class);
+
+                                InputStream sis = HttpConverter.toInputStream(msg);
+                                assertNotNull(sis);
+                                String s = exchange.getContext().getTypeConverter().convertTo(String.class, sis);
+
+                                assertEquals("Hello World", s);
+                            }
+                        }).transform(constant("Bye World"));
+            }
+        });
+        context.start();
+
+        String out = template.requestBody("http://localhost:9080/test", "Hello World", String.class);
+        assertEquals("Bye World", out);
+    }
+
+    @Test
+    public void testNulls() throws Exception {
+        HttpMessage msg = null;
+        assertNull(HttpConverter.toInputStream(msg));
+        assertNull(HttpConverter.toServletInputStream(msg));
+        assertNull(HttpConverter.toServletRequest(msg));
+        assertNull(HttpConverter.toServletResponse(msg));
+
+        HttpServletRequest req = null;
+        assertNull(HttpConverter.toInputStream(req));
+    }
+
+}

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java?rev=827025&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java Tue Oct 20 10:24:06 2009
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpReturnDataNotInputStreamConvertableTest extends CamelTestSupport {
+
+    @Test
+    public void testHttpReturnDataNotInputStreamConvertableTest() throws Exception {
+        String out = template.requestBody("http://localhost:9080/test", "Hello World", String.class);
+        assertEquals("This is the response", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty://http://localhost:9080/test")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            exchange.getOut().setBody(new MyResponseBean());
+                        }
+                    });
+            }
+        };
+    }
+
+    private class MyResponseBean {
+        @Override
+        public String toString() {
+            return "This is the response";
+        }
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java?rev=827025&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java Tue Oct 20 10:24:06 2009
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpReturnFaultTest extends CamelTestSupport {
+
+    @Test
+    public void testHttpFault() throws Exception {
+        String out = template.requestBody("http://localhost:9080/test", "Hello World", String.class);
+        assertEquals("This is a fault", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty://http://localhost:9080/test")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            exchange.getOut().setFault(true);
+                            exchange.getOut().setBody("This is a fault");
+                        }
+                    });
+            }
+        };
+    }
+}

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date