RESOLVED - BATCH-1016: Create listener to promote items from Step ExecutionContext to Job ExecutionContext

applied patch and added unit test in core
This commit is contained in:
robokaso
2009-01-26 11:11:59 +00:00
parent e53dcab046
commit d09691aad2
4 changed files with 123 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
package org.springframework.batch.core.listener;
import static org.junit.Assert.*;
import java.util.Collections;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.util.Assert;
/**
* Tests for {@link ExecutionContextPromotionListener}.
*/
public class ExecutionContextPromotionListenerTests {
private ExecutionContextPromotionListener tested = new ExecutionContextPromotionListener();
private static final String key = "testKey";
private static final String value = "testValue";
@Test
public void promoteEntryFromStepToJobExectutionContext() throws Exception {
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
Assert.state(jobExecution.getExecutionContext().isEmpty());
Assert.state(stepExecution.getExecutionContext().isEmpty());
stepExecution.getExecutionContext().putString(key, value);
tested.setKeys(Collections.singletonList(key));
tested.afterPropertiesSet();
tested.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
}
@Test(expected = IllegalArgumentException.class)
public void keysMustBeSet() throws Exception {
// didn't set the keys, same as tested.setKeys(null);
tested.afterPropertiesSet();
}
}