@ -25,6 +25,7 @@ import java.util.Locale;
@@ -25,6 +25,7 @@ import java.util.Locale;
import java.util.Map ;
import groovy.text.markup.BaseTemplate ;
import groovy.text.markup.DelegatingIndentWriter ;
import groovy.text.markup.MarkupTemplateEngine ;
import groovy.text.markup.TemplateConfiguration ;
import jakarta.servlet.http.HttpServletRequest ;
@ -159,9 +160,16 @@ class GroovyTemplateAutoConfigurationTests {
@@ -159,9 +160,16 @@ class GroovyTemplateAutoConfigurationTests {
assertThat ( result ) . contains ( "suffixed" ) ;
}
@Test
void defaultResourceLoaderPath ( ) throws Exception {
registerAndRefreshContext ( ) ;
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . getResourceLoaderPath ( ) )
. isEqualTo ( GroovyTemplateProperties . DEFAULT_RESOURCE_LOADER_PATH ) ;
}
@Test
@WithResource ( name = "custom-templates/custom.tpl" , content = "yield \"custom\"" )
void customTemplateLoaderPath ( ) throws Exception {
void customResourc eLoaderPath ( ) throws Exception {
registerAndRefreshContext ( "spring.groovy.template.resource-loader-path:classpath:/custom-templates/" ) ;
MockHttpServletResponse response = render ( "custom" ) ;
String result = response . getContentAsString ( ) ;
@ -206,6 +214,13 @@ class GroovyTemplateAutoConfigurationTests {
@@ -206,6 +214,13 @@ class GroovyTemplateAutoConfigurationTests {
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . isAutoIndent ( ) ) . isTrue ( ) ;
}
@Test
void defaultAutoIndentString ( ) {
registerAndRefreshContext ( ) ;
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . getAutoIndentString ( ) )
. isEqualTo ( DelegatingIndentWriter . SPACES ) ;
}
@Test
void customAutoIndentString ( ) {
registerAndRefreshContext ( "spring.groovy.template.auto-indent-string:\\t" ) ;
@ -218,6 +233,13 @@ class GroovyTemplateAutoConfigurationTests {
@@ -218,6 +233,13 @@ class GroovyTemplateAutoConfigurationTests {
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . isAutoNewLine ( ) ) . isTrue ( ) ;
}
@Test
void defaultBaseTemplateClass ( ) {
registerAndRefreshContext ( ) ;
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . getBaseTemplateClass ( ) )
. isEqualTo ( BaseTemplate . class ) ;
}
@Test
void customBaseTemplateClass ( ) {
registerAndRefreshContext ( "spring.groovy.template.base-template-class:" + CustomBaseTemplate . class . getName ( ) ) ;
@ -225,6 +247,12 @@ class GroovyTemplateAutoConfigurationTests {
@@ -225,6 +247,12 @@ class GroovyTemplateAutoConfigurationTests {
. isEqualTo ( CustomBaseTemplate . class ) ;
}
@Test
void defaultDeclarationEncoding ( ) {
registerAndRefreshContext ( ) ;
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . getDeclarationEncoding ( ) ) . isNull ( ) ;
}
@Test
void customDeclarationEncoding ( ) {
registerAndRefreshContext ( "spring.groovy.template.declaration-encoding:UTF-8" ) ;
@ -237,12 +265,25 @@ class GroovyTemplateAutoConfigurationTests {
@@ -237,12 +265,25 @@ class GroovyTemplateAutoConfigurationTests {
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . isExpandEmptyElements ( ) ) . isTrue ( ) ;
}
@Test
void defaultLocale ( ) {
registerAndRefreshContext ( ) ;
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . getLocale ( ) ) . isEqualTo ( Locale . getDefault ( ) ) ;
}
@Test
void customLocale ( ) {
registerAndRefreshContext ( "spring.groovy.template.locale:en_US" ) ;
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . getLocale ( ) ) . isEqualTo ( Locale . US ) ;
}
@Test
void defaultNewLineString ( ) {
registerAndRefreshContext ( ) ;
assertThat ( this . context . getBean ( GroovyMarkupConfigurer . class ) . getNewLineString ( ) )
. isEqualTo ( System . lineSeparator ( ) ) ;
}
@Test
void customNewLineString ( ) {
registerAndRefreshContext ( "spring.groovy.template.new-line-string:\\r\\n" ) ;