|
20 | 20 | import java.util.Collections;
|
21 | 21 | import java.util.Locale;
|
22 | 22 |
|
| 23 | +import nz.net.ultraq.thymeleaf.LayoutDialect; |
| 24 | +import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy; |
23 | 25 | import org.junit.After;
|
24 | 26 | import org.junit.Rule;
|
25 | 27 | import org.junit.Test;
|
|
31 | 33 | import org.thymeleaf.templateresolver.TemplateResolver;
|
32 | 34 |
|
33 | 35 | import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
| 36 | +import org.springframework.boot.autoconfigure.test.ImportAutoConfiguration; |
34 | 37 | import org.springframework.boot.test.EnvironmentTestUtils;
|
35 | 38 | import org.springframework.boot.test.OutputCapture;
|
36 | 39 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
| 40 | +import org.springframework.context.annotation.Bean; |
| 41 | +import org.springframework.context.annotation.Configuration; |
37 | 42 | import org.springframework.mock.web.MockHttpServletRequest;
|
38 | 43 | import org.springframework.mock.web.MockHttpServletResponse;
|
39 | 44 | import org.springframework.mock.web.MockServletContext;
|
| 45 | +import org.springframework.test.util.ReflectionTestUtils; |
40 | 46 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
41 | 47 | import org.springframework.web.servlet.ViewResolver;
|
42 | 48 | import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
|
43 | 49 | import org.springframework.web.servlet.support.RequestContext;
|
44 | 50 |
|
45 | 51 | import static org.hamcrest.Matchers.containsString;
|
| 52 | +import static org.hamcrest.Matchers.instanceOf; |
| 53 | +import static org.hamcrest.Matchers.is; |
46 | 54 | import static org.junit.Assert.assertArrayEquals;
|
47 | 55 | import static org.junit.Assert.assertEquals;
|
48 | 56 | import static org.junit.Assert.assertNotNull;
|
@@ -221,4 +229,24 @@ public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled()
|
221 | 229 | assertNotNull(this.context.getBean(ResourceUrlEncodingFilter.class));
|
222 | 230 | }
|
223 | 231 |
|
| 232 | + @Test |
| 233 | + public void layoutDialectCanBeCustomized() throws Exception { |
| 234 | + this.context.register(LayoutDialectConfiguration.class); |
| 235 | + this.context.refresh(); |
| 236 | + LayoutDialect layoutDialect = this.context.getBean(LayoutDialect.class); |
| 237 | + assertThat(ReflectionTestUtils.getField(layoutDialect, "sortingStrategy"), |
| 238 | + is(instanceOf(GroupingStrategy.class))); |
| 239 | + } |
| 240 | + |
| 241 | + @Configuration |
| 242 | + @ImportAutoConfiguration({ ThymeleafAutoConfiguration.class, |
| 243 | + PropertyPlaceholderAutoConfiguration.class }) |
| 244 | + static class LayoutDialectConfiguration { |
| 245 | + |
| 246 | + @Bean |
| 247 | + public LayoutDialect layoutDialect() { |
| 248 | + return new LayoutDialect(new GroupingStrategy()); |
| 249 | + } |
| 250 | + } |
| 251 | + |
224 | 252 | }
|
0 commit comments