RESOLVED - issue BATCH-1130: Ensure Ordered is respected by generated listeners
Add JobListenerFactoryBean - same solution
This commit is contained in:
@@ -23,10 +23,12 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobExecutionListener;
|
||||
import org.springframework.batch.core.annotation.AfterJob;
|
||||
import org.springframework.batch.core.annotation.BeforeJob;
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
@@ -74,6 +76,15 @@ public class JobListenerFactoryBeanTests {
|
||||
assertTrue(delegate.afterJobCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVanillaInterfaceWithProxy() throws Exception {
|
||||
JobListenerWithInterface delegate = new JobListenerWithInterface();
|
||||
ProxyFactory factory = new ProxyFactory(delegate);
|
||||
factoryBean.setDelegate(factory.getProxy());
|
||||
Object listener = factoryBean.getObject();
|
||||
assertTrue(listener instanceof JobExecutionListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUseInHashSet() throws Exception {
|
||||
JobListenerWithInterface delegate = new JobListenerWithInterface();
|
||||
@@ -102,6 +113,23 @@ public class JobListenerFactoryBeanTests {
|
||||
assertTrue(JobListenerFactoryBean.isListener(new JobListenerWithInterface()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationsWithOrdered() throws Exception {
|
||||
Object delegate = new Ordered() {
|
||||
@SuppressWarnings("unused")
|
||||
@BeforeJob
|
||||
public void foo(JobExecution execution) {
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return 3;
|
||||
}
|
||||
};
|
||||
JobExecutionListener listener = JobListenerFactoryBean.getListener(delegate);
|
||||
assertTrue("Listener is not of correct type", listener instanceof Ordered);
|
||||
assertEquals(3, ((Ordered) listener).getOrder());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityOfProxies() throws Exception {
|
||||
JobListenerWithInterface delegate = new JobListenerWithInterface();
|
||||
|
||||
Reference in New Issue
Block a user