[BATCH-383] Fixes to make Spring Batch 1.4 runtime compliant.

This commit is contained in:
nebhale
2008-03-11 13:49:17 +00:00
parent 32e25b081c
commit 9f7cc87c0d
40 changed files with 500 additions and 564 deletions

View File

@@ -40,11 +40,12 @@ public class ScheduledJobParametersFactory implements JobParametersConverter {
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.runtime.JobParametersFactory#getJobParameters(java.util.Properties)
*/
public JobParameters getJobParameters(Properties props) {
if(props == null || props.isEmpty()){
if (props == null || props.isEmpty()) {
return new JobParameters();
}
@@ -56,14 +57,11 @@ public class ScheduledJobParametersFactory implements JobParametersConverter {
Date scheduleDate;
try {
scheduleDate = dateFormat.parse(entry.getValue().toString());
}
catch (ParseException ex) {
throw new IllegalArgumentException("Date format is invalid: [" + entry.getValue() + "]",
ex);
} catch (ParseException ex) {
throw new IllegalArgumentException("Date format is invalid: [" + entry.getValue() + "]");
}
propertiesBuilder.addDate(entry.getKey().toString(), scheduleDate);
}
else {
} else {
propertiesBuilder.addString(entry.getKey().toString(), entry.getValue().toString());
}
}
@@ -72,17 +70,16 @@ public class ScheduledJobParametersFactory implements JobParametersConverter {
}
/**
* Convert schedule date to Date, and assume all other parameters can be
* represented by their default string value.
* Convert schedule date to Date, and assume all other parameters can be represented by their default string value.
*
* @see org.springframework.batch.core.support.JobParametersConverter#getProperties(org.springframework.batch.core.JobParameters)
*/
public Properties getProperties(JobParameters params) {
if(params == null || params.isEmpty()){
if (params == null || params.isEmpty()) {
return new Properties();
}
Map parameters = params.getParameters();
Properties result = new Properties();
for (Iterator iterator = parameters.keySet().iterator(); iterator.hasNext();) {
@@ -91,7 +88,7 @@ public class ScheduledJobParametersFactory implements JobParametersConverter {
if (key.equals(SCHEDULE_DATE_KEY)) {
result.setProperty(key, dateFormat.format(value));
} else {
result.setProperty(key,""+value);
result.setProperty(key, "" + value);
}
}
return result;
@@ -99,6 +96,7 @@ public class ScheduledJobParametersFactory implements JobParametersConverter {
/**
* Public setter for injecting a date format.
*
* @param dateFormat a {@link DateFormat}, defaults to "yyyy/MM/dd"
*/
public void setDateFormat(DateFormat dateFormat) {

View File

@@ -31,9 +31,8 @@ import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.util.StringUtils;
/**
* Converter for {@link JobParameters} instances using a simple naming convention
* for property keys. Key names ending with "(<type>)" where type is one
* of string, date, long are converted to the corresponding type. The default
* Converter for {@link JobParameters} instances using a simple naming convention for property keys. Key names ending
* with "(<type>)" where type is one of string, date, long are converted to the corresponding type. The default
* type is string. E.g.
*
* <pre>
@@ -41,8 +40,8 @@ import org.springframework.util.StringUtils;
* department.id(long)=2345
* </pre>
*
* The literal values are converted to the correct type using the default Spring
* strategies, augmented if necessary by the custom editors provided.
* The literal values are converted to the correct type using the default Spring strategies, augmented if necessary by
* the custom editors provided.
*
* @author Dave Syer
*
@@ -60,11 +59,10 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
private NumberFormat numberFormat = new DecimalFormat("#");
/**
* Check for suffix on keys and use those to decide how to convert the
* value.
* Check for suffix on keys and use those to decide how to convert the value.
*
* @throws IllegalArgumentException if a number or date is passed in that
* cannot be parsed, or cast to the correct type.
* @throws IllegalArgumentException if a number or date is passed in that cannot be parsed, or cast to the correct
* type.
*
* @see org.springframework.batch.core.support.JobParametersConverter#getJobParameters(java.util.Properties)
*/
@@ -84,35 +82,28 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
Date date;
try {
date = dateFormat.parse(value);
}
catch (ParseException ex) {
} catch (ParseException ex) {
String suffix = (dateFormat instanceof SimpleDateFormat) ? ", use "
+ ((SimpleDateFormat) dateFormat).toPattern() : "";
throw new IllegalArgumentException("Date format is invalid: [" + value + "]" + suffix, ex);
+ ((SimpleDateFormat) dateFormat).toPattern() : "";
throw new IllegalArgumentException("Date format is invalid: [" + value + "]" + suffix);
}
propertiesBuilder.addDate(StringUtils.replace(key, DATE_TYPE, ""), date);
}
else if (key.endsWith(LONG_TYPE)) {
} else if (key.endsWith(LONG_TYPE)) {
Long result;
try {
result = (Long) numberFormat.parse(value);
}
catch (ParseException ex) {
} catch (ParseException ex) {
String suffix = (numberFormat instanceof DecimalFormat) ? ", use "
+ ((DecimalFormat) numberFormat).toPattern() : "";
throw new IllegalArgumentException(
"Number format is invalid: [" + value + "], use " + suffix, ex);
}
catch (ClassCastException ex) {
+ ((DecimalFormat) numberFormat).toPattern() : "";
throw new IllegalArgumentException("Number format is invalid: [" + value + "], use " + suffix);
} catch (ClassCastException ex) {
throw new IllegalArgumentException("Number format is invalid: [" + value
+ "], use a format with no decimal places", ex);
+ "], use a format with no decimal places");
}
propertiesBuilder.addLong(StringUtils.replace(key, LONG_TYPE, ""), result);
}
else if (StringUtils.endsWithIgnoreCase(key, STRING_TYPE)) {
} else if (StringUtils.endsWithIgnoreCase(key, STRING_TYPE)) {
propertiesBuilder.addString(StringUtils.replace(key, STRING_TYPE, ""), value);
}
else {
} else {
propertiesBuilder.addString(key.toString(), value.toString());
}
}
@@ -121,8 +112,7 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
}
/**
* Use the same suffixes to create properties (omitting the string suffix
* because it is the default).
* Use the same suffixes to create properties (omitting the string suffix because it is the default).
*
* @see org.springframework.batch.core.support.JobParametersConverter#getProperties(org.springframework.batch.core.JobParameters)
*/
@@ -139,11 +129,9 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
Object value = parameters.get(key);
if (value instanceof Date) {
result.setProperty(key + DATE_TYPE, dateFormat.format(value));
}
else if (value instanceof Long) {
} else if (value instanceof Long) {
result.setProperty(key + LONG_TYPE, numberFormat.format(value));
}
else {
} else {
result.setProperty(key, "" + value);
}
}
@@ -152,6 +140,7 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
/**
* Public setter for injecting a date format.
*
* @param dateFormat a {@link DateFormat}, defaults to "yyyy/MM/dd"
*/
public void setDateFormat(DateFormat dateFormat) {
@@ -159,8 +148,8 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
}
/**
* Public setter for the {@link NumberFormat}. Used to parse longs, so must
* not contain decimal place (e.g. use "#" or "#,###").
* Public setter for the {@link NumberFormat}. Used to parse longs, so must not contain decimal place (e.g. use "#"
* or "#,###").
*
* @param numberFormat the {@link NumberFormat} to set
*/

View File

@@ -199,7 +199,7 @@ public class JobParametersTests extends TestCase {
public void testToStringOrder() {
Map props = parameters.getParameters();
StringBuilder stringBuilder = new StringBuilder();
StringBuffer stringBuilder = new StringBuffer();
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
Entry entry = (Entry) it.next();
stringBuilder.append(entry.toString() + ";");
@@ -226,7 +226,7 @@ public class JobParametersTests extends TestCase {
JobParameters testProps = new JobParameters(stringMap, longMap, doubleMap, dateMap);
props = testProps.getParameters();
stringBuilder = new StringBuilder();
stringBuilder = new StringBuffer();
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
Entry entry = (Entry) it.next();
stringBuilder.append(entry.toString() + ";");

View File

@@ -17,11 +17,10 @@ package org.springframework.batch.core.job;
import java.util.Collections;
import org.springframework.batch.core.step.StepSupport;
import junit.framework.TestCase;
import org.springframework.batch.core.step.StepSupport;
/**
* @author Dave Syer
*
@@ -31,8 +30,7 @@ public class AbstractJobTests extends TestCase {
JobSupport job = new JobSupport("job");
/**
* Test method for
* {@link org.springframework.batch.core.job.AbstractJob#JobConfiguration()}.
* Test method for {@link org.springframework.batch.core.job.AbstractJob#JobConfiguration()}.
*/
public void testJobConfiguration() {
job = new JobSupport();
@@ -40,8 +38,7 @@ public class AbstractJobTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.job.AbstractJob#setBeanName(java.lang.String)}.
* Test method for {@link org.springframework.batch.core.job.AbstractJob#setBeanName(java.lang.String)}.
*/
public void testSetBeanName() {
job.setBeanName("foo");
@@ -49,8 +46,7 @@ public class AbstractJobTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.job.AbstractJob#setBeanName(java.lang.String)}.
* Test method for {@link org.springframework.batch.core.job.AbstractJob#setBeanName(java.lang.String)}.
*/
public void testSetBeanNameWithNullName() {
job = new JobSupport(null);
@@ -60,8 +56,7 @@ public class AbstractJobTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.job.AbstractJob#setStepNames(java.util.List)}.
* Test method for {@link org.springframework.batch.core.job.AbstractJob#setStepNames(java.util.List)}.
*/
public void testSetSteps() {
job.setSteps(Collections.singletonList(new StepSupport("step")));
@@ -78,8 +73,7 @@ public class AbstractJobTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.job.AbstractJob#setStartLimit(int)}.
* Test method for {@link org.springframework.batch.core.job.AbstractJob#setStartLimit(int)}.
*/
public void testSetStartLimit() {
assertEquals(Integer.MAX_VALUE, job.getStartLimit());
@@ -88,28 +82,30 @@ public class AbstractJobTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.job.AbstractJob#setRestartable(boolean)}.
* Test method for {@link org.springframework.batch.core.job.AbstractJob#setRestartable(boolean)}.
*/
public void testSetRestartable() {
assertFalse(job.isRestartable());
job.setRestartable(true);
assertTrue(job.isRestartable());
}
public void testToString() throws Exception {
String value = job.toString();
assertTrue("Should contain name: "+value, value.indexOf("name=")>=0);
assertTrue("Should contain name: " + value, value.indexOf("name=") >= 0);
}
public void testRunNotSupported() throws Exception {
try {
job.execute(null);
} catch (UnsupportedOperationException e) {
// expected
String message = e.getMessage();
assertTrue("Message should contain JobSupport: "+message, message.contains("JobSupport"));
assertTrue("Message should contain JobSupport: " + message, contains(message, "JobSupport"));
}
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}

View File

@@ -98,8 +98,7 @@ public class SimpleJobLauncherTests extends TestCase {
try {
testRun();
fail("Expected RuntimeException");
}
catch (RuntimeException e) {
} catch (RuntimeException e) {
assertEquals("foo", e.getMessage());
}
}
@@ -114,8 +113,7 @@ public class SimpleJobLauncherTests extends TestCase {
try {
testRun();
fail("Expected Error");
}
catch (RuntimeException e) {
} catch (RuntimeException e) {
assertEquals("foo", e.getCause().getMessage());
}
}
@@ -124,11 +122,10 @@ public class SimpleJobLauncherTests extends TestCase {
try {
new SimpleJobLauncher().afterPropertiesSet();
fail("Expected IllegalArgumentException");
}
catch (IllegalStateException e) {
} catch (IllegalStateException e) {
// expected
assertTrue("Message did not contain repository: " + e.getMessage(), e.getMessage().toLowerCase().contains(
"repository"));
assertTrue("Message did not contain repository: " + e.getMessage(), contains(e.getMessage().toLowerCase(),
"repository"));
}
}
@@ -137,4 +134,8 @@ public class SimpleJobLauncherTests extends TestCase {
jobLauncher.setJobRepository(jobRepository);
jobLauncher.afterPropertiesSet(); // no error
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}

View File

@@ -62,7 +62,7 @@ public class ScheduledJobParametersFactoryTests extends TestCase {
public void testGetProperties() throws Exception {
JobParameters parameters = new JobParametersBuilder().addDate("schedule.date", dateFormat.parse("01/23/2008"))
.addString("job.key", "myKey").addString("vendor.id", "33243243").toJobParameters();
.addString("job.key", "myKey").addString("vendor.id", "33243243").toJobParameters();
Properties props = factory.getProperties(parameters);
assertNotNull(props);
@@ -76,12 +76,12 @@ public class ScheduledJobParametersFactoryTests extends TestCase {
JobParameters props = factory.getJobParameters(new Properties());
assertTrue(props.getParameters().isEmpty());
}
public void testNullArgs(){
public void testNullArgs() {
assertEquals(new JobParameters(), factory.getJobParameters(null));
assertEquals(new Properties(), factory.getProperties(null));
}
public void testGetParametersWithDateFormat() throws Exception {
String[] args = new String[] { "schedule.date=2008/23/01" };
@@ -101,8 +101,11 @@ public class ScheduledJobParametersFactoryTests extends TestCase {
factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message should contain wrong date: "+message, message.contains("20080123"));
assertTrue("Message should contain wrong date: " + message, contains(message, "20080123"));
}
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}

View File

@@ -46,7 +46,7 @@ public class SimpleExportedJobLauncherTests extends TestCase {
private SimpleExportedJobLauncher launcher = new SimpleExportedJobLauncher();
private MapJobRegistry jobLocator;
private List list = new ArrayList();
protected void setUp() throws Exception {
@@ -55,7 +55,8 @@ public class SimpleExportedJobLauncherTests extends TestCase {
public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException {
JobExecution result = new JobExecution(null);
StepExecution stepExecution = result.createStepExecution(new StepSupport("stepName"));
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter
.stringToProperties("foo=bar")));
list.add(jobParameters);
return result;
}
@@ -67,6 +68,7 @@ public class SimpleExportedJobLauncherTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#afterPropertiesSet()}.
*
* @throws Exception
*/
public void testAfterPropertiesSet() throws Exception {
@@ -74,16 +76,16 @@ public class SimpleExportedJobLauncherTests extends TestCase {
try {
launcher.afterPropertiesSet();
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message does not contain 'launcher': " + message, message.toLowerCase().contains("joblauncher"));
assertTrue("Message does not contain 'launcher': " + message, contains(message.toLowerCase(), "joblauncher"));
}
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#afterPropertiesSet()}.
*
* @throws Exception
*/
public void testAfterPropertiesSetWithLauncher() throws Exception {
@@ -96,16 +98,14 @@ public class SimpleExportedJobLauncherTests extends TestCase {
try {
launcher.afterPropertiesSet();
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message does not contain 'locator': " + message, message.toLowerCase().contains("joblocator"));
assertTrue("Message does not contain 'locator': " + message, contains(message.toLowerCase(), "joblocator"));
}
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#getStatistics()}.
* Test method for {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#getStatistics()}.
*/
public void testGetStatistics() {
Properties props = launcher.getStatistics();
@@ -114,8 +114,8 @@ public class SimpleExportedJobLauncherTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#getStatistics()}.
* Test method for {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#getStatistics()}.
*
* @throws Exception
*/
public void testGetStatisticsWithContent() throws Exception {
@@ -127,8 +127,8 @@ public class SimpleExportedJobLauncherTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#isRunning()}.
* Test method for {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#isRunning()}.
*
* @throws Exception
*/
public void testIsRunning() throws Exception {
@@ -138,8 +138,8 @@ public class SimpleExportedJobLauncherTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#isRunning()}.
* Test method for {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#isRunning()}.
*
* @throws Exception
*/
public void testAlreadyRunning() throws Exception {
@@ -150,7 +150,7 @@ public class SimpleExportedJobLauncherTests extends TestCase {
}
});
String value = launcher.run("foo");
assertTrue("Return value was not an exception: " + value, value.contains("JobExecutionAlreadyRunningException"));
assertTrue("Return value was not an exception: " + value, contains(value, "JobExecutionAlreadyRunningException"));
}
/**
@@ -159,25 +159,27 @@ public class SimpleExportedJobLauncherTests extends TestCase {
*/
public void testRunNonExistentJob() {
String value = launcher.run("foo");
assertTrue("Return value was not an exception: " + value, value.contains("NoSuchJobException"));
assertTrue("Return value was not an exception: " + value, contains(value, "NoSuchJobException"));
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#run(java.lang.String)}.
* @throws Exception
*
* @throws Exception
*/
public void testRunJobWithParameters() throws Exception {
jobLocator.register(new ReferenceJobFactory(new JobSupport("foo")));
String value = launcher.run("foo", "bar=spam,bucket=crap");
assertTrue(launcher.isRunning());
assertTrue("Return value was not a JobExecution: " + value, value.contains("JobExecution"));
assertTrue("Return value was not a JobExecution: " + value, contains(value, "JobExecution"));
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#run(java.lang.String)}.
* @throws Exception
*
* @throws Exception
*/
public void testRunJobWithParametersAndFactory() throws Exception {
jobLocator.register(new ReferenceJobFactory(new JobSupport("foo")));
@@ -185,6 +187,7 @@ public class SimpleExportedJobLauncherTests extends TestCase {
public JobParameters getJobParameters(Properties properties) {
return new JobParametersBuilder().addString("foo", "spam").toJobParameters();
}
public Properties getProperties(JobParameters params) {
return null;
}
@@ -195,9 +198,9 @@ public class SimpleExportedJobLauncherTests extends TestCase {
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#stop()}.
* @throws Exception
* Test method for {@link org.springframework.batch.core.launch.support.SimpleExportedJobLauncher#stop()}.
*
* @throws Exception
*/
public void testStop() throws Exception {
jobLocator.register(new ReferenceJobFactory(new JobSupport("foo")));
@@ -207,4 +210,7 @@ public class SimpleExportedJobLauncherTests extends TestCase {
assertFalse(launcher.isRunning());
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}

View File

@@ -503,8 +503,8 @@ public class ItemOrientedStepTests extends TestCase {
} catch (JobInterruptedException ex) {
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
String msg = stepExecution.getExitStatus().getExitDescription();
assertTrue("Message does not contain JobInterruptedException: " + msg, msg
.contains("JobInterruptedException"));
assertTrue("Message does not contain JobInterruptedException: " + msg, contains(msg,
"JobInterruptedException"));
}
}
@@ -562,7 +562,7 @@ public class ItemOrientedStepTests extends TestCase {
} catch (UnexpectedJobExecutionException ex) {
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
String msg = stepExecution.getExitStatus().getExitDescription();
assertTrue("Message does not contain ResetFailedException: " + msg, msg.contains("ResetFailedException"));
assertTrue("Message does not contain ResetFailedException: " + msg, contains(msg, "ResetFailedException"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
@@ -591,7 +591,7 @@ public class ItemOrientedStepTests extends TestCase {
String msg = stepExecution.getExitStatus().getExitDescription();
assertEquals("", msg);
msg = ex.getMessage();
assertTrue("Message does not contain 'saving': " + msg, msg.contains("saving"));
assertTrue("Message does not contain 'saving': " + msg, contains(msg, "saving"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
@@ -620,7 +620,7 @@ public class ItemOrientedStepTests extends TestCase {
String msg = stepExecution.getExitStatus().getExitDescription();
assertEquals("", msg);
msg = ex.getMessage();
assertTrue("Message does not contain 'final': " + msg, msg.contains("final"));
assertTrue("Message does not contain 'final': " + msg, contains(msg, "final"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
@@ -648,17 +648,21 @@ public class ItemOrientedStepTests extends TestCase {
itemOrientedStep.execute(stepExecution);
fail("Expected InfrastructureException");
} catch (UnexpectedJobExecutionException ex) {
// The job actually completeed, but the streams couldn't be closed.
// The job actually completed, but the streams couldn't be closed.
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
String msg = stepExecution.getExitStatus().getExitDescription();
assertEquals("", msg);
msg = ex.getMessage();
assertTrue("Message does not contain 'close': " + msg, msg.contains("close"));
assertTrue("Message does not contain 'close': " + msg, contains(msg, "close"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
private class MockRestartableItemReader extends ItemStreamSupport implements ItemReader, StepListener {
private boolean getExecutionAttributesCalled = false;

View File

@@ -27,7 +27,7 @@ public class TaskletStepTests extends TestCase {
protected void setUp() throws Exception {
stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(0L),
new JobParameters(), new JobSupport("testJob")), new Long(12)));
new JobParameters(), new JobSupport("testJob")), new Long(12)));
}
public void testTaskletMandatory() throws Exception {
@@ -35,10 +35,9 @@ public class TaskletStepTests extends TestCase {
step.setJobRepository(new JobRepositorySupport());
try {
step.afterPropertiesSet();
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message should contain 'tasklet': " + message, message.toLowerCase().contains("tasklet"));
assertTrue("Message should contain 'tasklet': " + message, contains(message.toLowerCase(), "tasklet"));
}
}
@@ -46,10 +45,9 @@ public class TaskletStepTests extends TestCase {
TaskletStep step = new TaskletStep();
try {
step.afterPropertiesSet();
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message should contain 'tasklet': " + message, message.toLowerCase().contains("tasklet"));
assertTrue("Message should contain 'tasklet': " + message, contains(message.toLowerCase(), "tasklet"));
}
}
@@ -90,8 +88,7 @@ public class TaskletStepTests extends TestCase {
try {
step.execute(stepExecution);
fail("Expected BatchCriticalException");
}
catch (UnexpectedJobExecutionException e) {
} catch (UnexpectedJobExecutionException e) {
assertEquals("foo", e.getCause().getMessage());
}
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
@@ -126,31 +123,27 @@ public class TaskletStepTests extends TestCase {
try {
step.execute(stepExecution);
fail();
}
catch (RuntimeException e) {
} catch (RuntimeException e) {
assertNotNull(stepExecution.getStartTime());
assertEquals(ExitStatus.FAILED, stepExecution.getExitStatus());
assertNotNull(stepExecution.getEndTime());
}
}
/**
* When job is interrupted the {@link JobInterruptedException} should be propagated up.
*/
public void testJobInterrupted() throws Exception {
TaskletStep step = new TaskletStep(
new Tasklet(){
public ExitStatus execute() throws Exception {
throw new JobInterruptedException("Interrupted while executing tasklet");
}
},
new JobRepositorySupport());
TaskletStep step = new TaskletStep(new Tasklet() {
public ExitStatus execute() throws Exception {
throw new JobInterruptedException("Interrupted while executing tasklet");
}
}, new JobRepositorySupport());
try {
step.execute(stepExecution);
fail();
}
catch (JobInterruptedException expected) {
} catch (JobInterruptedException expected) {
assertEquals("Interrupted while executing tasklet", expected.getMessage());
}
}
@@ -197,4 +190,7 @@ public class TaskletStepTests extends TestCase {
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}

View File

@@ -73,8 +73,8 @@ public class DefaultJobParametersConverterTests extends TestCase {
factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message should contain wrong date: "+message, message.contains("20080123"));
assertTrue("Message should contain format: "+message, message.contains("yyyy/MM/dd"));
assertTrue("Message should contain wrong date: " + message, contains(message, "20080123"));
assertTrue("Message should contain format: " + message, contains(message, "yyyy/MM/dd"));
}
}
@@ -96,8 +96,8 @@ public class DefaultJobParametersConverterTests extends TestCase {
factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message should contain wrong number: "+message, message.contains("foo"));
assertTrue("Message should contain format: "+message, message.contains("#"));
assertTrue("Message should contain wrong number: " + message, contains(message, "foo"));
assertTrue("Message should contain format: " + message, contains(message, "#"));
}
}
@@ -110,15 +110,15 @@ public class DefaultJobParametersConverterTests extends TestCase {
factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
} catch (IllegalArgumentException e) {
String message = e.getMessage();
assertTrue("Message should contain wrong number: "+message, message.contains("1.03"));
assertTrue("Message should contain 'decimal': "+message, message.contains("decimal"));
assertTrue("Message should contain wrong number: " + message, contains(message, "1.03"));
assertTrue("Message should contain 'decimal': " + message, contains(message, "decimal"));
}
}
public void testGetProperties() throws Exception {
JobParameters parameters = new JobParametersBuilder().addDate("schedule.date", dateFormat.parse("01/23/2008"))
.addString("job.key", "myKey").addLong("vendor.id", new Long(33243243)).toJobParameters();
.addString("job.key", "myKey").addLong("vendor.id", new Long(33243243)).toJobParameters();
Properties props = factory.getProperties(parameters);
assertNotNull(props);
@@ -132,9 +132,13 @@ public class DefaultJobParametersConverterTests extends TestCase {
JobParameters props = factory.getJobParameters(new Properties());
assertTrue(props.getParameters().isEmpty());
}
public void testNullArgs(){
public void testNullArgs() {
assertEquals(new JobParameters(), factory.getJobParameters(null));
assertEquals(new Properties(), factory.getProperties(null));
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}