BATCH-2212: Updated CommandLineJobRunner to better communicate exceptions
This commit is contained in:
@@ -33,6 +33,8 @@ import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -118,7 +120,7 @@ public class CommandLineJobRunnerTests {
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(1, StubSystemExiter.status);
|
||||
String errorMessage = CommandLineJobRunner.getErrorMessage();
|
||||
assertTrue("Wrong error message: " + errorMessage, errorMessage.contains("Config locations must not be null"));
|
||||
assertTrue("Wrong error message: " + errorMessage, errorMessage.contains("At least 2 arguments are required: JobPath/JobClass and jobIdentifier."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -355,6 +357,19 @@ public class CommandLineJobRunnerTests {
|
||||
assertTrue(StubJobLauncher.destroyed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaConfig() throws Exception {
|
||||
String[] args =
|
||||
new String[] { "org.springframework.batch.core.launch.support.CommandLineJobRunnerTests$Configuration1",
|
||||
"invalidJobName"};
|
||||
CommandLineJobRunner.presetSystemExiter(new StubSystemExiter());
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(1, StubSystemExiter.status);
|
||||
String errorMessage = CommandLineJobRunner.getErrorMessage();
|
||||
assertTrue("Wrong error message: " + errorMessage,
|
||||
errorMessage.contains("A JobLauncher must be provided. Please add one to the configuration."));
|
||||
}
|
||||
|
||||
public static class StubSystemExiter implements SystemExiter {
|
||||
|
||||
private static int status;
|
||||
@@ -530,4 +545,12 @@ public class CommandLineJobRunnerTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class Configuration1 {
|
||||
@Bean
|
||||
public String bean1() {
|
||||
return "bean1";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user