OPEN - issue BATCH-911: Consolidate Samples

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

Added support for listeners that implement the interface, along with support for class attribute in listener tag.
This commit is contained in:
lucasward
2008-11-19 07:02:32 +00:00
parent 6e39c1a572
commit 6a66b0efed
5 changed files with 218 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
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;
@@ -32,12 +33,15 @@ public class JobExecutionListenerAdapterTests {
private TestClass testClass;
private AnnotatedTestClass annotatedTestClass;
private InterfaceTestClass interfaceTestClass;
private JobExecution jobExecution = new JobExecution(11L);
@Before
public void setUp(){
testClass = new TestClass();
annotatedTestClass = new AnnotatedTestClass();
interfaceTestClass = new InterfaceTestClass();
}
@Test
@@ -90,6 +94,16 @@ public class JobExecutionListenerAdapterTests {
assertTrue(annotatedTestClass.afterJobCalled);
}
@Test
public void testWithInterface() throws Exception{
JobExecutionListenerAdapter adapter = new JobExecutionListenerAdapter(interfaceTestClass);
adapter.afterPropertiesSet();
adapter.beforeJob(jobExecution);
adapter.afterJob(jobExecution);
assertTrue(annotatedTestClass.beforeJobCalled);
assertTrue(annotatedTestClass.afterJobCalled);
}
private class TestClass{
boolean beforeJobCalled = false;
@@ -116,4 +130,9 @@ public class JobExecutionListenerAdapterTests {
super.afterJobCalled = true;
}
}
private class InterfaceTestClass extends TestClass implements JobExecutionListener {
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.listener;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
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;
/**
* @author Lucas Ward
*
*/
public class JobExecutionListnerFactoryBeanTests {
JobExecutionListenerFactoryBean factoryBean;
@Before
public void setUp(){
factoryBean = new JobExecutionListenerFactoryBean();
}
@Test
public void testWithInterface() throws Exception{
JobListenerWithInterface delegate = new JobListenerWithInterface();
factoryBean.setDelegate(delegate);
assertEquals(delegate,factoryBean.getObject());
}
@Test
public void testWithAnnotations() throws Exception{
AnnotatedTestClass delegate = new AnnotatedTestClass();
factoryBean.setDelegate(delegate);
JobExecutionListener listener = (JobExecutionListener) factoryBean.getObject();
JobExecution jobExecution = new JobExecution(11L);
listener.beforeJob(jobExecution);
listener.afterJob(jobExecution);
assertTrue(delegate.beforeJobCalled);
assertTrue(delegate.afterJobCalled);
}
private class JobListenerWithInterface implements JobExecutionListener{
public void afterJob(JobExecution jobExecution) {
}
public void beforeJob(JobExecution jobExecution) {
}
}
private class AnnotatedTestClass {
boolean beforeJobCalled = false;
boolean afterJobCalled = false;
@BeforeJob
public void before(){
beforeJobCalled = true;
}
@AfterJob
public void after(){
afterJobCalled = true;
}
}
}