From 292177996a729bae21bd9edf0ac6b96097acfca2 Mon Sep 17 00:00:00 2001 From: dhgarrette Date: Wed, 11 Mar 2009 18:08:59 +0000 Subject: [PATCH] BATCH-1016: Added test case --- ...xecutionContextPromotionListenerTests.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java index f724b7427..2edf416ac 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java @@ -29,8 +29,8 @@ public class ExecutionContextPromotionListenerTests { private static final String statusWildcard = "COMPL*SKIPS"; /** - * CONDITION: keys = {key1, key2}. statuses is not set (defaults to - * {COMPLETED}). + * CONDITION: ExecutionContext contains {key, key2}. keys = {key}. statuses + * is not set (defaults to {COMPLETED}). * * EXPECTED: key is promoted. key2 is not. */ @@ -58,7 +58,8 @@ public class ExecutionContextPromotionListenerTests { } /** - * CONDITION: keys = {key1, key2}. statuses = {status}. ExitStatus = status + * CONDITION: ExecutionContext contains {key, key2}. keys = {key, key2}. + * statuses = {status}. ExitStatus = status * * EXPECTED: key is promoted. key2 is not. */ @@ -87,7 +88,8 @@ public class ExecutionContextPromotionListenerTests { } /** - * CONDITION: keys = {key1, key2}. statuses = {status}. ExitStatus = status2 + * CONDITION: ExecutionContext contains {key, key2}. keys = {key, key2}. + * statuses = {status}. ExitStatus = status2 * * EXPECTED: no promotions. */ @@ -116,7 +118,7 @@ public class ExecutionContextPromotionListenerTests { } /** - * CONDITION: keys = {key1, key2}. statuses = {statusWildcard}. ExitStatus = + * CONDITION: keys = {key, key2}. statuses = {statusWildcard}. ExitStatus = * status * * EXPECTED: key is promoted. key2 is not. @@ -145,6 +147,33 @@ public class ExecutionContextPromotionListenerTests { assertFalse(jobExecution.getExecutionContext().containsKey(key2)); } + /** + * CONDITION: keys = {key, key2}. Only {key} exists in the ExecutionContext. + * + * EXPECTED: key is promoted. key2 is not. + */ + @Test + public void promoteEntries_keyNotFound() throws Exception { + ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener(); + + 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 *