|
17 | 17 | package org.springframework.test.context.support; |
18 | 18 |
|
19 | 19 | import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader; |
20 | | -import org.springframework.beans.factory.support.BeanDefinitionReader; |
| 20 | +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
21 | 21 | import org.springframework.context.support.GenericApplicationContext; |
| 22 | +import org.springframework.test.context.MergedContextConfiguration; |
| 23 | +import org.springframework.util.StringUtils; |
22 | 24 |
|
23 | 25 | /** |
24 | 26 | * Concrete implementation of {@link AbstractGenericContextLoader} that reads |
|
36 | 38 | public class GenericGroovyXmlContextLoader extends GenericXmlContextLoader { |
37 | 39 |
|
38 | 40 | /** |
39 | | - * Create a new {@link GroovyBeanDefinitionReader}. |
40 | | - * @return a new {@code GroovyBeanDefinitionReader} |
| 41 | + * Load bean definitions into the supplied {@link GenericApplicationContext context} |
| 42 | + * from the locations in the supplied {@code MergedContextConfiguration}. |
| 43 | + * |
| 44 | + * <p>If a location ends with the suffix {@code ".xml"}, bean definitions |
| 45 | + * will be loaded from that location using an {@link XmlBeanDefinitionReader}; |
| 46 | + * otherwise, a {@link GroovyBeanDefinitionReader} will be used. |
| 47 | + * |
| 48 | + * @param context the context into which the bean definitions should be loaded |
| 49 | + * @param mergedConfig the merged context configuration |
| 50 | + * @see org.springframework.test.context.support.AbstractGenericContextLoader#loadBeanDefinitions |
41 | 51 | */ |
42 | 52 | @Override |
43 | | - protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) { |
44 | | - return new GroovyBeanDefinitionReader(context); |
| 53 | + protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) { |
| 54 | + XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); |
| 55 | + GroovyBeanDefinitionReader groovyReader = new GroovyBeanDefinitionReader(context); |
| 56 | + |
| 57 | + for (String location : mergedConfig.getLocations()) { |
| 58 | + if (StringUtils.endsWithIgnoreCase(location, ".xml")) { |
| 59 | + xmlReader.loadBeanDefinitions(location); |
| 60 | + } |
| 61 | + else { |
| 62 | + groovyReader.loadBeanDefinitions(location); |
| 63 | + } |
| 64 | + } |
45 | 65 | } |
46 | 66 |
|
47 | 67 | /** |
|
0 commit comments