IN PROGRESS - issue BATCH-891: Create Annotations

http://jira.springframework.org/browse/BATCH-891

Added a post processor that checks for annotations. (still under development)
This commit is contained in:
lucasward
2008-11-07 16:35:09 +00:00
parent 97ce100ff9
commit 9ac28ef106
5 changed files with 290 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package org.springframework.batch.core.annotation;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.job.SimpleJob;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"component-scan-context.xml"})
public class StepComponentBeanPostProcessorIntegrationTests {
@Autowired
private SimpleJob job;
@Autowired
private JobLauncher jobLauncher;
@Test
public void testListener() throws Exception{
jobLauncher.run(job, new JobParameters());
// assertTrue(TestComponent.isAfterStepCalled());
// assertTrue(TestComponent.isBeforeStepCalled());
}
}

View File

@@ -0,0 +1,55 @@
/**
*
*/
package org.springframework.batch.core.annotation;
import static org.easymock.EasyMock.createMock;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Lucas Ward
*
*/
public class StepComponentBeanPostProcessorTests {
@BatchComponent
private class TestComponent {
boolean afterStepCalled = false;
@AfterStep
public void testMethod(){
afterStepCalled = true;
}
}
@Test
public void testNormalCase() throws Exception{
AbstractStep step = new StubStep();
step.setJobRepository(createMock(JobRepository.class));
StepComponentBeanPostProcessor postProcessor = new StepComponentBeanPostProcessor(step, "org.springframework.batch.core.annotation");
TestComponent testComponent = new TestComponent();
postProcessor.postProcessAfterInitialization(testComponent, "testComponent");
step.execute(new StepExecution("teststep", new JobExecution(11L)));
assertTrue(testComponent.afterStepCalled);
}
private class StubStep extends AbstractStep{
@Override
protected ExitStatus doExecute(StepExecution stepExecution)
throws Exception {
// TODO Auto-generated method stub
return ExitStatus.FINISHED;
}
}
}

View File

@@ -10,4 +10,25 @@ package org.springframework.batch.core.annotation;
@BatchComponent
public class TestComponent {
private static boolean beforeStepCalled = false;
private static boolean afterStepCalled = false;
public static boolean isBeforeStepCalled(){
return beforeStepCalled;
}
public static boolean isAfterStepCalled(){
return afterStepCalled;
}
@BeforeStep
public void beforeStep(){
beforeStepCalled = true;
}
@AfterStep
public void afterStep(){
afterStepCalled = true;
}
}