This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-2.24.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 3606be8d1fdce2fd769e09adcbd7b3e0a7ac0afd Author: Otávio Prado <otavio.pr...@sensedia.com> AuthorDate: Fri Jun 28 21:37:49 2019 -0300 unit test to validate column type --- .../camel/component/jdbc/JdbcColumnTypeTest.java | 53 ++++++++++++++++++++++ .../camel-jdbc/src/test/resources/sql/init.sql | 5 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcColumnTypeTest.java b/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcColumnTypeTest.java new file mode 100644 index 0000000..3f63e8a --- /dev/null +++ b/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcColumnTypeTest.java @@ -0,0 +1,53 @@ +package org.apache.camel.component.jdbc; + +import java.io.InputStream; +import java.io.StringWriter; +import java.sql.Clob; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.logging.log4j.core.util.IOUtils; +import org.junit.Test; + +public class JdbcColumnTypeTest extends AbstractJdbcTestSupport { + + @Test + @SuppressWarnings("unchecked") + public void testClobColumnType() throws SQLException { + Endpoint directHelloEndpoint = context.getEndpoint("direct:hello"); + Exchange directHelloExchange = directHelloEndpoint.createExchange(); + + directHelloExchange.getIn().setBody("select * from tableWithClob"); + + Exchange out = template.send(directHelloEndpoint, directHelloExchange); + assertNotNull(out); + assertNotNull(out.getOut()); + + List<Map<String, Object>> returnValues = out.getOut().getBody(List.class); + assertNotNull(returnValues); + assertEquals(1, returnValues.size()); + Map<String, Object> row = returnValues.get(0); + assertEquals("id1", row.get("ID")); + assertNotNull(row.get("PICTURE")); + + Set<String> columnNames = (Set<String>) out.getOut().getHeader(JdbcConstants.JDBC_COLUMN_NAMES); + assertNotNull(columnNames); + assertEquals(2, columnNames.size()); + assertTrue(columnNames.contains("ID")); + assertTrue(columnNames.contains("PICTURE")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:hello").to("jdbc:testdb?readSize=100"); + } + }; + } +} diff --git a/components/camel-jdbc/src/test/resources/sql/init.sql b/components/camel-jdbc/src/test/resources/sql/init.sql index 87d5467..6d0eb2b 100644 --- a/components/camel-jdbc/src/test/resources/sql/init.sql +++ b/components/camel-jdbc/src/test/resources/sql/init.sql @@ -21,4 +21,7 @@ insert into customer values('cust2','nsandhu'); insert into customer values('cust3','willem'); create table tableWithAutoIncr (id int not null GENERATED ALWAYS AS IDENTITY, content varchar(10)); -insert into tableWithAutoIncr (content) values ('value1'); \ No newline at end of file +insert into tableWithAutoIncr (content) values ('value1'); + +create table tableWithClob (id varchar(15), picture clob(10M)); +insert into tableWithClob values ('id1', cast('\x0123456789ABCDEF' as clob)); \ No newline at end of file