Clear context to job name mapping when clearing contexts BATCH-2347

This commit is contained in:
Michael Minella
2015-03-06 11:54:44 -06:00
parent acbe718d78
commit 8b32462072
2 changed files with 22 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.batch.core.Job;
@@ -35,6 +36,7 @@ import org.springframework.batch.core.step.NoSuchStepException;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.util.ReflectionTestUtils;
/**
* @author Dave Syer
@@ -57,6 +59,18 @@ public class DefaultJobLoaderTests {
private DefaultJobLoader jobLoader = new DefaultJobLoader(jobRegistry, stepRegistry);
@Test
public void testClear() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(new ByteArrayResource(
JOB_XML.getBytes()));
jobLoader.load(factory);
assertEquals(1, ((Map) ReflectionTestUtils.getField(jobLoader, "contexts")).size());
assertEquals(1, ((Map) ReflectionTestUtils.getField(jobLoader, "contextToJobNames")).size());
jobLoader.clear();
assertEquals(0, ((Map) ReflectionTestUtils.getField(jobLoader, "contexts")).size());
assertEquals(0, ((Map) ReflectionTestUtils.getField(jobLoader, "contextToJobNames")).size());
}
@Test
public void testLoadWithExplicitName() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(new ByteArrayResource(