camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/9] camel git commit: Saving work. Simple Producer.
Date Sat, 09 Jan 2016 10:44:45 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java
new file mode 100644
index 0000000..2182bd7
--- /dev/null
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java
@@ -0,0 +1,33 @@
+package org.apache.camel.component.sql.stored.template.ast;
+
+/**
+ * Created by snurmine on 12/20/15.
+ */
+public class OutParameter {
+
+
+    String name;
+
+    int sqlType;
+
+    String outHeader;
+
+
+    public OutParameter(String name, int sqlType, String outHeader) {
+        this.name = name;
+        this.sqlType = sqlType;
+        this.outHeader = outHeader;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getSqlType() {
+        return sqlType;
+    }
+
+    public String getOutHeader() {
+        return outHeader;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java
new file mode 100644
index 0000000..e84c7a9
--- /dev/null
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java
@@ -0,0 +1,58 @@
+package org.apache.camel.component.sql.stored.template.ast;
+
+import org.springframework.util.ReflectionUtils;
+
+import java.lang.reflect.Field;
+import java.math.BigInteger;
+import java.sql.Date;
+import java.sql.Types;
+
+
+public class ParseHelper {
+
+    public static int parseSqlType(String sqlType) {
+        Field field = ReflectionUtils.findField(Types.class, sqlType);
+        if (field == null) {
+            throw new ParseRuntimeException("Field " + sqlType + " not found from java.procedureName.Types");
+        }
+        try {
+            return field.getInt(Types.class);
+        } catch (IllegalAccessException e) {
+            throw new ParseRuntimeException(e);
+        }
+    }
+
+    public static Class sqlTypeToJavaType(int sqlType, String sqlTypeStr) {
+        //TODO: as rest of types.
+        //TODO: add test for each type.
+        Class ret = null;
+        switch (sqlType) {
+            case Types.INTEGER:
+                ret = Integer.class;
+                break;
+            case Types.VARCHAR:
+                ret = String.class;
+                break;
+            case Types.BIGINT:
+                ret = BigInteger.class;
+                break;
+            case Types.CHAR:
+                ret = String.class;
+                break;
+            case Types.BOOLEAN:
+                ret = Boolean.class;
+                break;
+            case Types.DATE:
+                ret = Date.class;
+                break;
+            case Types.TIMESTAMP:
+                ret = Date.class;
+                break;
+        }
+        if (ret == null) {
+            throw new ParseRuntimeException("Unable to map SQL type " + sqlTypeStr + " to
Java type");
+
+        }
+        return ret;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java
new file mode 100644
index 0000000..b3b8fc8
--- /dev/null
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java
@@ -0,0 +1,14 @@
+package org.apache.camel.component.sql.stored.template.ast;
+
+/**
+ * Created by snurmine on 1/3/16.
+ */
+public class ParseRuntimeException extends RuntimeException {
+    public ParseRuntimeException(String message) {
+        super(message);
+    }
+
+    public ParseRuntimeException(Throwable cause) {
+        super(cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java
new file mode 100644
index 0000000..b442fde
--- /dev/null
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java
@@ -0,0 +1,43 @@
+package org.apache.camel.component.sql.stored.template.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Root element of Simple Stored Procedure Template AST.
+ */
+public class Template {
+
+    String procedureName;
+
+    List<InputParameter> inputParameterList = new ArrayList<>();
+
+    List<OutParameter> outParameterList = new ArrayList<>();
+
+    public void addParameter(Object parameter) {
+
+        if (parameter instanceof OutParameter) {
+            outParameterList.add((OutParameter) parameter);
+        } else {
+            inputParameterList.add((InputParameter) parameter);
+
+        }
+    }
+
+    public String getProcedureName() {
+        return procedureName;
+    }
+
+    public void setProcedureName(String procedureName) {
+        this.procedureName = procedureName;
+    }
+
+    public List<InputParameter> getInputParameterList() {
+        return inputParameterList;
+    }
+
+    public List<OutParameter> getOutParameterList() {
+        return outParameterList;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
new file mode 100644
index 0000000..764764c
--- /dev/null
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
@@ -0,0 +1,136 @@
+//Using some token definions from: http://kiwwito.com/build-a-lexical-analyzer-with-javacc/
+
+options {
+    STATIC = false;
+}
+
+
+PARSER_BEGIN(SSPTParser)
+
+package org.apache.camel.component.sql.stored.template.generated;
+
+import org.apache.camel.component.sql.stored.template.ast.*;
+
+public class SSPTParser {
+   int paramaterNameCounter = 0;
+
+   String createNextParameterName() {
+      return "_"+(paramaterNameCounter++);
+   }
+}
+
+PARSER_END(SSPTParser)
+
+public Template parse() :
+{   Token procudureName;
+    Template template = new Template();
+    Object parameter = null;
+}
+{
+  (procudureName = <IDENTIFIER> "(" (parameter = Parameter() { template.addParameter(parameter);})
(","
+  parameter
+  = Parameter(){template.addParameter(parameter);})*  ")" <EOF>)
+  {
+   template.setProcedureName(procudureName.toString());
+   return template;
+  }
+}
+
+Object Parameter() :
+{
+    Object param;
+}
+{
+     (param = InputParameter() {return param;}) | (param = OutParameter(){return param;})
+}
+
+InputParameter InputParameter() :
+{
+     String sqlTypeAsStr;
+     String name;
+     String valueSrcAsStr;
+}
+{
+    (sqlTypeAsStr = ParameterSqlType() " " valueSrcAsStr =
+    InputParameterSrc())
+    {
+        int sqlType = ParseHelper.parseSqlType(sqlTypeAsStr);
+        return new InputParameter(createNextParameterName(),sqlType,valueSrcAsStr,ParseHelper.sqlTypeToJavaType(sqlType,sqlTypeAsStr));
+    }
+}
+
+OutParameter OutParameter() :
+{
+     String sqlType;
+     String name;
+     String outHeader;
+}
+{
+    ("OUT" " " sqlType = ParameterSqlType() " " outHeader =
+    OutHeader())
+    {
+        return new OutParameter(createNextParameterName(),ParseHelper.parseSqlType(sqlType),outHeader);
+    }
+}
+
+String ParameterSqlType():
+{
+    Token t;
+}
+{
+    (t = <IDENTIFIER>)
+    {
+        return t.toString();
+    }
+}
+
+String OutHeader():
+{
+ Token token;
+}
+{
+    (token = <IDENTIFIER>)
+    {
+        return token.toString();
+    }
+}
+
+String InputParameterSrc():
+{
+    String ret;
+}
+{
+    (ret = SimpleExpression())
+    {
+        return ret;
+    }
+}
+
+String SimpleExpression() :
+{
+ Token t = null;
+}
+{
+    (t = <SIMPLE_EXP_TOKEN>)
+    {
+    return t.toString();
+    }
+}
+
+TOKEN: {
+    <#DIGIT: (["0"-"9"])>
+}
+
+TOKEN: {
+    <#LETTER: (["a"-"z","A"-"Z"])>
+}
+
+TOKEN : {
+    <SIMPLE_EXP_TOKEN: "${"(<LETTER>|<DIGIT> | " " | "'" | "." )* "}">
+}
+
+
+TOKEN : {
+    <IDENTIFIER: <LETTER>( <LETTER> | <DIGIT> | ".") *>
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/main/resources/META-INF/services/org/apache/camel/component/sql-stored
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/resources/META-INF/services/org/apache/camel/component/sql-stored
b/components/camel-sql/src/main/resources/META-INF/services/org/apache/camel/component/sql-stored
new file mode 100644
index 0000000..74e07fd
--- /dev/null
+++ b/components/camel-sql/src/main/resources/META-INF/services/org/apache/camel/component/sql-stored
@@ -0,0 +1 @@
+class=org.apache.camel.component.sql.stored.SqlStoredComponent

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ParserTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ParserTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ParserTest.java
deleted file mode 100644
index ba36baf..0000000
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ParserTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.apache.camel.component.sql.sspt;
-
-
-import org.apache.camel.Exchange;
-import org.apache.camel.component.sql.sspt.ast.InputParameter;
-import org.apache.camel.component.sql.sspt.ast.OutParameter;
-import org.apache.camel.component.sql.sspt.ast.ParseException;
-import org.apache.camel.component.sql.sspt.ast.Template;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.math.BigInteger;
-import java.sql.Types;
-
-public class ParserTest extends CamelTestSupport {
-
-    SimpleStoredProcedureFactory parser = new SimpleStoredProcedureFactory();
-
-
-    @Test
-    public void shouldParseOk() {
-
-
-        Template template = parser.parseTemplate("addnumbers(INTEGER ${header.header1},"
+
-                "VARCHAR ${property.property1},BIGINT ${header.header2},OUT INTEGER header1)");
-
-        Assert.assertEquals("addnumbers", template.getProcedureName());
-        Assert.assertEquals(3, template.getInputParameterList().size());
-
-        Exchange exchange = createExchangeWithBody(null);
-        exchange.getIn().setHeader("header1", 1);
-        exchange.setProperty("property1", "constant string");
-        exchange.getIn().setHeader("header2", BigInteger.valueOf(2));
-
-        InputParameter param1 = template.getInputParameterList().get(0);
-        Assert.assertEquals("_0", param1.getName());
-        Assert.assertEquals(Types.INTEGER, param1.getSqlType());
-        Assert.assertEquals(Integer.valueOf(1), param1.getValueExpression().evaluate(exchange,
Integer.class));
-
-        InputParameter param2 = template.getInputParameterList().get(1);
-        Assert.assertEquals("_1", param2.getName());
-        Assert.assertEquals(Types.VARCHAR, param2.getSqlType());
-        Assert.assertEquals("constant string", param2.getValueExpression().evaluate(exchange,
String.class));
-
-        InputParameter param3 = template.getInputParameterList().get(2);
-        Assert.assertEquals("_2", param3.getName());
-        Assert.assertEquals(Types.BIGINT, param3.getSqlType());
-        Assert.assertEquals(BigInteger.valueOf(2), param3.getValueExpression().evaluate(exchange,
BigInteger.class));
-
-        OutParameter sptpOutputNode = template.getOutParameterList().get(0);
-        Assert.assertEquals("_3", sptpOutputNode.getName());
-        Assert.assertEquals(Types.INTEGER, sptpOutputNode.getSqlType());
-        Assert.assertEquals("header1", sptpOutputNode.getOutHeader());
-
-    }
-
-
-    @Test(expected = ParseException.class)
-    public void noOutputParameterShouldFail() {
-        parser.parseTemplate("ADDNUMBERS2" +
-                "(INTEGER VALUE1 ${header.v1},INTEGER VALUE2 ${header.v2})");
-
-    }
-
-    @Test(expected = ParseException.class)
-    public void unexistingTypeShouldFail() {
-        parser.parseTemplate("ADDNUMBERS2" +
-                "(XML VALUE1 ${header.v1},OUT INTEGER VALUE2 ${header.v2})");
-
-    }
-
-
-    @Test(expected = ParseException.class)
-    public void unmappedTypeShouldFaild() {
-        parser.parseTemplate("ADDNUMBERS2" +
-                "(OTHER VALUE1 ${header.v1},INTEGER VALUE2 ${header.v2})");
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ProducerTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ProducerTest.java
deleted file mode 100644
index d00108c..0000000
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/ProducerTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.apache.camel.component.sql.sspt;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.sql.SqlComponent;
-import org.apache.camel.test.junit4.CamelTestSupport;
-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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created by snurmine on 12/30/15.
- */
-public class ProducerTest extends CamelTestSupport {
-
-
-    private EmbeddedDatabase db;
-
-    @Before
-    public void setUp() throws Exception {
-        db = new EmbeddedDatabaseBuilder()
-                .setType(EmbeddedDatabaseType.DERBY).addScript("sql/storedProcedureTest.sql").build();
-
-        super.setUp();
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
-
-        db.shutdown();
-    }
-
-    @Test
-    public void shouldExecuteStoredProcedure() throws InterruptedException {
-        MockEndpoint mock = getMockEndpoint("mock:query");
-        mock.expectedMessageCount(1);
-
-
-        Map<String, Object> headers = new HashMap<>();
-        headers.put("num1", 1);
-        headers.put("num2", 2);
-        template.requestBodyAndHeaders("direct:query", null, headers);
-
-        assertMockEndpointsSatisfied();
-
-        Exchange exchange = mock.getExchanges().get(0);
-
-        assertEquals(Integer.valueOf(3), exchange.getIn().getHeader("resultofsum"));
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                // required for the sql component
-                getContext().getComponent("sql", SqlComponent.class).setDataSource(db);
-
-                from("direct:query").to("sql:sspt:ADDNUMBERS(INTEGER ${headers.num1},INTEGER
${headers"
-                        + ".num2},OUT INTEGER resultofsum)").to("mock:query");
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureTest.java
deleted file mode 100644
index 5fc4fef..0000000
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.apache.camel.component.sql.sspt;
-
-
-import org.apache.camel.Exchange;
-import org.apache.camel.component.sql.sspt.ast.ParseException;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
-import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
-import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
-
-public class SimpleStoredProcedureTest extends CamelTestSupport {
-
-    SimpleStoredProcedureFactory parser = new SimpleStoredProcedureFactory();
-
-    private EmbeddedDatabase db;
-    private JdbcTemplate jdbcTemplate;
-
-    @Before
-    public void setUp() throws Exception {
-        db = new EmbeddedDatabaseBuilder()
-                .setType(EmbeddedDatabaseType.DERBY).addScript("sql/storedProcedureTest.sql").build();
-
-        jdbcTemplate = new JdbcTemplate(db);
-
-        super.setUp();
-    }
-
-
-    @Test
-    public void shouldExecuteStoredProcedure() throws ParseException {
-        SimpleStoredProcedure sp = new SimpleStoredProcedure(db, parser.parseTemplate("ADDNUMBERS"
+
-                "(INTEGER ${header.v1},INTEGER ${header.v2},OUT INTEGER resultofsum)"));
-
-        Exchange exchange = createExchangeWithBody(null);
-        exchange.getIn().setHeader("v1", 1);
-        exchange.getIn().setHeader("v2", 2);
-
-
-        sp.execute(exchange);
-
-        Assert.assertEquals(Integer.valueOf(3), exchange.getOut().getHeader("resultofsum"));
-
-
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
-
-        db.shutdown();
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureUdf.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureUdf.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureUdf.java
deleted file mode 100644
index f88ebd4..0000000
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/sspt/SimpleStoredProcedureUdf.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.apache.camel.component.sql.sspt;
-
-/**
- * Created by snurmine on 12/20/15.
- */
-public class SimpleStoredProcedureUdf {
-
-    public static void addnumbers(int VALUE1, int VALUE2, int[] RESULT) {
-        System.out.println("calling addnumbers:" + VALUE1 + "," + VALUE2);
-
-        RESULT[0] = VALUE1 + VALUE2;
-
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java
new file mode 100644
index 0000000..81b6b5a
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java
@@ -0,0 +1,83 @@
+package org.apache.camel.component.sql.stored;
+
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.sql.stored.template.ast.InputParameter;
+import org.apache.camel.component.sql.stored.template.ast.OutParameter;
+import org.apache.camel.component.sql.stored.template.ast.ParseRuntimeException;
+import org.apache.camel.component.sql.stored.template.ast.Template;
+import org.apache.camel.component.sql.stored.template.TemplateStoredProcedureFactory;
+import org.apache.camel.component.sql.stored.template.generated.ParseException;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.math.BigInteger;
+import java.sql.Types;
+
+public class ParserTest extends CamelTestSupport {
+
+    TemplateStoredProcedureFactory parser = new TemplateStoredProcedureFactory();
+
+
+    @Test
+    public void shouldParseOk() {
+
+
+        Template template = parser.parseTemplate("addnumbers(INTEGER ${header.header1},"
+
+                "VARCHAR ${property.property1},BIGINT ${header.header2},OUT INTEGER header1)");
+
+        Assert.assertEquals("addnumbers", template.getProcedureName());
+        Assert.assertEquals(3, template.getInputParameterList().size());
+
+        Exchange exchange = createExchangeWithBody(null);
+        exchange.getIn().setHeader("header1", 1);
+        exchange.setProperty("property1", "constant string");
+        exchange.getIn().setHeader("header2", BigInteger.valueOf(2));
+
+        InputParameter param1 = template.getInputParameterList().get(0);
+        Assert.assertEquals("_0", param1.getName());
+        Assert.assertEquals(Types.INTEGER, param1.getSqlType());
+        Assert.assertEquals(Integer.valueOf(1), param1.getValueExpression().evaluate(exchange,
Integer.class));
+
+        InputParameter param2 = template.getInputParameterList().get(1);
+        Assert.assertEquals("_1", param2.getName());
+        Assert.assertEquals(Types.VARCHAR, param2.getSqlType());
+        Assert.assertEquals("constant string", param2.getValueExpression().evaluate(exchange,
String.class));
+
+        InputParameter param3 = template.getInputParameterList().get(2);
+        Assert.assertEquals("_2", param3.getName());
+        Assert.assertEquals(Types.BIGINT, param3.getSqlType());
+        Assert.assertEquals(BigInteger.valueOf(2), param3.getValueExpression().evaluate(exchange,
BigInteger.class));
+
+        OutParameter sptpOutputNode = template.getOutParameterList().get(0);
+        Assert.assertEquals("_3", sptpOutputNode.getName());
+        Assert.assertEquals(Types.INTEGER, sptpOutputNode.getSqlType());
+        Assert.assertEquals("header1", sptpOutputNode.getOutHeader());
+
+    }
+
+
+    @Test(expected = ParseRuntimeException.class)
+    public void noOutputParameterShouldFail() {
+        parser.parseTemplate("ADDNUMBERS2" +
+                "(INTEGER VALUE1 ${header.v1},INTEGER VALUE2 ${header.v2})");
+
+    }
+
+    @Test(expected = ParseRuntimeException.class)
+    public void unexistingTypeShouldFail() {
+        parser.parseTemplate("ADDNUMBERS2" +
+                "(XML VALUE1 ${header.v1},OUT INTEGER VALUE2 ${header.v2})");
+
+    }
+
+
+    @Test(expected = ParseRuntimeException.class)
+    public void unmappedTypeShouldFaild() {
+        parser.parseTemplate("ADDNUMBERS2" +
+                "(OTHER VALUE1 ${header.v1},INTEGER VALUE2 ${header.v2})");
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
new file mode 100644
index 0000000..969bca1
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
@@ -0,0 +1,72 @@
+package org.apache.camel.component.sql.stored;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.sql.SqlComponent;
+import org.apache.camel.test.junit4.CamelTestSupport;
+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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by snurmine on 12/30/15.
+ */
+public class ProducerTest extends CamelTestSupport {
+
+
+    private EmbeddedDatabase db;
+
+    @Before
+    public void setUp() throws Exception {
+        db = new EmbeddedDatabaseBuilder()
+                .setType(EmbeddedDatabaseType.DERBY).addScript("sql/storedProcedureTest.sql").build();
+
+        super.setUp();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        db.shutdown();
+    }
+
+    @Test
+    public void shouldExecuteStoredProcedure() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:query");
+        mock.expectedMessageCount(1);
+
+
+        Map<String, Object> headers = new HashMap<>();
+        headers.put("num1", 1);
+        headers.put("num2", 2);
+        template.requestBodyAndHeaders("direct:query", null, headers);
+
+        assertMockEndpointsSatisfied();
+
+        Exchange exchange = mock.getExchanges().get(0);
+
+        assertEquals(Integer.valueOf(3), exchange.getIn().getHeader("resultofsum"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // required for the sql component
+                getContext().getComponent("sql-stored", SqlStoredComponent.class).setDataSource(db);
+
+                from("direct:query").to("sql-stored:ADDNUMBERS(INTEGER ${headers.num1},INTEGER
${headers"
+                        + ".num2},OUT INTEGER resultofsum)").to("mock:query");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SimpleStoredProcedureUdf.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SimpleStoredProcedureUdf.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SimpleStoredProcedureUdf.java
new file mode 100644
index 0000000..2802b70
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SimpleStoredProcedureUdf.java
@@ -0,0 +1,15 @@
+package org.apache.camel.component.sql.stored;
+
+/**
+ * Created by snurmine on 12/20/15.
+ */
+public class SimpleStoredProcedureUdf {
+
+    public static void addnumbers(int VALUE1, int VALUE2, int[] RESULT) {
+        System.out.println("calling addnumbers:" + VALUE1 + "," + VALUE2);
+
+        RESULT[0] = VALUE1 + VALUE2;
+
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java
new file mode 100644
index 0000000..752dcaa
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java
@@ -0,0 +1,58 @@
+package org.apache.camel.component.sql.stored;
+
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.sql.stored.template.TemplateStoredProcedure;
+import org.apache.camel.component.sql.stored.template.TemplateStoredProcedureFactory;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
+
+public class TemplateStoredProcedureTest extends CamelTestSupport {
+
+    TemplateStoredProcedureFactory parser = new TemplateStoredProcedureFactory();
+
+    private EmbeddedDatabase db;
+    private JdbcTemplate jdbcTemplate;
+
+    @Before
+    public void setUp() throws Exception {
+        db = new EmbeddedDatabaseBuilder()
+                .setType(EmbeddedDatabaseType.DERBY).addScript("sql/storedProcedureTest.sql").build();
+
+        jdbcTemplate = new JdbcTemplate(db);
+
+        super.setUp();
+    }
+
+
+    @Test
+    public void shouldExecuteStoredProcedure()  {
+        TemplateStoredProcedure sp = new TemplateStoredProcedure(db, parser.parseTemplate("ADDNUMBERS"
+
+                "(INTEGER ${header.v1},INTEGER ${header.v2},OUT INTEGER resultofsum)"));
+
+        Exchange exchange = createExchangeWithBody(null);
+        exchange.getIn().setHeader("v1", 1);
+        exchange.getIn().setHeader("v2", 2);
+
+
+        sp.execute(exchange);
+
+        Assert.assertEquals(Integer.valueOf(3), exchange.getOut().getHeader("resultofsum"));
+
+
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        db.shutdown();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3ee2bb46/components/camel-sql/src/test/resources/sql/storedProcedureTest.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/storedProcedureTest.sql b/components/camel-sql/src/test/resources/sql/storedProcedureTest.sql
index edee883..3f6ed74 100644
--- a/components/camel-sql/src/test/resources/sql/storedProcedureTest.sql
+++ b/components/camel-sql/src/test/resources/sql/storedProcedureTest.sql
@@ -19,4 +19,4 @@ CREATE PROCEDURE ADDNUMBERS(VALUE1 INTEGER, VALUE2 INTEGER,OUT RESULT INTEGER)
  PARAMETER STYLE JAVA
  LANGUAGE JAVA
  EXTERNAL NAME
-'org.apache.camel.component.sql.sspt.SimpleStoredProcedureUdf.addnumbers';
\ No newline at end of file
+'org.apache.camel.component.sql.stored.SimpleStoredProcedureUdf.addnumbers';
\ No newline at end of file


Mime
View raw message