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 2011/08/30 11:18:58 UTC

svn commit: r1163152 - /camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteKeyOrderingTest.java

Author: davsclaus
Date: Tue Aug 30 09:18:58 2011
New Revision: 1163152

URL: http://svn.apache.org/viewvc?rev=1163152&view=rev
Log:
CAMEL-4350: camel-jdbc should use a linked map so the data is in order according to the ResultSet. Thanks to Mathieu for the patch.

Added:
    camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteKeyOrderingTest.java   (with props)

Added: camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteKeyOrderingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteKeyOrderingTest.java?rev=1163152&view=auto
==============================================================================
--- camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteKeyOrderingTest.java (added)
+++ camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteKeyOrderingTest.java Tue Aug 30 09:18:58 2011
@@ -0,0 +1,79 @@
+/**
+ * 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.jdbc;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.junit.Test;
+
+/**
+ * Tests that key ordering for the Maps (rows) is preserved.
+ * @version
+ */
+public class JdbcRouteKeyOrderingTest extends JdbcRouteTest {
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testJdbcRoutes() throws Exception {
+        // first we create our exchange using the endpoint
+        Endpoint endpoint = context.getEndpoint("direct:hello");
+        
+        // repeat the test often enough to make sure preserved ordering is not a fluke
+        for (int i = 0; i < 10; i++) {
+            Exchange exchange = endpoint.createExchange();
+            // then we set the SQL on the in body
+            exchange.getIn().setBody("select * from customer order by ID");
+
+            // now we send the exchange to the endpoint, and receives the response from Camel
+            Exchange out = template.send(endpoint, exchange);
+
+            // assertions of the response
+            assertNotNull(out);
+            assertNotNull(out.getOut());
+            List<Map<String, Object>> rowList = out.getOut().getBody(List.class);
+            assertNotNull("out body could not be converted to an ArrayList - was: "
+                + out.getOut().getBody(), rowList);
+            assertEquals(2, rowList.size());
+            
+            Map<String, Object> row = rowList.get(0);
+            assertTrue("ordering not preserved " + row.keySet(), isOrdered(row.keySet()));
+            
+            row = rowList.get(1);
+            assertTrue("ordering not preserved " + row.keySet(), isOrdered(row.keySet()));
+        }
+    }
+    
+
+    /**
+     * @param keySet (should have 2 items "ID" & "NAME")
+     * @return true if "ID" comes before "NAME", false otherwise
+     */
+    private static boolean isOrdered(Set<String> keySet) {
+        final String msg = "isOrdered() relies on \"ID\" & \"NAME\" being the only two fields";
+        assertTrue(msg, keySet.contains("ID"));
+        assertTrue(msg, keySet.contains("NAME"));
+        assertEquals(msg, 2, keySet.size());
+        
+        final Iterator<String> iter = keySet.iterator();
+        return "ID".equals(iter.next()) && "NAME".equals(iter.next());
+    }
+}

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

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