OPEN - issue BATCH-1108: Add composite ItemWriter/Processor based on Classifier

First draft of classifier features added.  Also refactored MethodInvoker abstraction into infrastructure.
This commit is contained in:
dsyer
2009-03-03 11:55:03 +00:00
parent b8208dcd8a
commit 998f6f592e
25 changed files with 819 additions and 132 deletions

View File

@@ -1,144 +0,0 @@
/*
* 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.
*/
/*
* 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.configuration.util;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.util.Assert;
/**
* @author Lucas Ward
*
*/
public class SimpleMethodInvokerTests {
TestClass testClass;
JobExecution jobExecution = new JobExecution(11L);
@Before
public void setUp(){
testClass = new TestClass();
}
@Test
public void testMethod() throws Exception{
Method method = TestClass.class.getMethod("beforeJob");
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method);
methodInvoker.invokeMethod(jobExecution);
assertTrue(testClass.beforeJobCalled);
}
@Test
public void testMethodByName() throws Exception{
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "beforeJob", JobExecutionListener.class);
methodInvoker.invokeMethod(jobExecution);
assertTrue(testClass.beforeJobCalled);
}
@Test
public void testMethodWithExecution() throws Exception{
Method method = TestClass.class.getMethod("beforeJobWithExecution", JobExecution.class);
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method);
methodInvoker.invokeMethod(jobExecution);
assertTrue(testClass.beforeJobCalled);
}
@Test
public void testMethodByNameWithExecution() throws Exception{
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "beforeJobWithExecution", JobExecution.class);
methodInvoker.invokeMethod(jobExecution);
assertTrue(testClass.beforeJobCalled);
}
@Test(expected=IllegalArgumentException.class)
public void testMethodWithTooManyArguments() throws Exception{
Method method = TestClass.class.getMethod("beforeJobWithTooManyArguments", JobExecution.class, int.class);
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method);
methodInvoker.invokeMethod(jobExecution);
assertFalse(testClass.beforeJobCalled);
}
@Test(expected=IllegalArgumentException.class)
public void testMethodByNameWithTooManyArguments() throws Exception{
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "beforeJobWithTooManyArguments", JobExecution.class);
methodInvoker.invokeMethod(jobExecution);
assertFalse(testClass.beforeJobCalled);
}
@Test
public void testMethodWithArgument() throws Exception{
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "argumentTest", Object.class);
methodInvoker.invokeMethod(new Object());
assertTrue(testClass.argumentTestCalled);
}
@Test
public void testEquals() throws Exception{
Method method = TestClass.class.getMethod("beforeJobWithExecution", JobExecution.class);
MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method);
method = TestClass.class.getMethod("beforeJobWithExecution", JobExecution.class);
MethodInvoker methodInvoker2 = new SimpleMethodInvoker(testClass, method);
assertEquals(methodInvoker, methodInvoker2);
}
private class TestClass{
boolean beforeJobCalled = false;
boolean argumentTestCalled = false;
public void beforeJob(){
beforeJobCalled = true;
}
public void beforeJobWithExecution(JobExecution jobExecution){
beforeJobCalled = true;
}
public void beforeJobWithTooManyArguments(JobExecution jobExecution, int someInt){
beforeJobCalled = true;
}
public void argumentTest(Object object){
Assert.notNull(object);
argumentTestCalled = true;
}
}
}

View File

@@ -26,7 +26,7 @@ import java.lang.annotation.Target;
import java.lang.reflect.Method;
import org.junit.Test;
import org.springframework.batch.core.configuration.util.AnnotationMethodResolver;
import org.springframework.batch.support.AnnotationMethodResolver;
/**
* @author Mark Fisher

View File

@@ -13,9 +13,9 @@ import org.aopalliance.intercept.MethodInvocation;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.configuration.util.MethodInvoker;
import org.springframework.batch.core.configuration.util.MethodInvokerUtils;
import org.springframework.batch.core.configuration.util.SimpleMethodInvoker;
import org.springframework.batch.support.MethodInvoker;
import org.springframework.batch.support.MethodInvokerUtils;
import org.springframework.batch.support.SimpleMethodInvoker;
public class StepListenerMethodInterceptorTests {