Fixed CS. This closes #1094. This closes #1088
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/560844c2 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/560844c2 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/560844c2 Branch: refs/heads/master Commit: 560844c2c5ac0f330838e4c5490d4c6139e20dc0 Parents: 8b796b5 Author: Claus Ibsen <davscl...@apache.org> Authored: Sat Jul 30 08:58:51 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat Jul 30 08:58:51 2016 +0200 ---------------------------------------------------------------------- .../src/main/docs/spring-batch.adoc | 10 ++- .../spring/batch/SpringBatchEndpoint.java | 4 +- .../spring/batch/SpringBatchProducer.java | 2 +- .../SpringBatchComponentAutoConfiguration.java | 70 ++++++++--------- .../SpringBatchComponentConfiguration.java | 65 +++++++++------- .../spring/batch/SpringBatchEndpointTest.java | 10 ++- .../batch/SpringBatchJobRegistryTest.java | 79 ++++++++++---------- 7 files changed, 127 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/560844c2/components/camel-spring-batch/src/main/docs/spring-batch.adoc ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/main/docs/spring-batch.adoc b/components/camel-spring-batch/src/main/docs/spring-batch.adoc index d970c0e..2064f4b 100644 --- a/components/camel-spring-batch/src/main/docs/spring-batch.adoc +++ b/components/camel-spring-batch/src/main/docs/spring-batch.adoc @@ -41,8 +41,9 @@ Options ^^^^^^^ + // component options: START -The Spring Batch component supports 1 options which are listed below. +The Spring Batch component supports 2 options which are listed below. @@ -60,8 +61,10 @@ The Spring Batch component supports 1 options which are listed below. + + // endpoint options: START -The Spring Batch component supports 5 endpoint options which are listed below: +The Spring Batch component supports 6 endpoint options which are listed below: {% raw %} [width="100%",cols="2s,1,1m,1m,5",options="header"] @@ -70,7 +73,7 @@ The Spring Batch component supports 5 endpoint options which are listed below: | jobName | producer | | String | *Required* The name of the Spring Batch job located in the registry. | jobFromHeader | producer | false | boolean | Explicitly defines if the jobName should be taken from the headers instead of the URI. | jobLauncher | producer | | JobLauncher | Explicitly specifies a JobLauncher to be used. -| jobRegistry | producer | | JobRegistry | Explicitly specifies a JobRegistry to be used. If set it it will be used to locate jobs. +| jobRegistry | producer | | JobRegistry | Explicitly specifies a JobRegistry to be used. | exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange | synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). |======================================================================= @@ -80,6 +83,7 @@ The Spring Batch component supports 5 endpoint options which are listed below: + [[SpringBatch-Usage]] Usage ^^^^^ http://git-wip-us.apache.org/repos/asf/camel/blob/560844c2/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 4f4fcd1..1d14d8f 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 @@ -23,7 +23,6 @@ import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.impl.DefaultEndpoint; - import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; @@ -73,7 +72,6 @@ public class SpringBatchEndpoint extends DefaultEndpoint { this.allResolvedJobLaunchers = allResolvedJobLaunchers; this.jobName = jobName; this.jobRegistry = jobRegistry; - } @Override @@ -97,7 +95,7 @@ public class SpringBatchEndpoint extends DefaultEndpoint { jobLauncher = resolveJobLauncher(); } if (job == null && jobName != null && !jobFromHeader) { - if(jobRegistry != null) { + if (jobRegistry != null) { job = jobRegistry.getJob(jobName); } else { job = CamelContextHelper.mandatoryLookup(getCamelContext(), jobName, Job.class); http://git-wip-us.apache.org/repos/asf/camel/blob/560844c2/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java index ddcb028..73a4b79 100644 --- a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java +++ b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java @@ -57,7 +57,7 @@ public class SpringBatchProducer extends DefaultProducer { Job job2run = this.job; if (messageJobName != null) { - if(jobRegistry != null) { + if (jobRegistry != null) { job2run = jobRegistry.getJob(messageJobName); } else { job2run = CamelContextHelper.mandatoryLookup(getEndpoint().getCamelContext(), messageJobName, Job.class); http://git-wip-us.apache.org/repos/asf/camel/blob/560844c2/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentAutoConfiguration.java b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentAutoConfiguration.java index bb184ca..3ffd8c6 100644 --- a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentAutoConfiguration.java +++ b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentAutoConfiguration.java @@ -14,39 +14,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.spring.batch.springboot; - -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.CamelContext; -import org.apache.camel.component.spring.batch.SpringBatchComponent; -import org.apache.camel.util.IntrospectionSupport; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Generated by camel-package-maven-plugin - do not edit this file! - */ -@Configuration -@EnableConfigurationProperties(SpringBatchComponentConfiguration.class) -public class SpringBatchComponentAutoConfiguration { - - @Bean - @ConditionalOnClass(CamelContext.class) - @ConditionalOnMissingBean(SpringBatchComponent.class) - public SpringBatchComponent configureSpringBatchComponent( - CamelContext camelContext, - SpringBatchComponentConfiguration configuration) throws Exception { - SpringBatchComponent component = new SpringBatchComponent(); - component.setCamelContext(camelContext); - Map<String, Object> parameters = new HashMap<>(); - IntrospectionSupport.getProperties(configuration, parameters, null, - false); - IntrospectionSupport.setProperties(camelContext, - camelContext.getTypeConverter(), component, parameters); - return component; - } +package org.apache.camel.component.spring.batch.springboot; + +import java.util.HashMap; +import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.component.spring.batch.SpringBatchComponent; +import org.apache.camel.util.IntrospectionSupport; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Configuration +@EnableConfigurationProperties(SpringBatchComponentConfiguration.class) +public class SpringBatchComponentAutoConfiguration { + + @Bean(name = "spring-batch-component") + @ConditionalOnClass(CamelContext.class) + @ConditionalOnMissingBean(SpringBatchComponent.class) + public SpringBatchComponent configureSpringBatchComponent( + CamelContext camelContext, + SpringBatchComponentConfiguration configuration) throws Exception { + SpringBatchComponent component = new SpringBatchComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + return component; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/560844c2/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentConfiguration.java b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentConfiguration.java index d00cd58..36914a5 100644 --- a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentConfiguration.java +++ b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/springboot/SpringBatchComponentConfiguration.java @@ -14,30 +14,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.spring.batch.springboot; - -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * The spring-batch component allows to send messages to Spring Batch for - * further processing. - * - * Generated by camel-package-maven-plugin - do not edit this file! - */ -@ConfigurationProperties(prefix = "camel.component.spring-batch") -public class SpringBatchComponentConfiguration { - - /** - * Explicitly specifies a JobLauncher to be used. - */ - private JobLauncher jobLauncher; - - public JobLauncher getJobLauncher() { - return jobLauncher; - } - - public void setJobLauncher(JobLauncher jobLauncher) { - this.jobLauncher = jobLauncher; - } +package org.apache.camel.component.spring.batch.springboot; + +import org.springframework.batch.core.configuration.JobRegistry; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The spring-batch component allows to send messages to Spring Batch for + * further processing. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@ConfigurationProperties(prefix = "camel.component.spring-batch") +public class SpringBatchComponentConfiguration { + + /** + * Explicitly specifies a JobLauncher to be used. + */ + private JobLauncher jobLauncher; + /** + * Explicitly specifies a JobRegistry to be used. + */ + private JobRegistry jobRegistry; + + public JobLauncher getJobLauncher() { + return jobLauncher; + } + + public void setJobLauncher(JobLauncher jobLauncher) { + this.jobLauncher = jobLauncher; + } + + public JobRegistry getJobRegistry() { + return jobRegistry; + } + + public void setJobRegistry(JobRegistry jobRegistry) { + this.jobRegistry = jobRegistry; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/560844c2/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java index 45d79c2..da09770 100644 --- a/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java +++ b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java @@ -31,7 +31,6 @@ import org.apache.camel.impl.JndiRegistry; import org.apache.camel.impl.SimpleRegistry; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.commons.lang.reflect.FieldUtils; -import static org.junit.Assert.assertSame; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -40,11 +39,14 @@ import org.mockito.runners.MockitoJUnitRunner; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.launch.JobLauncher; - -import static org.mockito.BDDMockito.*; -import org.springframework.batch.core.configuration.JobRegistry; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.eq; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.when; @RunWith(MockitoJUnitRunner.class) public class SpringBatchEndpointTest extends CamelTestSupport { http://git-wip-us.apache.org/repos/asf/camel/blob/560844c2/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobRegistryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobRegistryTest.java b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobRegistryTest.java index cd56e78..e28bdf7 100755 --- a/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobRegistryTest.java +++ b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchJobRegistryTest.java @@ -61,24 +61,23 @@ public class SpringBatchJobRegistryTest extends AbstractJUnit4SpringContextTests @EndpointInject(uri = "mock:jobExecutionEventsQueue") MockEndpoint jobExecutionEventsQueueEndpoint; - + @Autowired - protected ProducerTemplate template; - + ProducerTemplate template; + @Autowired - protected ConsumerTemplate consumer; + ConsumerTemplate consumer; String[] inputMessages = new String[]{"foo", "bar", "baz", null}; @Before public void setUp() throws Exception { - + for (String message : inputMessages) { template.sendBody("seda:inputQueue", message); } } - @DirtiesContext @Test public void testJobRegistry() throws InterruptedException { @@ -88,14 +87,12 @@ public class SpringBatchJobRegistryTest extends AbstractJUnit4SpringContextTests outputEndpoint.assertIsSatisfied(); } - @Configuration @Import(value = BatchConfig.class) public static class ContextConfig extends SingleRouteCamelConfiguration { @Override - public RouteBuilder route() - { + public RouteBuilder route() { return new RouteBuilder() { @Override public void configure() { @@ -103,68 +100,68 @@ public class SpringBatchJobRegistryTest extends AbstractJUnit4SpringContextTests from("direct:processor").setExchangePattern(ExchangePattern.InOut).setBody(simple("Echo ${body}")); } }; - } + } } - + @EnableAutoConfiguration @EnableBatchProcessing(modular = true) public static class BatchConfig { - + @Bean - public ApplicationContextFactory testJobs () { + public ApplicationContextFactory testJobs() { return new GenericApplicationContextFactory(ChildBatchConfig.class); } } - + @Configuration public static class ChildBatchConfig { - + @Autowired - private JobBuilderFactory jobs; + JobBuilderFactory jobs; + + @Autowired + StepBuilderFactory steps; - @Autowired - private StepBuilderFactory steps; - @Autowired ConsumerTemplate consumerTemplate; - + @Autowired ProducerTemplate producerTemplate; - + @Bean - protected ItemReader reader() throws Exception { + protected ItemReader reader() throws Exception { return new CamelItemReader(consumerTemplate, "seda:inputQueue"); - } + } - @Bean - protected ItemWriter writer() throws Exception { + @Bean + protected ItemWriter writer() throws Exception { return new CamelItemWriter(producerTemplate, "mock:output"); } - + @Bean protected ItemProcessor processor() throws Exception { return new CamelItemProcessor(producerTemplate, "direct:processor"); } - + @Bean protected JobExecutionListener jobExecutionListener() throws Exception { return new CamelJobExecutionListener(producerTemplate, "mock:jobExecutionEventsQueue"); } - + @Bean - public Job echoJob() throws Exception { + public Job echoJob() throws Exception { return this.jobs.get("echoJob").start(echoStep()).build(); - } - - @Bean - protected Step echoStep() throws Exception { - return this.steps.get("echoStep") - .chunk(3) - .reader(reader()) - .processor(processor()) - .writer(writer()) - .build(); - } - + } + + @Bean + protected Step echoStep() throws Exception { + return this.steps.get("echoStep") + .chunk(3) + .reader(reader()) + .processor(processor()) + .writer(writer()) + .build(); + } } + }