Author: davsclaus
Date: Tue Jun 12 09:28:40 2012
New Revision: 1349209
URL: http://svn.apache.org/viewvc?rev=1349209&view=rev
Log:
CAMEL-5355: Fixed sql endpoint to support % sign in uri.
Added:
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.java
(with props)
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointLikeTest.java
- copied, changed from r1348756,
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointTest.java
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/component/
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/component/sql/
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.xml
- copied, changed from r1348756,
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/processor/aggregate/jdbc/JdbcSpringDataSource.xml
Added:
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.java?rev=1349209&view=auto
==============================================================================
---
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.java
(added)
+++
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.java
Tue Jun 12 09:28:40 2012
@@ -0,0 +1,45 @@
+/**
+ * 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 org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version
+ */
+public class SpringSqlEndpointLikeTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/component/sql/SpringSqlEndpointLikeTest.xml");
+ }
+
+ @Test
+ public void testSQLEndpoint() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+
+ template.sendBody("direct:start", "");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
\ No newline at end of file
Propchange:
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.java
------------------------------------------------------------------------------
svn:executable = *
Copied:
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointLikeTest.java
(from r1348756,
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointLikeTest.java?p2=camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointLikeTest.java&p1=camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointTest.java&r1=1348756&r2=1349209&rev=1349209&view=diff
==============================================================================
---
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointTest.java
(original)
+++
camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlEndpointLikeTest.java
Tue Jun 12 09:28:40 2012
@@ -18,11 +18,10 @@ package org.apache.camel.component.sql;
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.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;
@@ -30,32 +29,33 @@ import org.springframework.jdbc.datasour
/**
* @version
*/
-public class SqlEndpointTest extends CamelTestSupport {
+public class SqlEndpointLikeTest extends CamelTestSupport {
private EmbeddedDatabase db;
@Test
public void testSQLEndpoint() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMessageCount(1);
+ mock.expectedMessageCount(2);
template.sendBody("direct:start", "");
assertMockEndpointsSatisfied();
}
- @Before
- public void setUp() throws Exception {
+ @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();
-
- super.setUp();
+
.setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase.sql").build();
+ jndi.bind("jdbc/myDataSource", db);
+ return jndi;
}
@After
public void tearDown() throws Exception {
super.tearDown();
-
db.shutdown();
}
@@ -63,15 +63,9 @@ public class SqlEndpointTest extends Cam
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- SqlEndpoint sql = new SqlEndpoint();
- sql.setCamelContext(context);
- sql.setJdbcTemplate(new JdbcTemplate(db));
- sql.setQuery("select * from projects");
-
- context.addEndpoint("mysql", sql);
-
from("direct:start")
- .to("mysql")
+ .to("sql:select * from projects where license like
'A%25'?dataSourceRef=jdbc/myDataSource")
+ .split(body())
.to("mock:result");
}
};
Copied:
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.xml
(from r1348756,
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/processor/aggregate/jdbc/JdbcSpringDataSource.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.xml?p2=camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.xml&p1=camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/processor/aggregate/jdbc/JdbcSpringDataSource.xml&r1=1348756&r2=1349209&rev=1349209&view=diff
==============================================================================
---
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/processor/aggregate/jdbc/JdbcSpringDataSource.xml
(original)
+++
camel/trunk/components/camel-sql/src/test/resources/org/apache/camel/component/sql/SpringSqlEndpointLikeTest.xml
Tue Jun 12 09:28:40 2012
@@ -17,51 +17,25 @@
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:ctx="http://www.springframework.org/schema/context"
- xmlns:util="http://www.springframework.org/schema/util"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
- http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
- http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
- http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
- <tx:annotation-driven transaction-manager="txManager"/>
-
- <!-- In Memory Database #1 -->
- <jdbc:embedded-database id="dataSource1" type="DERBY">
- <jdbc:script location="classpath:/sql/init.sql"/>
- </jdbc:embedded-database>
-
- <!-- In Memory Database #2 -->
- <jdbc:embedded-database id="dataSource2" type="DERBY">
- <jdbc:script location="classpath:/sql/init2.sql"/>
- </jdbc:embedded-database>
-
- <bean id="repo1"
class="org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository">
- <property name="repositoryName" value="aggregationRepo1" />
- <property name="transactionManager" ref="txManager1" />
- <property name="dataSource" ref="dataSource1" />
- </bean>
-
- <bean id="repo2"
class="org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository">
- <property name="repositoryName" value="aggregationRepo2" />
- <property name="transactionManager" ref="txManager2" />
- <property name="dataSource" ref="dataSource2" />
- </bean>
-
- <bean id="txManager1"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource1"/>
- </bean>
-
- <bean id="txManager2"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource2"/>
- </bean>
+ <!-- In Memory Database -->
+ <jdbc:embedded-database id="myDataSource" type="DERBY">
+ <jdbc:script location="classpath:/sql/createAndPopulateDatabase.sql"/>
+ </jdbc:embedded-database>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <to uri="sql:select * from projects where license like
'A%25'?dataSourceRef=myDataSource"/>
+ <split>
+ <simple>body</simple>
+ <to uri="mock:result"/>
+ </split>
+ </route>
+ </camelContext>
</beans>