|
18 | 18 |
|
19 | 19 | import static org.junit.Assert.assertEquals;
|
20 | 20 | import static org.junit.Assert.assertFalse;
|
| 21 | +import static org.junit.Assert.assertNotNull; |
| 22 | +import static org.junit.Assert.assertSame; |
21 | 23 | import static org.junit.Assert.assertTrue;
|
22 | 24 |
|
23 | 25 | import java.util.concurrent.CopyOnWriteArrayList;
|
24 | 26 |
|
25 | 27 | import org.junit.Test;
|
26 | 28 |
|
| 29 | +import org.springframework.beans.DirectFieldAccessor; |
| 30 | +import org.springframework.beans.factory.config.BeanDefinition; |
| 31 | +import org.springframework.beans.factory.support.RootBeanDefinition; |
27 | 32 | import org.springframework.context.Lifecycle;
|
| 33 | +import org.springframework.context.LifecycleProcessor; |
28 | 34 | import org.springframework.context.SmartLifecycle;
|
29 | 35 |
|
30 | 36 | /**
|
|
33 | 39 | */
|
34 | 40 | public class DefaultLifecycleProcessorTests {
|
35 | 41 |
|
| 42 | + @Test |
| 43 | + public void defaultLifecycleProcessorInstance() { |
| 44 | + StaticApplicationContext context = new StaticApplicationContext(); |
| 45 | + context.refresh(); |
| 46 | + Object lifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor"); |
| 47 | + assertNotNull(lifecycleProcessor); |
| 48 | + assertEquals(DefaultLifecycleProcessor.class, lifecycleProcessor.getClass()); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void customLifecycleProcessorInstance() { |
| 53 | + BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class); |
| 54 | + beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000); |
| 55 | + StaticApplicationContext context = new StaticApplicationContext(); |
| 56 | + context.registerBeanDefinition("lifecycleProcessor", beanDefinition); |
| 57 | + context.refresh(); |
| 58 | + LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class); |
| 59 | + Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor"); |
| 60 | + assertNotNull(contextLifecycleProcessor); |
| 61 | + assertSame(bean, contextLifecycleProcessor); |
| 62 | + assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue("timeoutPerShutdownPhase")); |
| 63 | + } |
| 64 | + |
36 | 65 | @Test
|
37 | 66 | public void singleSmartLifecycleAutoStartup() throws Exception {
|
38 | 67 | CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<Lifecycle>();
|
|
0 commit comments