Add ViewResolverRegistry#scriptTemplate in WebFlux
Issue: SPR-16431
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,16 +15,22 @@
|
||||
*/
|
||||
package org.springframework.web.reactive.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
import org.springframework.web.reactive.result.view.HttpMessageWriterView;
|
||||
import org.springframework.web.reactive.result.view.UrlBasedViewResolver;
|
||||
import org.springframework.web.reactive.result.view.View;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.springframework.web.reactive.result.view.script.ScriptTemplateConfigurer;
|
||||
import org.springframework.web.reactive.result.view.script.ScriptTemplateViewResolver;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -32,6 +38,7 @@ import static org.junit.Assert.*;
|
||||
* Unit tests for {@link ViewResolverRegistry}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class ViewResolverRegistryTests {
|
||||
|
||||
@@ -42,6 +49,7 @@ public class ViewResolverRegistryTests {
|
||||
public void setup() {
|
||||
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
||||
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
|
||||
context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
|
||||
this.registry = new ViewResolverRegistry(context);
|
||||
}
|
||||
|
||||
@@ -84,4 +92,16 @@ public class ViewResolverRegistryTests {
|
||||
assertSame(view, this.registry.getDefaultViews().get(0));
|
||||
}
|
||||
|
||||
@Test // SPR-16431
|
||||
public void scriptTemplate() {
|
||||
this.registry.scriptTemplate().prefix("/").suffix(".html");
|
||||
|
||||
List<ViewResolver> viewResolvers = this.registry.getViewResolvers();
|
||||
assertEquals(1, viewResolvers.size());
|
||||
assertEquals(ScriptTemplateViewResolver.class, viewResolvers.get(0).getClass());
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(viewResolvers.get(0));
|
||||
assertEquals("/", accessor.getPropertyValue("prefix"));
|
||||
assertEquals(".html", accessor.getPropertyValue("suffix"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user