OPEN - issue BATCH-811: StepExecutionResourceProxy should throw an exception if a job paramter key in the path isn't found
http://jira.springframework.org/browse/BATCH-811 StepExecutionResourceProxy will now throw an Exception if any "%" signs are left after pattern matching.
This commit is contained in:
@@ -284,7 +284,14 @@ public class StepExecutionResourceProxy extends StepExecutionListenerSupport imp
|
||||
String jobName = execution.getJobExecution().getJobInstance().getJobName();
|
||||
Properties properties = jobParametersConverter.getProperties(execution.getJobExecution().getJobInstance()
|
||||
.getJobParameters());
|
||||
delegate = resourceLoader.getResource(createFileName(jobName, stepName, properties));
|
||||
String fileName = createFileName(jobName, stepName, properties);
|
||||
if(fileName.indexOf("%") > -1){
|
||||
//if a % is still left in the fileName after matching, we have to assume that either no job parameter was found,
|
||||
//or an invalid path was used.
|
||||
throw new IllegalStateException("Invalid file pattern provided: [" + this.filePattern + "], tokens still remain after parameter matching: [" +
|
||||
fileName + "]");
|
||||
}
|
||||
delegate = resourceLoader.getResource(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,6 +141,22 @@ public class StepExecutionResourceProxyTests extends TestCase {
|
||||
resource.setFilePattern("arbitrary pattern");
|
||||
assertEquals(filePattern, resource.toString());
|
||||
}
|
||||
|
||||
public void testNonExistentJobParameter() throws Exception{
|
||||
|
||||
resource.setFilePattern("foo/data/%JOB_NAME%/%non.key%-foo");
|
||||
jobInstance = new JobInstance(new Long(0), new JobParametersBuilder().addString("job.key", "spam")
|
||||
.toJobParameters(), "testJob");
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
Step step = new StepSupport("bar");
|
||||
try{
|
||||
resource.beforeStep(jobExecution.createStepExecution(step));
|
||||
fail();
|
||||
}
|
||||
catch(Exception ex){
|
||||
//expected, if there isn't a JobParameter for that key, it should throw an exception
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestPathName(String filename, String path) throws Exception, IOException {
|
||||
String returnedPath = resource.getFile().getAbsolutePath();
|
||||
|
||||
Reference in New Issue
Block a user