Unit test for JavaBeans introspection against FreeMarker Configuration class
Issue: SPR-12448
This commit is contained in:
parent
7fcadaa393
commit
282adeda88
|
@ -24,7 +24,12 @@ import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
@ -42,7 +47,7 @@ import static org.junit.Assert.*;
|
||||||
public class FreeMarkerConfigurerTests {
|
public class FreeMarkerConfigurerTests {
|
||||||
|
|
||||||
@Test(expected = IOException.class)
|
@Test(expected = IOException.class)
|
||||||
public void freemarkerConfigurationFactoryBeanWithConfigLocation() throws Exception {
|
public void freeMarkerConfigurationFactoryBeanWithConfigLocation() throws Exception {
|
||||||
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
|
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
|
||||||
fcfb.setConfigLocation(new FileSystemResource("myprops.properties"));
|
fcfb.setConfigLocation(new FileSystemResource("myprops.properties"));
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
|
@ -62,14 +67,13 @@ public class FreeMarkerConfigurerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void freemarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
|
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
|
||||||
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
|
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
|
||||||
fcfb.setTemplateLoaderPath("file:/mydir");
|
fcfb.setTemplateLoaderPath("file:/mydir");
|
||||||
Properties settings = new Properties();
|
Properties settings = new Properties();
|
||||||
settings.setProperty("localized_lookup", "false");
|
settings.setProperty("localized_lookup", "false");
|
||||||
fcfb.setFreemarkerSettings(settings);
|
fcfb.setFreemarkerSettings(settings);
|
||||||
fcfb.setResourceLoader(new ResourceLoader() {
|
fcfb.setResourceLoader(new ResourceLoader() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource getResource(String location) {
|
public Resource getResource(String location) {
|
||||||
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
|
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
|
||||||
|
@ -77,7 +81,6 @@ public class FreeMarkerConfigurerTests {
|
||||||
}
|
}
|
||||||
return new ByteArrayResource("test".getBytes(), "test");
|
return new ByteArrayResource("test".getBytes(), "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassLoader getClassLoader() {
|
public ClassLoader getClassLoader() {
|
||||||
return getClass().getClassLoader();
|
return getClass().getClassLoader();
|
||||||
|
@ -90,4 +93,16 @@ public class FreeMarkerConfigurerTests {
|
||||||
assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap()));
|
assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // SPR-12448
|
||||||
|
public void freeMarkerConfigurationAsBean() {
|
||||||
|
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
|
RootBeanDefinition loaderDef = new RootBeanDefinition(SpringTemplateLoader.class);
|
||||||
|
loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new DefaultResourceLoader());
|
||||||
|
loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
|
||||||
|
RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
|
||||||
|
configDef.getPropertyValues().add("templateLoader", loaderDef);
|
||||||
|
beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
|
||||||
|
beanFactory.getBean(Configuration.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue