CAMEL-6076: deprecate the xxxRef options and provide the xxx option if it not 
exists yet - work in progress


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/adf8c439
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/adf8c439
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/adf8c439

Branch: refs/heads/master
Commit: adf8c4395376d770e6eb19cb536a020edbc3d561
Parents: 50d661f
Author: cmueller <cmuel...@apache.org>
Authored: Thu May 23 23:47:09 2013 +0200
Committer: cmueller <cmuel...@apache.org>
Committed: Thu May 23 23:47:09 2013 +0200

----------------------------------------------------------------------
 components/camel-spring-batch/pom.xml              |    5 +
 .../spring/batch/SpringBatchComponent.java         |    4 +-
 .../spring/batch/SpringBatchEndpoint.java          |    7 +
 .../spring/batch/SpringBatchJobLauncherTest.java   |   68 ++++++++++
 .../batch/springBatchtestJobLauncherContext.xml    |   98 +++++++++++++++
 5 files changed, 181 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/adf8c439/components/camel-spring-batch/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-batch/pom.xml 
b/components/camel-spring-batch/pom.xml
index 4179850..7bf80e7 100644
--- a/components/camel-spring-batch/pom.xml
+++ b/components/camel-spring-batch/pom.xml
@@ -70,6 +70,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-spring</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
             <artifactId>camel-spring</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/adf8c439/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchComponent.java
 
b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchComponent.java
index bf3bcd0..bac2fb9 100644
--- 
a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchComponent.java
+++ 
b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchComponent.java
@@ -37,7 +37,9 @@ public class SpringBatchComponent extends DefaultComponent {
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
         Job resolvedJob = 
CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Job.class);
-        return new SpringBatchEndpoint(uri, this, jobLauncher, 
defaultResolvedJobLauncher, allResolvedJobLaunchers, resolvedJob);
+        SpringBatchEndpoint endpoint = new SpringBatchEndpoint(uri, this, 
jobLauncher, defaultResolvedJobLauncher, allResolvedJobLaunchers, resolvedJob);
+        setProperties(endpoint, parameters);
+        return endpoint;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/adf8c439/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchEndpoint.java
 
b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchEndpoint.java
index 7d9fa0a..dfe525f 100644
--- 
a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchEndpoint.java
+++ 
b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchEndpoint.java
@@ -28,6 +28,10 @@ import org.springframework.batch.core.launch.JobLauncher;
 
 public class SpringBatchEndpoint extends DefaultEndpoint {
 
+    /**
+     * @deprecated will be removed in Camel 3.0
+     * use jobLauncher instead
+     */
     private String jobLauncherRef;
 
     private JobLauncher jobLauncher;
@@ -97,4 +101,7 @@ public class SpringBatchEndpoint extends DefaultEndpoint {
         this.jobLauncherRef = jobLauncherRef;
     }
 
+    public void setJobLauncher(JobLauncher jobLauncher) {
+        this.jobLauncher = jobLauncher;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/adf8c439/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobLauncherTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobLauncherTest.java
 
b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobLauncherTest.java
new file mode 100644
index 0000000..6057589
--- /dev/null
+++ 
b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobLauncherTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.spring.batch;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringBatchJobLauncherTest extends CamelSpringTestSupport {
+
+    @EndpointInject(uri = "mock:output")
+    MockEndpoint outputEndpoint;
+
+    @EndpointInject(uri = "mock:jobExecutionEventsQueue")
+    MockEndpoint jobExecutionEventsQueueEndpoint;
+
+    String[] inputMessages = new String[]{"foo", "bar", "baz", null};
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+
+        for (String message : inputMessages) {
+            template.sendBody("seda:inputQueue", message);
+        }
+    }
+
+    @Test
+    public void testJobLauncher() throws InterruptedException {
+        outputEndpoint.expectedBodiesReceived("Echo foo", "Echo bar", "Echo 
baz");
+
+        template.sendBody("direct:start-jobLauncher", "Start batch!");
+
+        outputEndpoint.assertIsSatisfied();
+    }
+
+    @Test
+    public void testJobLauncherRef() throws InterruptedException {
+        outputEndpoint.expectedBodiesReceived("Echo foo", "Echo bar", "Echo 
baz");
+
+        template.sendBody("direct:start-jobLauncherRef", "Start batch!");
+
+        outputEndpoint.assertIsSatisfied();
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/component/spring/batch/springBatchtestJobLauncherContext.xml");
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/adf8c439/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestJobLauncherContext.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestJobLauncherContext.xml
 
b/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestJobLauncherContext.xml
new file mode 100644
index 0000000..bebd40d
--- /dev/null
+++ 
b/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestJobLauncherContext.xml
@@ -0,0 +1,98 @@
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:camel="http://camel.apache.org/schema/spring";
+       xmlns:batch="http://www.springframework.org/schema/batch";
+       xsi:schemaLocation="
+          http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+          http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+          http://www.springframework.org/schema/batch 
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd";>
+
+    <!-- Spring Batch task -->
+
+    <batch:job id="echoJob">
+        <batch:step id="echoStep">
+            <batch:tasklet>
+                <batch:chunk reader="camelReader" writer="camelWriter" 
processor="camelProcessor" commit-interval="3"/>
+            </batch:tasklet>
+        </batch:step>
+        <batch:listeners>
+            <batch:listener ref="camelJobExecutionListener"/>
+        </batch:listeners>
+    </batch:job>
+
+    <!-- Camel infrastructure -->
+
+    <camel:camelContext id="camel">
+        <camel:route>
+            <camel:from uri="direct:start-jobLauncherRef"/>
+            <camel:to uri="spring-batch:echoJob?jobLauncherRef=jobLauncher"/>
+        </camel:route>
+        <camel:route>
+            <camel:from uri="direct:start-jobLauncher"/>
+            <camel:to uri="spring-batch:echoJob?jobLauncher=#jobLauncher"/>
+        </camel:route>
+        <camel:route>
+            <camel:from uri="direct:processor"/>
+            <camel:setExchangePattern pattern="InOut"/>
+            <camel:setBody>
+                <camel:simple>Echo ${body}</camel:simple>
+            </camel:setBody>
+        </camel:route>
+    </camel:camelContext>
+
+    <camel:consumerTemplate id="consumerTemplate" camelContextId="camel"/>
+
+    <camel:template id="template" camelContextId="camel"/>
+
+    <!-- Spring Batch infrastructure -->
+
+    <bean id="jobRepository"
+          
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
+        <property name="transactionManager" ref="transactionManager"/>
+    </bean>
+
+    <bean id="transactionManager" 
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
+
+    <bean id="jobLauncher"
+          
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
+        <property name="jobRepository" ref="jobRepository"/>
+    </bean>
+
+    <bean id="camelReader" 
class="org.apache.camel.component.spring.batch.support.CamelItemReader">
+        <constructor-arg ref="consumerTemplate"/>
+        <constructor-arg value="seda:inputQueue"/>
+    </bean>
+
+    <bean id="camelWriter" 
class="org.apache.camel.component.spring.batch.support.CamelItemWriter">
+        <constructor-arg ref="template"/>
+        <constructor-arg value="mock:output"/>
+    </bean>
+
+    <bean id="camelProcessor" 
class="org.apache.camel.component.spring.batch.support.CamelItemProcessor">
+        <constructor-arg ref="template"/>
+        <constructor-arg value="direct:processor"/>
+    </bean>
+
+    <bean id="camelJobExecutionListener"
+          
class="org.apache.camel.component.spring.batch.support.CamelJobExecutionListener">
+        <constructor-arg ref="template"/>
+        <constructor-arg value="mock:jobExecutionEventsQueue"/>
+    </bean>
+
+</beans>
\ No newline at end of file

Reply via email to