From b9a3065c0c3594994720fba6f1f68e2b0ebad2f5 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 1 Jun 2009 21:16:11 +0000 Subject: [PATCH] Added tests for the 'scheduler' element parsing within the 'task' namespace. --- .../SchedulerBeanDefinitionParserTests.java | 63 +++++++++++++++++++ .../scheduling/config/schedulerContext.xml | 14 +++++ 2 files changed, 77 insertions(+) create mode 100644 org.springframework.context/src/test/java/org/springframework/scheduling/config/SchedulerBeanDefinitionParserTests.java create mode 100644 org.springframework.context/src/test/resources/org/springframework/scheduling/config/schedulerContext.xml diff --git a/org.springframework.context/src/test/java/org/springframework/scheduling/config/SchedulerBeanDefinitionParserTests.java b/org.springframework.context/src/test/java/org/springframework/scheduling/config/SchedulerBeanDefinitionParserTests.java new file mode 100644 index 0000000000..cf274050bc --- /dev/null +++ b/org.springframework.context/src/test/java/org/springframework/scheduling/config/SchedulerBeanDefinitionParserTests.java @@ -0,0 +1,63 @@ +/* + * Copyright 2002-2009 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.scheduling.config; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; + +/** + * @author Mark Fisher + */ +public class SchedulerBeanDefinitionParserTests { + + private ApplicationContext context; + + + @Before + public void setup() { + this.context = new ClassPathXmlApplicationContext( + "schedulerContext.xml", SchedulerBeanDefinitionParserTests.class); + } + + @Test + public void defaultScheduler() { + ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) this.context.getBean("defaultScheduler"); + Integer size = (Integer) new DirectFieldAccessor(scheduler).getPropertyValue("poolSize"); + assertEquals(new Integer(1), size); + } + + @Test + public void customScheduler() { + ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) this.context.getBean("customScheduler"); + Integer size = (Integer) new DirectFieldAccessor(scheduler).getPropertyValue("poolSize"); + assertEquals(new Integer(42), size); + } + + @Test + public void threadNamePrefix() { + ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) this.context.getBean("customScheduler"); + assertEquals("customScheduler-", scheduler.getThreadNamePrefix()); + } + +} diff --git a/org.springframework.context/src/test/resources/org/springframework/scheduling/config/schedulerContext.xml b/org.springframework.context/src/test/resources/org/springframework/scheduling/config/schedulerContext.xml new file mode 100644 index 0000000000..21ee952503 --- /dev/null +++ b/org.springframework.context/src/test/resources/org/springframework/scheduling/config/schedulerContext.xml @@ -0,0 +1,14 @@ + + + + + + + +