camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1460015 - in /camel/trunk/components/camel-sql/src: main/java/org/apache/camel/component/sql/SqlComponent.java test/java/org/apache/camel/component/sql/SqlDataSourceTest.java
Date Fri, 22 Mar 2013 21:49:03 GMT
Author: cmueller
Date: Fri Mar 22 21:49:03 2013
New Revision: 1460015

URL: http://svn.apache.org/r1460015
Log:
CAMEL-6076: deprecate the xxxRef options and provide the xxx option if it not exists yet -
work in progress

Added:
    camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceTest.java
Modified:
    camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java

Modified: camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java?rev=1460015&r1=1460014&r2=1460015&view=diff
==============================================================================
--- camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
(original)
+++ camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
Fri Mar 22 21:49:03 2013
@@ -42,10 +42,19 @@ public class SqlComponent extends Defaul
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-        String dataSourceRef = getAndRemoveParameter(parameters, "dataSourceRef", String.class);
-        if (dataSourceRef != null) {
-            dataSource = CamelContextHelper.mandatoryLookup(getCamelContext(), dataSourceRef,
DataSource.class);
+        DataSource ds = resolveAndRemoveReferenceParameter(parameters, "dataSource", DataSource.class);
+        if (ds != null) {
+            dataSource = ds;
         }
+
+        //TODO cmueller: remove the 'dataSourceRef' lookup in Camel 3.0
+        if (dataSource == null) {
+            String dataSourceRef = getAndRemoveParameter(parameters, "dataSourceRef", String.class);
+            if (dataSourceRef != null) {
+                dataSource = CamelContextHelper.mandatoryLookup(getCamelContext(), dataSourceRef,
DataSource.class);
+            }
+        }
+
         String parameterPlaceholderSubstitute = getAndRemoveParameter(parameters, "placeholder",
String.class, "#");
         
         JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

Added: camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceTest.java?rev=1460015&view=auto
==============================================================================
--- camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceTest.java
(added)
+++ camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceTest.java
Fri Mar 22 21:49:03 2013
@@ -0,0 +1,86 @@
+/**
+ * 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.sql;
+
+import java.util.List;
+import java.util.Map;
+
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.After;
+import org.junit.Test;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
+
+public class SqlDataSourceTest extends CamelTestSupport {
+
+    private EmbeddedDatabase db;
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+
+        // this is the database we create with some initial data for our unit test
+        db = new EmbeddedDatabaseBuilder()
+            .setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase.sql").build();
+
+        jndi.bind("dataSource", db);
+
+        return jndi;
+    }
+
+    @Test
+    public void testSimpleBody() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:simple", "XXX");
+
+        mock.assertIsSatisfied();
+
+        // the result is a List
+        List<?> received = assertIsInstanceOf(List.class, mock.getReceivedExchanges().get(0).getIn().getBody());
+
+        // and each row in the list is a Map
+        Map<?, ?> row = assertIsInstanceOf(Map.class, received.get(0));
+
+        // and we should be able the get the project from the map that should be Linux
+        assertEquals("Linux", row.get("PROJECT"));
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        db.shutdown();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:simple")
+                    .to("sql:select * from projects where license = # order by id?dataSource=dataSource")
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file



Mime
View raw message