25
25
import freemarker .template .Template ;
26
26
import org .junit .Test ;
27
27
28
- import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
29
- import org .springframework .beans .factory .support .RootBeanDefinition ;
30
28
import org .springframework .core .io .ByteArrayResource ;
31
- import org .springframework .core .io .DefaultResourceLoader ;
32
29
import org .springframework .core .io .FileSystemResource ;
33
30
import org .springframework .core .io .Resource ;
34
31
import org .springframework .core .io .ResourceLoader ;
41
38
/**
42
39
* @author Juergen Hoeller
43
40
* @author Issam El-atif
41
+ * @author Sam Brannen
44
42
*/
45
43
public class FreeMarkerConfigurerTests {
46
44
45
+ private final FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer ();
46
+
47
47
@ Test
48
- public void freeMarkerConfigurationFactoryBeanWithConfigLocation () throws Exception {
49
- FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer ();
48
+ public void freeMarkerConfigurerWithConfigLocation () throws Exception {
50
49
freeMarkerConfigurer .setConfigLocation (new FileSystemResource ("myprops.properties" ));
51
50
Properties props = new Properties ();
52
51
props .setProperty ("myprop" , "/mydir" );
53
52
freeMarkerConfigurer .setFreemarkerSettings (props );
54
- assertThatIOException ().isThrownBy (
55
- freeMarkerConfigurer ::afterPropertiesSet );
53
+ assertThatIOException ().isThrownBy (freeMarkerConfigurer ::afterPropertiesSet );
56
54
}
57
55
58
56
@ Test
59
- public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath () throws Exception {
60
- FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer ();
57
+ public void freeMarkerConfigurerWithResourceLoaderPath () throws Exception {
61
58
freeMarkerConfigurer .setTemplateLoaderPath ("file:/mydir" );
62
59
freeMarkerConfigurer .afterPropertiesSet ();
63
60
Configuration cfg = freeMarkerConfigurer .getConfiguration ();
@@ -69,8 +66,7 @@ public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Ex
69
66
70
67
@ Test
71
68
@ SuppressWarnings ("rawtypes" )
72
- public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath () throws Exception {
73
- FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer ();
69
+ public void freeMarkerConfigurerWithNonFileResourceLoaderPath () throws Exception {
74
70
freeMarkerConfigurer .setTemplateLoaderPath ("file:/mydir" );
75
71
Properties settings = new Properties ();
76
72
settings .setProperty ("localized_lookup" , "false" );
@@ -95,16 +91,4 @@ public ClassLoader getClassLoader() {
95
91
assertThat (FreeMarkerTemplateUtils .processTemplateIntoString (ft , new HashMap ())).isEqualTo ("test" );
96
92
}
97
93
98
- @ Test // SPR-12448
99
- public void freeMarkerConfigurationAsBean () {
100
- DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory ();
101
- RootBeanDefinition loaderDef = new RootBeanDefinition (SpringTemplateLoader .class );
102
- loaderDef .getConstructorArgumentValues ().addGenericArgumentValue (new DefaultResourceLoader ());
103
- loaderDef .getConstructorArgumentValues ().addGenericArgumentValue ("/freemarker" );
104
- RootBeanDefinition configDef = new RootBeanDefinition (Configuration .class );
105
- configDef .getPropertyValues ().add ("templateLoader" , loaderDef );
106
- beanFactory .registerBeanDefinition ("freeMarkerConfig" , configDef );
107
- beanFactory .getBean (Configuration .class );
108
- }
109
-
110
94
}
0 commit comments