From a64f0f1ebedf317b6ff3b34ec615fa9ea85a1931 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 27 Nov 2009 20:38:43 +0000 Subject: [PATCH] Added tests for the DefaultLifecycleProcessor and a custom "lifecycleProcessor" bean. --- .../support/DefaultLifecycleProcessor.java | 4 +-- .../DefaultLifecycleProcessorTests.java | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java b/org.springframework.context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java index d67869d981..5f5b670f19 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java +++ b/org.springframework.context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java @@ -55,8 +55,8 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor /** - * Specify the maximum time allotted for the shutdown of any phase - * (group of SmartLifecycle beans with the same 'phase' value). + * Specify the maximum time allotted in milliseconds for the shutdown of + * any phase (group of SmartLifecycle beans with the same 'phase' value). * The default value is 30 seconds. */ public void setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase) { diff --git a/org.springframework.context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java b/org.springframework.context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java index 116743d5ec..ea3fc2b361 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java @@ -18,13 +18,19 @@ package org.springframework.context.support; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.util.concurrent.CopyOnWriteArrayList; import org.junit.Test; +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.Lifecycle; +import org.springframework.context.LifecycleProcessor; import org.springframework.context.SmartLifecycle; /** @@ -33,6 +39,29 @@ import org.springframework.context.SmartLifecycle; */ public class DefaultLifecycleProcessorTests { + @Test + public void defaultLifecycleProcessorInstance() { + StaticApplicationContext context = new StaticApplicationContext(); + context.refresh(); + Object lifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor"); + assertNotNull(lifecycleProcessor); + assertEquals(DefaultLifecycleProcessor.class, lifecycleProcessor.getClass()); + } + + @Test + public void customLifecycleProcessorInstance() { + BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class); + beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000); + StaticApplicationContext context = new StaticApplicationContext(); + context.registerBeanDefinition("lifecycleProcessor", beanDefinition); + context.refresh(); + LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class); + Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor"); + assertNotNull(contextLifecycleProcessor); + assertSame(bean, contextLifecycleProcessor); + assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue("timeoutPerShutdownPhase")); + } + @Test public void singleSmartLifecycleAutoStartup() throws Exception { CopyOnWriteArrayList startedBeans = new CopyOnWriteArrayList();