Add additional test cases for step-scoped proxies

This commit is contained in:
dsyer
2010-04-09 09:54:26 +00:00
parent f71f61d30c
commit a28a4c3f76
5 changed files with 64 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -27,6 +28,10 @@ public class StepScopeDestructionCallbackIntegrationTests {
@Qualifier("nested")
private Step nested;
@Autowired
@Qualifier("ref")
private Step ref;
@Autowired
@Qualifier("foo")
private Collaborator foo;
@@ -42,14 +47,14 @@ public class StepScopeDestructionCallbackIntegrationTests {
public void testDisposableScopedProxy() throws Exception {
assertNotNull(proxied);
proxied.execute(new StepExecution("step", new JobExecution(0L), 1L));
assertEquals("destroyed", TestDisposableCollaborator.message);
assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed"));
}
@Test
public void testDisposableInnerScopedProxy() throws Exception {
assertNotNull(nested);
nested.execute(new StepExecution("step", new JobExecution(0L), 1L));
assertEquals("destroyed", TestDisposableCollaborator.message);
assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed"));
}
@Test
@@ -58,7 +63,18 @@ public class StepScopeDestructionCallbackIntegrationTests {
nested.execute(new StepExecution("step", new JobExecution(0L), 1L));
assertEquals(4, TestAdvice.names.size());
assertEquals("bar", TestAdvice.names.get(0));
assertEquals("destroyed", TestDisposableCollaborator.message);
assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed"));
}
@Test
public void testRefScopedProxy() throws Exception {
assertNotNull(ref);
ref.execute(new StepExecution("step", new JobExecution(0L), 1L));
assertEquals(4, TestAdvice.names.size());
assertEquals("spam", TestAdvice.names.get(0));
assertEquals(2, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed"));
assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "bar:destroyed"));
assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "spam:destroyed"));
}
@Test

View File

@@ -39,6 +39,10 @@ public class StepScopePlaceholderIntegrationTests implements BeanFactoryAware {
@Qualifier("ref")
private Collaborator ref;
@Autowired
@Qualifier("scopedRef")
private Collaborator scopedRef;
@Autowired
@Qualifier("list")
private Collaborator list;
@@ -63,12 +67,16 @@ public class StepScopePlaceholderIntegrationTests implements BeanFactoryAware {
@Before
public void start() {
start("bar");
}
private void start(String foo) {
StepSynchronizationManager.close();
stepExecution = new StepExecution("foo", new JobExecution(11L), 123L);
ExecutionContext executionContext = new ExecutionContext();
executionContext.put("foo", "bar");
executionContext.put("foo", foo);
executionContext.put("parent", bar);
stepExecution.setExecutionContext(executionContext);
@@ -79,7 +87,7 @@ public class StepScopePlaceholderIntegrationTests implements BeanFactoryAware {
}
@After
public void cleanUp() {
public void stop() {
StepSynchronizationManager.close();
// Check that all temporary bean definitions are cleaned up
assertEquals(beanCount, beanFactory.getBeanDefinitionCount());
@@ -137,4 +145,12 @@ public class StepScopePlaceholderIntegrationTests implements BeanFactoryAware {
assertEquals("bar", nested.getParent().getName());
}
@Test
public void testScopedRef() throws Exception {
assertEquals("bar", scopedRef.getParent().getName());
stop();
start("spam");
assertEquals("spam", scopedRef.getParent().getName());
}
}

View File

@@ -2,13 +2,12 @@ package org.springframework.batch.core.scope;
import org.springframework.beans.factory.DisposableBean;
public class TestDisposableCollaborator extends TestCollaborator implements DisposableBean {
public static volatile String message = "none";
public void destroy() throws Exception {
message = "destroyed";
message = (message.equals("none") ? "" : message + ",") + getName() + ":destroyed";
}
}