OPEN - issue BATCH-733: Upgrade StepExecutionResourceProxy to be able to use values from job execution context.

Step 1: extend JobFactory implementations a bit to provide more options for creating the context (also consolidated TaskExecutor and QUartz JobLaunchers into JobRegstryBackgroundJobRunner).
This commit is contained in:
dsyer
2008-07-21 16:41:16 +00:00
parent c424603e59
commit 69a64758d8
18 changed files with 566 additions and 332 deletions

View File

@@ -0,0 +1,30 @@
package org.springframework.batch.core.configuration.support;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.StaticApplicationContext;
public class ApplicationContextJobFactoryTests {
private ApplicationContextJobFactory factory = new ApplicationContextJobFactory(
new StubApplicationContextFactory(), "job");
@Test
public void testFactoryContext() throws Exception {
assertNotNull(factory.createJob());
}
private static class StubApplicationContextFactory implements
ApplicationContextFactory {
public ConfigurableApplicationContext createApplicationContext() {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("job", JobSupport.class);
return context ;
}
}
}

View File

@@ -17,28 +17,25 @@ package org.springframework.batch.core.configuration.support;
import junit.framework.TestCase;
import org.springframework.batch.core.Job;
import org.springframework.util.ClassUtils;
/**
* @author Dave Syer
*
*
*/
public class ClassPathXmlApplicationContextJobFactoryTests extends TestCase {
private ClassPathXmlApplicationContextJobFactory factory = new ClassPathXmlApplicationContextJobFactory("test-job", ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml"));
public class ClassPathXmlApplicationContextFactoryTests extends TestCase {
private ClassPathXmlApplicationContextFactory factory = new ClassPathXmlApplicationContextFactory();
/**
* Test method for {@link org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextJobFactory#createJob()}.
*/
public void testCreateJob() {
assertNotNull(factory.createJob());
factory.setPath(ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml"));
assertNotNull(factory.createApplicationContext());
}
/**
* Test method for {@link org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextJobFactory#getJobName()}.
*/
public void testGetJobName() {
assertEquals("test-job", factory.getJobName());
factory.setPath(ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml"));
assertEquals("test-job", factory.createApplicationContext().getBeanNamesForType(Job.class)[0]);
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2006-2007 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.launch.support;
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.util.ClassUtils;
/**
* @author Dave Syer
*
*/
public class JobRegistryBackgroundJobRunnerTests {
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.JobRegistryBackgroundJobRunner#main(java.lang.String[])}.
*/
@Test
public void testMain() {
assertEquals(0, JobRegistryBackgroundJobRunner.getErrors().size());
}
@Before
public void setUp() throws Exception {
JobRegistryBackgroundJobRunner.getErrors().clear();
System.setProperty(JobRegistryBackgroundJobRunner.EMBEDDED, "");
JobRegistryBackgroundJobRunner.main(
ClassUtils.addResourcePathToPackagePath(getClass(), "test-environment.xml"), ClassUtils
.addResourcePathToPackagePath(getClass(), "job.xml"));
}
@After
public void tearDown() throws Exception {
System.clearProperty(JobRegistryBackgroundJobRunner.EMBEDDED);
JobRegistryBackgroundJobRunner.getErrors().clear();
}
}