camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r1043819 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/util/ObjectHelper.java test/java/org/apache/camel/processor/SplitterTest.java test/java/org/apache/camel/util/ObjectHelperTest.java
Date Thu, 09 Dec 2010 02:03:35 GMT
Author: ammulder
Date: Thu Dec  9 02:03:35 2010
New Revision: 1043819

URL: http://svn.apache.org/viewvc?rev=1043819&view=rev
Log:
Make splitter support Iterable (CAMEL-3415)

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java

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=1043819&r1=1043818&r2=1043819&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 Thu Dec 
9 02:03:35 2010
@@ -477,6 +477,8 @@ public final class ObjectHelper {
             return Collections.emptyList().iterator();
         } else if (value instanceof Iterator) {
             return (Iterator)value;
+        } else if (value instanceof Iterable) {
+            return ((Iterable)value).iterator();
         } else if (value instanceof Collection) {
             Collection collection = (Collection)value;
             return collection.iterator();

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java?rev=1043819&r1=1043818&r2=1043819&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java Thu
Dec  9 02:03:35 2010
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.processor;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -203,6 +206,20 @@ public class SplitterTest extends Contex
         assertMockEndpointsSatisfied();
     }
 
+    public void testSplitterWithIterable() throws Exception {
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+        resultEndpoint.expectedMessageCount(4);
+        resultEndpoint.expectedBodiesReceived("A","B","C","D");
+        final List<String> data = Arrays.asList("A","B","C","D");
+        Iterable itb = new Iterable() {
+            public Iterator iterator() {
+                return data.iterator();
+            }
+        };
+        sendBody("direct:simple", itb);
+        resultEndpoint.assertIsSatisfied();
+    }
+
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
@@ -229,6 +246,8 @@ public class SplitterTest extends Contex
                         
                         }                    
                     }).to("mock:result");
+
+                from("direct:simple").split(body()).to("mock:result");
             }
         };
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java?rev=1043819&r1=1043818&r2=1043819&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java Thu Dec
 9 02:03:35 2010
@@ -269,7 +269,24 @@ public class ObjectHelperTest extends Te
         Iterator<Object> it = ObjectHelper.createIterator(msg);
         assertFalse(it.hasNext());
     }
-    
+
+    public void testIterable() {
+        final List<String> data = new ArrayList<String>();
+        data.add("A");
+        data.add("B");
+        data.add("C");
+        Iterable<String> itb = new Iterable<String>() {
+            public Iterator<String> iterator() {
+                return data.iterator();
+            }
+        };
+        Iterator<String> it = CastUtils.cast(ObjectHelper.createIterator(itb));
+        assertEquals("A", it.next());
+        assertEquals("B", it.next());
+        assertEquals("C", it.next());
+        assertFalse(it.hasNext());
+    }
+
     public void testNormalizeClassName() {
         assertEquals("Should get the right class name", "my.package-info", ObjectHelper.normalizeClassName("my.package-info"));
         assertEquals("Should get the right class name", "Integer[]", ObjectHelper.normalizeClassName("Integer[]
\r"));



Mime
View raw message