parent
ab36a0a82f
commit
9b084bb3ea
|
|
@ -16,9 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.ui.freemarker;
|
package org.springframework.ui.freemarker;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import freemarker.template.Configuration;
|
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.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
|
|
@ -27,42 +31,38 @@ 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;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIOException;
|
import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Issam El-atif
|
* @author Issam El-atif
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class FreeMarkerConfigurationFactoryBeanTests {
|
public class FreeMarkerConfigurationFactoryBeanTests {
|
||||||
|
|
||||||
|
private final FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void freeMarkerConfigurationFactoryBeanWithConfigLocation() throws Exception {
|
public void freeMarkerConfigurationFactoryBeanWithConfigLocation() throws Exception {
|
||||||
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
|
|
||||||
fcfb.setConfigLocation(new FileSystemResource("myprops.properties"));
|
fcfb.setConfigLocation(new FileSystemResource("myprops.properties"));
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.setProperty("myprop", "/mydir");
|
props.setProperty("myprop", "/mydir");
|
||||||
fcfb.setFreemarkerSettings(props);
|
fcfb.setFreemarkerSettings(props);
|
||||||
assertThatIOException().isThrownBy(
|
assertThatIOException().isThrownBy(fcfb::afterPropertiesSet);
|
||||||
fcfb::afterPropertiesSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
|
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
|
||||||
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
|
|
||||||
fcfb.setTemplateLoaderPath("file:/mydir");
|
fcfb.setTemplateLoaderPath("file:/mydir");
|
||||||
fcfb.afterPropertiesSet();
|
fcfb.afterPropertiesSet();
|
||||||
Configuration cfg = fcfb.getObject();
|
Configuration cfg = fcfb.getObject();
|
||||||
assertThat(cfg.getTemplateLoader() instanceof SpringTemplateLoader).isTrue();
|
assertThat(cfg.getTemplateLoader()).isInstanceOf(SpringTemplateLoader.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
|
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
|
||||||
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");
|
||||||
|
|
@ -96,7 +96,7 @@ public class FreeMarkerConfigurationFactoryBeanTests {
|
||||||
RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
|
RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
|
||||||
configDef.getPropertyValues().add("templateLoader", loaderDef);
|
configDef.getPropertyValues().add("templateLoader", loaderDef);
|
||||||
beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
|
beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
|
||||||
beanFactory.getBean(Configuration.class);
|
assertThat(beanFactory.getBean(Configuration.class)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,7 @@ 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.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
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;
|
||||||
|
|
@ -41,23 +38,23 @@ import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Issam El-atif
|
* @author Issam El-atif
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class FreeMarkerConfigurerTests {
|
public class FreeMarkerConfigurerTests {
|
||||||
|
|
||||||
|
private final FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void freeMarkerConfigurationFactoryBeanWithConfigLocation() throws Exception {
|
public void freeMarkerConfigurerWithConfigLocation() throws Exception {
|
||||||
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
|
||||||
freeMarkerConfigurer.setConfigLocation(new FileSystemResource("myprops.properties"));
|
freeMarkerConfigurer.setConfigLocation(new FileSystemResource("myprops.properties"));
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.setProperty("myprop", "/mydir");
|
props.setProperty("myprop", "/mydir");
|
||||||
freeMarkerConfigurer.setFreemarkerSettings(props);
|
freeMarkerConfigurer.setFreemarkerSettings(props);
|
||||||
assertThatIOException().isThrownBy(
|
assertThatIOException().isThrownBy(freeMarkerConfigurer::afterPropertiesSet);
|
||||||
freeMarkerConfigurer::afterPropertiesSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
|
public void freeMarkerConfigurerWithResourceLoaderPath() throws Exception {
|
||||||
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
|
||||||
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
|
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
|
||||||
freeMarkerConfigurer.afterPropertiesSet();
|
freeMarkerConfigurer.afterPropertiesSet();
|
||||||
Configuration cfg = freeMarkerConfigurer.getConfiguration();
|
Configuration cfg = freeMarkerConfigurer.getConfiguration();
|
||||||
|
|
@ -69,8 +66,7 @@ public class FreeMarkerConfigurerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
|
public void freeMarkerConfigurerWithNonFileResourceLoaderPath() throws Exception {
|
||||||
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
|
||||||
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
|
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
|
||||||
Properties settings = new Properties();
|
Properties settings = new Properties();
|
||||||
settings.setProperty("localized_lookup", "false");
|
settings.setProperty("localized_lookup", "false");
|
||||||
|
|
@ -95,16 +91,4 @@ public class FreeMarkerConfigurerTests {
|
||||||
assertThat(FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())).isEqualTo("test");
|
assertThat(FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())).isEqualTo("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@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