From 089ac8f1710eac4e0478ff160672164e0ce59bd0 Mon Sep 17 00:00:00 2001 From: dsyer Date: Sun, 21 Oct 2007 15:10:41 +0000 Subject: [PATCH] RESOLVED - issue BATCH-180: JobConfigurations do not get their names set if they are child beans http://opensource.atlassian.com/projects/spring/browse/BATCH-180 Removed setName() from *Configuration - you have to use the bean id or setBeanName(). --- .../step/AbstractStepConfiguration.java | 16 ++------- ...urationRegistryBeanPostProcessorTests.java | 6 ++-- .../facade/JobConfigurationTests.java | 35 ------------------- .../facade/SimpleJobExecutorFacadeTests.java | 2 +- .../job/DefaultJobExecutorTests.java | 6 ++-- .../repository/SimpleJobRepositoryTests.java | 2 +- .../simple/SimpleStepConfigurationTests.java | 2 +- .../simple/StepExecutorInterruptionTests.java | 2 +- .../src/test/resources/job-configuration.xml | 1 - 9 files changed, 11 insertions(+), 61 deletions(-) delete mode 100644 execution/src/test/java/org/springframework/batch/execution/facade/JobConfigurationTests.java diff --git a/execution/src/main/java/org/springframework/batch/execution/step/AbstractStepConfiguration.java b/execution/src/main/java/org/springframework/batch/execution/step/AbstractStepConfiguration.java index 412f0a0d1..5b88a1d28 100644 --- a/execution/src/main/java/org/springframework/batch/execution/step/AbstractStepConfiguration.java +++ b/execution/src/main/java/org/springframework/batch/execution/step/AbstractStepConfiguration.java @@ -29,7 +29,7 @@ import org.springframework.beans.factory.BeanNameAware; * @author Dave Syer * */ -public class AbstractStepConfiguration extends StepConfigurationSupport implements BeanNameAware { +public class AbstractStepConfiguration extends StepConfigurationSupport { private int skipLimit = 0; @@ -43,25 +43,13 @@ public class AbstractStepConfiguration extends StepConfigurationSupport implemen } /** - * Convenent constructor for setting only the name property. + * Convenient constructor for setting only the name property. * @param name */ public AbstractStepConfiguration(String name) { super(name); } - /** - * Set the name property if it has not already been set explicitly (and is - * therefore not null). - * - * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String) - */ - public void setBeanName(String name) { - if (getName() == null) { - setName(name); - } - } - public ExceptionHandler getExceptionHandler() { return exceptionHandler; } diff --git a/execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java b/execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java index ad4ed6f50..3842562c5 100644 --- a/execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java @@ -57,7 +57,7 @@ public class JobConfigurationRegistryBeanPostProcessorTests extends TestCase { MapJobConfigurationRegistry registry = new MapJobConfigurationRegistry(); processor.setJobConfigurationRegistry(registry); JobConfiguration configuration = new JobConfiguration(); - configuration.setName("foo"); + configuration.setBeanName("foo"); assertEquals(configuration, processor.postProcessAfterInitialization(configuration, "bar")); assertEquals(configuration, registry.getJobConfiguration("foo")); } @@ -66,7 +66,7 @@ public class JobConfigurationRegistryBeanPostProcessorTests extends TestCase { MapJobConfigurationRegistry registry = new MapJobConfigurationRegistry(); processor.setJobConfigurationRegistry(registry); JobConfiguration configuration = new JobConfiguration(); - configuration.setName("foo"); + configuration.setBeanName("foo"); processor.postProcessAfterInitialization(configuration, "bar"); try { processor.postProcessAfterInitialization(configuration, "spam"); @@ -81,7 +81,7 @@ public class JobConfigurationRegistryBeanPostProcessorTests extends TestCase { MapJobConfigurationRegistry registry = new MapJobConfigurationRegistry(); processor.setJobConfigurationRegistry(registry); JobConfiguration configuration = new JobConfiguration(); - configuration.setName("foo"); + configuration.setBeanName("foo"); assertEquals(configuration, processor.postProcessAfterInitialization(configuration, "bar")); processor.destroy(); try { diff --git a/execution/src/test/java/org/springframework/batch/execution/facade/JobConfigurationTests.java b/execution/src/test/java/org/springframework/batch/execution/facade/JobConfigurationTests.java deleted file mode 100644 index 540308dd8..000000000 --- a/execution/src/test/java/org/springframework/batch/execution/facade/JobConfigurationTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.execution.facade; - -import junit.framework.TestCase; - -import org.springframework.batch.core.configuration.JobConfiguration; -import org.springframework.context.support.StaticApplicationContext; - -public class JobConfigurationTests extends TestCase { - - public void testBeanName() throws Exception { - StaticApplicationContext context = new StaticApplicationContext(); - JobConfiguration configuration = new JobConfiguration(); - context.getAutowireCapableBeanFactory().initializeBean(configuration, "bean"); - assertNotNull(configuration.getName()); - configuration.setName("foo"); - context.getAutowireCapableBeanFactory().initializeBean(configuration, "bean"); - assertEquals("foo", configuration.getName()); - } -} diff --git a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java index 913093c37..ee955aac9 100644 --- a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java @@ -67,7 +67,7 @@ public class SimpleJobExecutorFacadeTests extends TestCase { protected void setUp() throws Exception { super.setUp(); - jobConfiguration.setName("TestJob"); + jobConfiguration.setBeanName("TestJob"); jobExecutorFacade.setJobExecutor(jobExecutor); jobRepository = (JobRepository) jobRepositoryControl.getMock(); jobExecutorFacade.setJobRepository(jobRepository); diff --git a/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java b/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java index fbd619070..c6c20fab7 100644 --- a/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java @@ -116,10 +116,8 @@ public class DefaultJobExecutorTests extends TestCase { } }); - stepConfiguration1 = new SimpleStepConfiguration(); - stepConfiguration1.setName("TestStep1"); - stepConfiguration2 = new SimpleStepConfiguration(); - stepConfiguration2.setName("TestStep2"); + stepConfiguration1 = new SimpleStepConfiguration("TestStep1"); + stepConfiguration2 = new SimpleStepConfiguration("TestStep2"); List stepConfigurations = new ArrayList(); stepConfigurations.add(stepConfiguration1); stepConfigurations.add(stepConfiguration2); diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java index 4fdb27eae..bc29b15ab 100644 --- a/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java @@ -84,7 +84,7 @@ public class SimpleJobRepositoryTests extends TestCase { jobRuntimeInformation = new SimpleJobIdentifier("RepositoryTest"); jobConfiguration = new JobConfiguration(); - jobConfiguration.setName("RepositoryTest"); + jobConfiguration.setBeanName("RepositoryTest"); jobConfiguration.setRestartable(true); stepConfiguration1 = new StepConfigurationSupport("TestStep1"); diff --git a/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java b/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java index ef23843b6..c2f4ad5d0 100644 --- a/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java @@ -66,7 +66,7 @@ public class SimpleStepConfigurationTests extends TestCase { */ public void testSetBeanName() { configuration.setBeanName("bar"); - assertEquals("foo", configuration.getName()); + assertEquals("bar", configuration.getName()); } /** diff --git a/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java b/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java index 871e2ebe0..804a9e735 100644 --- a/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java @@ -64,7 +64,7 @@ public class StepExecutorInterruptionTests extends TestCase { stepConfiguration = new SimpleStepConfiguration(); jobConfiguration.addStep(stepConfiguration); JobIdentifier runtimeInformation = new SimpleJobIdentifier("TestJob"); - jobConfiguration.setName("testJob"); + jobConfiguration.setBeanName("testJob"); job = jobRepository.findOrCreateJob(jobConfiguration, runtimeInformation); executor = new SimpleStepExecutor(); } diff --git a/execution/src/test/resources/job-configuration.xml b/execution/src/test/resources/job-configuration.xml index dcea4a600..64fd8db50 100644 --- a/execution/src/test/resources/job-configuration.xml +++ b/execution/src/test/resources/job-configuration.xml @@ -12,7 +12,6 @@ -