camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: CAMEL-9805: camel-sql - body not copied from in to out when useing outputHeader and outputType=SelectOne when sql doesn't return a result
Date Thu, 28 Apr 2016 08:14:57 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 9216caf3d -> 54b3bf740


CAMEL-9805: camel-sql - body not copied from in to out when useing outputHeader and outputType=SelectOne
when sql doesn't return a result


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

Branch: refs/heads/camel-2.16.x
Commit: 680444ea87800ad22166cc33ef8e20315c172f9a
Parents: 9216caf
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Apr 28 09:35:28 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Apr 28 09:57:28 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/component/sql/SqlProducer.java |  7 +++
 ...ProducerOutputTypeSelectOneNoResultTest.java | 61 ++++++++++++++++++++
 .../sql/createAndPopulateDatabase5.sql          |  6 ++
 3 files changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/680444ea/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
index 9f2e9d2..7db8772 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
@@ -175,6 +175,13 @@ public class SqlProducer extends DefaultProducer {
                                         exchange.getOut().setBody(data);
                                     }
                                     exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT,
1);
+                                } else { 
+                                    if (getEndpoint().isNoop()) {
+                                        exchange.getOut().setBody(exchange.getIn().getBody());
+                                    } else if (getEndpoint().getOutputHeader() != null) {
+                                        exchange.getOut().setBody(exchange.getIn().getBody());
+                                    }
+                                    exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT,
0);
                                 }
                             } else {
                                 throw new IllegalArgumentException("Invalid outputType="
+ outputType);

http://git-wip-us.apache.org/repos/asf/camel/blob/680444ea/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerOutputTypeSelectOneNoResultTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerOutputTypeSelectOneNoResultTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerOutputTypeSelectOneNoResultTest.java
new file mode 100644
index 0000000..a476d68
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerOutputTypeSelectOneNoResultTest.java
@@ -0,0 +1,61 @@
+package org.apache.camel.component.sql;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.junit.After;
+import org.junit.Before;
+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 SqlProducerOutputTypeSelectOneNoResultTest extends CamelTestSupport{
+
+    @EndpointInject(uri = "mock:result")
+    MockEndpoint result;
+
+    private EmbeddedDatabase db;
+
+    @Before
+    public void setUp() throws Exception {
+        db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase5.sql").build();
+
+        super.setUp();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        db.shutdown();
+    }
+    
+	@Test
+	public void testSqlEndpoint() throws Exception {
+
+		String expectedBody = "body";
+		result.expectedBodiesReceived(expectedBody);
+		template.sendBody("direct:start",expectedBody);
+		result.assertIsSatisfied();
+
+	}
+    
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                getContext().getComponent("sql", SqlComponent.class).setDataSource(db);
+
+				from("direct:start")
+				.to("sql:select id from mytable where 1 = 2?outputHeader=myHeader&outputType=SelectOne")
+				.log("${body}").to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/680444ea/components/camel-sql/src/test/resources/sql/createAndPopulateDatabase5.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/createAndPopulateDatabase5.sql b/components/camel-sql/src/test/resources/sql/createAndPopulateDatabase5.sql
new file mode 100644
index 0000000..f1b3007
--- /dev/null
+++ b/components/camel-sql/src/test/resources/sql/createAndPopulateDatabase5.sql
@@ -0,0 +1,6 @@
+CREATE TABLE MYTABLE (
+	ID  INT PRIMARY KEY,
+  	SUBJECT         VARCHAR(255)
+);
+
+insert into MYTABLE (ID, SUBJECT) VALUES (1, 'subject');


Mime
View raw message