RESOLVED - issue BATCH-1130: Ensure Ordered is respected by generated listeners

Add JobListenerFactoryBean - same solution
This commit is contained in:
dsyer
2009-03-10 14:40:45 +00:00
parent 3719198418
commit 944b6aa4c8
2 changed files with 38 additions and 2 deletions

View File

@@ -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();