From 0b17684192998e7b1c74edd50dec6df719085f43 Mon Sep 17 00:00:00 2001 From: dsyer Date: Mon, 4 May 2009 08:25:29 +0000 Subject: [PATCH] BATCH-1228: use proxyTargetClass=true in proxy --- ...ScopeProxyTargetClassIntegrationTests.java | 72 +++++++++++++++++++ ...oxyTargetClassIntegrationTests-context.xml | 18 +++++ 2 files changed, 90 insertions(+) create mode 100644 spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests.java create mode 100644 spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests-context.xml diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests.java new file mode 100644 index 000000000..8c1432819 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests.java @@ -0,0 +1,72 @@ +package org.springframework.batch.core.scope; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.scope.context.StepSynchronizationManager; +import org.springframework.batch.item.ExecutionContext; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.ListableBeanFactory; +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; + +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class StepScopeProxyTargetClassIntegrationTests implements BeanFactoryAware { + + @Autowired + @Qualifier("simple") + private TestCollaborator simple; + + private StepExecution stepExecution; + + private ListableBeanFactory beanFactory; + + private int beanCount; + + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = (ListableBeanFactory) beanFactory; + } + + @Before + public void start() { + + StepSynchronizationManager.close(); + stepExecution = new StepExecution("foo", new JobExecution(11L), 123L); + + ExecutionContext executionContext = new ExecutionContext(); + executionContext.put("foo", "bar"); + + stepExecution.setExecutionContext(executionContext); + StepSynchronizationManager.register(stepExecution); + + beanCount = beanFactory.getBeanDefinitionCount(); + + } + + @After + public void cleanUp() { + StepSynchronizationManager.close(); + // Check that all temporary bean definitions are cleaned up + assertEquals(beanCount, beanFactory.getBeanDefinitionCount()); + } + + @Test + public void testSimpleProperty() throws Exception { + assertEquals("bar", simple.getName()); + // Once the step context is set up it should be baked into the proxies + // so changing it now should have no effect + stepExecution.getExecutionContext().put("foo", "wrong!"); + assertEquals("bar", simple.getName()); + } + +} diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests-context.xml new file mode 100644 index 000000000..56b52816c --- /dev/null +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/StepScopeProxyTargetClassIntegrationTests-context.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file