BATCH-1309: Added a 'strict' property to ExecutionContextPromotionListener to ensure the key is present

This commit is contained in:
dhgarrette
2009-06-26 12:45:47 +00:00
parent 2ce3c65c91
commit fe26ccb08a
2 changed files with 46 additions and 0 deletions

View File

@@ -174,6 +174,35 @@ public class ExecutionContextPromotionListenerTests {
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
/**
* CONDITION: strict = true. keys = {key, key2}. Only {key} exists in the
* ExecutionContext.
*
* EXPECTED: IllegalArgumentException
*/
@Test(expected = IllegalArgumentException.class)
public void promoteEntries_keyNotFound_strict() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
listener.setStrict(true);
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(ExitStatus.COMPLETED);
Assert.state(jobExecution.getExecutionContext().isEmpty());
Assert.state(stepExecution.getExecutionContext().isEmpty());
stepExecution.getExecutionContext().putString(key, value);
listener.setKeys(new String[] { key, key2 });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
/**
* CONDITION: keys = NULL
*