RESOLVED - BATCH-629: CommandLineJobRunner should allow injection of JobParametersConverter
This commit is contained in:
@@ -157,6 +157,15 @@ public class CommandLineJobRunner {
|
||||
public void setSystemExiter(SystemExiter systemExitor) {
|
||||
this.systemExiter = systemExitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection setter for {@link JobParametersConverter}.
|
||||
*
|
||||
* @param jobParametersConverter
|
||||
*/
|
||||
public void setJobParametersConverter(JobParametersConverter jobParametersConverter) {
|
||||
this.jobParametersConverter = jobParametersConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate to the exiter to (possibly) exit the VM gracefully.
|
||||
@@ -170,6 +179,7 @@ public class CommandLineJobRunner {
|
||||
public void setJobLocator(JobLocator jobLocator) {
|
||||
this.jobLocator = jobLocator;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Start a job by obtaining a combined classpath using the job launcher and
|
||||
|
||||
@@ -15,11 +15,15 @@
|
||||
*/
|
||||
package org.springframework.batch.core.launch.support;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
@@ -62,6 +66,7 @@ public class CommandLineJobRunnerTests extends TestCase {
|
||||
|
||||
public void testMain() {
|
||||
CommandLineJobRunner.main(args);
|
||||
assertTrue("injected JobParametersConverter used instead of default", StubJobParametersConverter.called);
|
||||
assertEquals(0, StubSystemExiter.getStatus());
|
||||
}
|
||||
|
||||
@@ -130,9 +135,9 @@ public class CommandLineJobRunnerTests extends TestCase {
|
||||
|
||||
return jobExecution;
|
||||
}
|
||||
|
||||
|
||||
public void destroy() {
|
||||
destroyed = true;
|
||||
destroyed = true;
|
||||
}
|
||||
|
||||
public static void tearDown() {
|
||||
@@ -143,4 +148,21 @@ public class CommandLineJobRunnerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class StubJobParametersConverter implements JobParametersConverter {
|
||||
|
||||
JobParametersConverter delegate = new DefaultJobParametersConverter();
|
||||
|
||||
static boolean called = false;
|
||||
|
||||
public JobParameters getJobParameters(Properties properties) {
|
||||
called = true;
|
||||
return delegate.getJobParameters(properties);
|
||||
}
|
||||
|
||||
public Properties getProperties(JobParameters params) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
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.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<bean id="simpleContainerLauncher"
|
||||
class="org.springframework.batch.core.launch.support.CommandLineJobRunnerTests$StubJobLauncher"
|
||||
destroy-method="destroy" />
|
||||
|
||||
<bean class="org.springframework.batch.core.launch.support.SimpleJvmExitCodeMapper" />
|
||||
|
||||
<bean id="simpleContainerLauncher"
|
||||
class="org.springframework.batch.core.launch.support.CommandLineJobRunnerTests$StubJobLauncher"
|
||||
destroy-method="destroy" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.batch.core.launch.support.SimpleJvmExitCodeMapper" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.batch.core.launch.support.CommandLineJobRunnerTests$StubSystemExiter" />
|
||||
|
||||
</beans>
|
||||
<bean
|
||||
class="org.springframework.batch.core.launch.support.CommandLineJobRunnerTests$StubJobParametersConverter" />
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user