Moved encodeHttpHeaderFieldParam method to HttpHeaders itself (including tests)
This commit also sets the test source encoding to UTF-8. Issue: SPR-14547
This commit is contained in:
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.web.servlet.view.groovy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -27,7 +25,6 @@ import groovy.text.Template;
|
||||
import groovy.text.TemplateEngine;
|
||||
import groovy.text.markup.MarkupTemplateEngine;
|
||||
import groovy.text.markup.TemplateConfiguration;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -57,6 +54,7 @@ public class GroovyMarkupViewTests {
|
||||
|
||||
private ServletContext servletContext;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.webAppContext = mock(WebApplicationContext.class);
|
||||
@@ -82,7 +80,6 @@ public class GroovyMarkupViewTests {
|
||||
|
||||
@Test
|
||||
public void customTemplateEngine() throws Exception {
|
||||
|
||||
GroovyMarkupView view = new GroovyMarkupView();
|
||||
view.setTemplateEngine(new TestTemplateEngine());
|
||||
view.setApplicationContext(this.webAppContext);
|
||||
@@ -95,9 +92,7 @@ public class GroovyMarkupViewTests {
|
||||
|
||||
@Test
|
||||
public void detectTemplateEngine() throws Exception {
|
||||
|
||||
GroovyMarkupView view = new GroovyMarkupView();
|
||||
|
||||
view.setTemplateEngine(new TestTemplateEngine());
|
||||
view.setApplicationContext(this.webAppContext);
|
||||
|
||||
@@ -109,35 +104,30 @@ public class GroovyMarkupViewTests {
|
||||
|
||||
@Test
|
||||
public void checkResource() throws Exception {
|
||||
|
||||
GroovyMarkupView view = createViewWithUrl("test.tpl");
|
||||
assertTrue(view.checkResource(Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMissingResource() throws Exception {
|
||||
|
||||
GroovyMarkupView view = createViewWithUrl("missing.tpl");
|
||||
assertFalse(view.checkResource(Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkI18nResource() throws Exception {
|
||||
|
||||
GroovyMarkupView view = createViewWithUrl("i18n.tpl");
|
||||
assertTrue(view.checkResource(Locale.FRENCH));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkI18nResourceMissingLocale() throws Exception {
|
||||
|
||||
GroovyMarkupView view = createViewWithUrl("i18n.tpl");
|
||||
assertTrue(view.checkResource(Locale.CHINESE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderMarkupTemplate() throws Exception {
|
||||
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
model.put("name", "Spring");
|
||||
MockHttpServletResponse response = renderViewWithModel("test.tpl", model, Locale.US);
|
||||
@@ -155,7 +145,7 @@ public class GroovyMarkupViewTests {
|
||||
assertEquals("<p>Include German</p><p>Hallo Spring</p>", response.getContentAsString());
|
||||
|
||||
response = renderViewWithModel("i18n.tpl", model, new Locale("es"));
|
||||
assertEquals("<p>Include Default</p><p>¡hola Spring</p>", response.getContentAsString());
|
||||
assertEquals("<p>Include Default</p><p>Hola Spring</p>", response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,30 +156,30 @@ public class GroovyMarkupViewTests {
|
||||
response.getContentAsString());
|
||||
}
|
||||
|
||||
private MockHttpServletResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Locale locale) throws Exception {
|
||||
|
||||
private MockHttpServletResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Locale locale) throws Exception {
|
||||
GroovyMarkupView view = createViewWithUrl(viewUrl);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setPreferredLocales(Arrays.asList(locale));
|
||||
request.addPreferredLocale(locale);
|
||||
LocaleContextHolder.setLocale(locale);
|
||||
view.renderMergedTemplateModel(model, request, response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private GroovyMarkupView createViewWithUrl(String viewUrl) throws Exception {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(GroovyMarkupConfiguration.class);
|
||||
ctx.refresh();
|
||||
|
||||
GroovyMarkupView view = new GroovyMarkupView();
|
||||
view.setApplicationContext(ctx);
|
||||
view.setUrl(viewUrl);
|
||||
view.setApplicationContext(ctx);
|
||||
view.afterPropertiesSet();
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
public class TestTemplateEngine extends MarkupTemplateEngine {
|
||||
|
||||
public TestTemplateEngine() {
|
||||
@@ -197,11 +187,12 @@ public class GroovyMarkupViewTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Template createTemplate(Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException {
|
||||
public Template createTemplate(Reader reader) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class GroovyMarkupConfiguration {
|
||||
|
||||
@@ -212,4 +203,5 @@ public class GroovyMarkupViewTests {
|
||||
return configurer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user