OPEN - issue BATCH-673: Add new Java 5.0 features
http://jira.springframework.org/browse/BATCH-673 Removed unnecessary classes.
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.core.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class BatchComponentIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testWithoutResolver(){
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/annotation/batch-component-context.xml");
|
||||
String[] beanNames = context.getBeanNamesForType(TestComponent.class);
|
||||
//There should be one instance of TextComponent in the Spring Container, because it's annotated with BatchComponent, and the filter
|
||||
//is setup. However, the beanDefinition, should not have the scope on it, because there is no proxy set.
|
||||
assertEquals(1, beanNames.length);
|
||||
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory();
|
||||
BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNames[0]);
|
||||
//Even though BatchComponent is annotated with StepScope, the scope will still be singleton without the resolver.
|
||||
assertEquals(BeanDefinition.SCOPE_SINGLETON, beanDef.getScope());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResolver(){
|
||||
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/annotation/batch-component-context-with-resolver.xml");
|
||||
String[] beanNames = context.getBeanNamesForType(TestComponent.class);
|
||||
//There should be one instance of TextComponent in the Spring Container, because it's annotated with BatchComponent, and the filter
|
||||
//is setup. However, the beanDefinition, should not have the scope on it, because there is no proxy set.
|
||||
assertEquals(1, beanNames.length);
|
||||
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory();
|
||||
BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNames[0]);
|
||||
//Even though BatchComponent is annotated with StepScope, the scope will still be singleton without the resolver.
|
||||
assertEquals("step", beanDef.getScope());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResolverNonScanned(){
|
||||
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/annotation/batch-component-context-with-resolver-nonscanned.xml");
|
||||
String[] beanNames = context.getBeanNamesForType(TestComponent.class);
|
||||
//There should be one instance of TextComponent in the Spring Container, because it's annotated with BatchComponent, and the filter
|
||||
//is setup. However, the beanDefinition, should not have the scope on it, because there is no proxy set.
|
||||
assertEquals(1, beanNames.length);
|
||||
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory();
|
||||
BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNames[0]);
|
||||
//Even though BatchComponent is annotated with StepScope, the scope will still be singleton without the resolver.
|
||||
assertEquals(BeanDefinition.SCOPE_SINGLETON, beanDef.getScope());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithScopedComponent(){
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/annotation/batch-component-context-scoped.xml");
|
||||
String[] beanNames = context.getBeanNamesForType(TestScopedComponent.class);
|
||||
//There should be one instance of TextComponent in the Spring Container, because it's annotated with BatchComponent, and the filter
|
||||
//is setup. However, the beanDefinition, should not have the scope on it, because there is no proxy set.
|
||||
assertEquals(1, beanNames.length);
|
||||
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory)context.getAutowireCapableBeanFactory();
|
||||
BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNames[0]);
|
||||
//Even though BatchComponent is annotated with StepScope, the scope will still be singleton without the resolver.
|
||||
assertEquals(BeanDefinition.SCOPE_SINGLETON, beanDef.getScope());
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.core.annotation;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class BatchComponentScopeMetaDataResolverTests {
|
||||
|
||||
AnnotatedBeanDefinition annBeanDef;
|
||||
AnnotationMetadata metaData;
|
||||
BatchComponentScopeMetaDataResolver resolver = new BatchComponentScopeMetaDataResolver();
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
annBeanDef = createMock(AnnotatedBeanDefinition.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalCase(){
|
||||
expect(annBeanDef.getMetadata()).andReturn(new StandardAnnotationMetadata(StubScopedClass.class));
|
||||
expect(annBeanDef.getMetadata()).andReturn(new StandardAnnotationMetadata(StubScopedClass.class));
|
||||
replay(annBeanDef);
|
||||
assertEquals("step",resolver.resolveScopeMetadata(annBeanDef).getScopeName());
|
||||
verify(annBeanDef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchComponent(){
|
||||
|
||||
expect(annBeanDef.getMetadata()).andReturn(new StandardAnnotationMetadata(TestComponent.class));
|
||||
replay(annBeanDef);
|
||||
assertEquals("step",resolver.resolveScopeMetadata(annBeanDef).getScopeName());
|
||||
verify(annBeanDef);
|
||||
}
|
||||
|
||||
@Scope("step")
|
||||
private class StubScopedClass{}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.springframework.batch.core.annotation;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
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 JobParametersBuilder().addDate("run.date", new Date()).toJobParameters());
|
||||
|
||||
// assertTrue(TestComponent.isAfterStepCalled());
|
||||
// assertTrue(TestComponent.isBeforeStepCalled());
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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.ExitStatus;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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 void doExecute(StepExecution stepExecution) throws Exception {
|
||||
stepExecution.setExitStatus(ExitStatus.FINISHED);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.core.annotation;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package org.springframework.batch.core.annotation;
|
||||
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
@Scope("step")
|
||||
public class TestScopedComponent {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user