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 2009/06/05 12:17:52 UTC
svn commit: r781974 - in /camel/trunk/components/camel-spring/src/test:
java/org/apache/camel/spring/interceptor/
resources/org/apache/camel/spring/interceptor/
Author: davsclaus
Date: Fri Jun 5 10:17:52 2009
New Revision: 781974
URL: http://svn.apache.org/viewvc?rev=781974&view=rev
Log:
CAMEL-1663: Added unit test with a POJO using mixed annotations from Spring and Camel. And based on idea from CAMEL-1601.
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookServiceImpl.java
- copied, changed from r781916, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/BookService.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookStore.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedRoute.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionClientWithAnnotatedBeanTest.java (with props)
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionClientWithAnnotatedBeanTest.xml
- copied, changed from r781916, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml
Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookServiceImpl.java (from r781916, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/BookService.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookServiceImpl.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookServiceImpl.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/BookService.java&r1=781916&r2=781974&rev=781974&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/BookService.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookServiceImpl.java Fri Jun 5 10:17:52 2009
@@ -18,30 +18,42 @@
import javax.sql.DataSource;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
/**
- * Used for unit testing
+ * Used for unit testing that we can use spring and camel annotations mixed together
*/
-// START SNIPPET: e1
-public class BookService {
+@Transactional
+@Service
+public class AnnotatedBookServiceImpl implements AnnotatedBookStore {
- private SimpleJdbcTemplate jdbc;
+ @Autowired
+ private DataSource dataSource;
- public BookService() {
- }
-
- public void setDataSource(DataSource ds) {
- jdbc = new SimpleJdbcTemplate(ds);
- }
+ @EndpointInject(uri = "mock:book")
+ private ProducerTemplate template;
public void orderBook(String title) throws Exception {
+ Transactional tx = this.getClass().getAnnotation(Transactional.class);
+ if (tx == null) {
+ throw new IllegalArgumentException("Spring annotation-driven should have instrumented this class as @Transactional");
+ }
+ if (!"REQUIRED".equals(tx.propagation().name())) {
+ throw new IllegalArgumentException("Should be REQUIRED propagation");
+ }
+
if (title.startsWith("Donkey")) {
throw new IllegalArgumentException("We don't have Donkeys, only Camels");
}
// create new local datasource to store in DB
- jdbc.update("insert into books (title) values (?)", title);
+ new SimpleJdbcTemplate(dataSource).update("insert into books (title) values (?)", title);
+
+ template.sendBody(title);
}
-}
-// END SNIPPET: e1
+}
\ No newline at end of file
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookStore.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookStore.java?rev=781974&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookStore.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookStore.java Fri Jun 5 10:17:52 2009
@@ -0,0 +1,25 @@
+/**
+ * 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.spring.interceptor;
+
+/**
+ * @version $Revision$
+ */
+public interface AnnotatedBookStore {
+
+ void orderBook(String title) throws Exception;
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookStore.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedBookStore.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedRoute.java?rev=781974&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedRoute.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedRoute.java Fri Jun 5 10:17:52 2009
@@ -0,0 +1,38 @@
+/**
+ * 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.spring.interceptor;
+
+import org.apache.camel.spring.SpringRouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class AnnotatedRoute extends SpringRouteBuilder {
+
+ public void configure() throws Exception {
+ from("direct:okay").
+ transacted().
+ setBody(constant("Tiger in Action")).beanRef("bookService").
+ setBody(constant("Elephant in Action")).beanRef("bookService");
+
+ from("direct:fail").
+ transacted().
+ setBody(constant("Tiger in Action")).beanRef("bookService").
+ setBody(constant("Donkey in Action")).beanRef("bookService");
+ }
+
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedRoute.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/AnnotatedRoute.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionClientWithAnnotatedBeanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionClientWithAnnotatedBeanTest.java?rev=781974&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionClientWithAnnotatedBeanTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionClientWithAnnotatedBeanTest.java Fri Jun 5 10:17:52 2009
@@ -0,0 +1,43 @@
+/**
+ * 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.spring.interceptor;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class TransactionClientWithAnnotatedBeanTest extends TransactionalClientDataSourceTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ setUseRouteBuilder(false);
+ super.setUp();
+ }
+
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext(
+ "/org/apache/camel/spring/interceptor/transactionClientWithAnnotatedBeanTest.xml");
+ }
+
+ @Override
+ protected int getExpectedRouteCount() {
+ return 1;
+ }
+
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionClientWithAnnotatedBeanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionClientWithAnnotatedBeanTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionClientWithAnnotatedBeanTest.xml (from r781916, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionClientWithAnnotatedBeanTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionClientWithAnnotatedBeanTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml&r1=781916&r2=781974&rev=781974&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionClientWithAnnotatedBeanTest.xml Fri Jun 5 10:17:52 2009
@@ -16,12 +16,14 @@
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <context:component-scan base-package="org.apache.camel.spring.interceptor"/>
+ <tx:annotation-driven transaction-manager="txManager"/>
- <!-- START SNIPPET: e1 -->
<!-- datasource to the database -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
@@ -35,15 +37,13 @@
<property name="dataSource" ref="dataSource"/>
</bean>
- <!-- policy for required transaction used in our Camel routes -->
- <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
- <property name="transactionManager" ref="txManager"/>
- </bean>
-
<!-- bean for book business logic -->
- <bean id="bookService" class="org.apache.camel.spring.interceptor.BookService">
- <property name="dataSource" ref="dataSource"/>
- </bean>
- <!-- END SNIPPET: e1 -->
+ <bean id="bookService" class="org.apache.camel.spring.interceptor.AnnotatedBookServiceImpl"/>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <routeBuilder ref="annotatedRoute"/>
+ </camelContext>
+
+ <bean id="annotatedRoute" class="org.apache.camel.spring.interceptor.AnnotatedRoute"/>
</beans>