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 2020/10/12 11:24:49 UTC

[camel] 01/03: CAMEL-15622: Added unit test for the reported problem.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 074b1be04ea49d5e7a8b11f3eafdf50ca21efd5f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Oct 12 10:38:27 2020 +0200

    CAMEL-15622: Added unit test for the reported problem.
---
 .../org/apache/camel/builder/endpoint/SqlTest.java | 84 ++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/SqlTest.java b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/SqlTest.java
new file mode 100644
index 0000000..ee6a20d
--- /dev/null
+++ b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/SqlTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.builder.endpoint;
+
+import javax.sql.DataSource;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.builder.endpoint.dsl.SqlEndpointBuilderFactory;
+import org.apache.camel.component.sql.SqlEndpoint;
+import org.junit.jupiter.api.Test;
+import org.springframework.jdbc.datasource.SimpleDriverDataSource;
+
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class SqlTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testSqlDataSourceInstance() throws Exception {
+        context.start();
+
+        final DataSource ds = new SimpleDriverDataSource();
+        context.getRegistry().bind("myDS", ds);
+
+        context.addRoutes(new EndpointRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                SqlEndpointBuilderFactory.SqlEndpointBuilder builder
+                        = sql("SELECT * FROM FOO").dataSource(ds);
+                Endpoint endpoint = builder.resolve(context);
+                assertNotNull(endpoint);
+                SqlEndpoint se = assertIsInstanceOf(SqlEndpoint.class, endpoint);
+                assertEquals("SELECT * FROM FOO", se.getQuery());
+                assertSame(ds, se.getDataSource());
+            }
+        });
+
+        context.stop();
+    }
+
+    @Test
+    public void testSqlDataSourceRefSyntax() throws Exception {
+        context.start();
+
+        final DataSource ds = new SimpleDriverDataSource();
+        context.getRegistry().bind("myDS", ds);
+
+        context.addRoutes(new EndpointRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                SqlEndpointBuilderFactory.SqlEndpointBuilder builder
+                        = sql("SELECT * FROM FOO").dataSource("#myDS");
+                Endpoint endpoint = builder.resolve(context);
+                assertNotNull(endpoint);
+                SqlEndpoint se = assertIsInstanceOf(SqlEndpoint.class, endpoint);
+                assertEquals("SELECT * FROM FOO", se.getQuery());
+                assertSame(ds, se.getDataSource());
+            }
+        });
+
+        context.stop();
+    }
+
+}