Polish FreeMarker macro support in spring-webflux

See gh-23002
This commit is contained in:
Sam Brannen
2019-06-10 16:08:04 +03:00
parent ac28de0dc1
commit 2f640fe205
8 changed files with 234 additions and 130 deletions

View File

@@ -25,7 +25,7 @@ import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.util.UriTemplate;
/**
* Dummy request context used for VTL and FTL macro tests.
* Dummy request context used for FreeMarker macro tests.
*
* @author Darren Davison
* @author Juergen Hoeller
@@ -34,7 +34,7 @@ import org.springframework.web.util.UriTemplate;
*/
public class DummyMacroRequestContext {
private HttpServletRequest request;
private final HttpServletRequest request;
private Map<String, String> messageMap;
@@ -147,14 +147,14 @@ public class DummyMacroRequestContext {
* @see org.springframework.web.servlet.support.RequestContext#getBindStatus(String)
*/
public BindStatus getBindStatus(String path) throws IllegalStateException {
return new BindStatus(new RequestContext(this.request), path, false);
return getBindStatus(path, false);
}
/**
* @see org.springframework.web.servlet.support.RequestContext#getBindStatus(String, boolean)
*/
public BindStatus getBindStatus(String path, boolean htmlEscape) throws IllegalStateException {
return new BindStatus(new RequestContext(this.request), path, true);
return new BindStatus(new RequestContext(this.request), path, htmlEscape);
}
}

View File

@@ -45,7 +45,7 @@ public class FreeMarkerConfigurerTests {
private final FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
@Test
public void freeMarkerConfigurerWithConfigLocation() throws Exception {
public void freeMarkerConfigurerWithConfigLocation() {
freeMarkerConfigurer.setConfigLocation(new FileSystemResource("myprops.properties"));
Properties props = new Properties();
props.setProperty("myprop", "/mydir");

View File

@@ -98,8 +98,7 @@ public class FreeMarkerMacroTests {
protected void processTemplate(Template template, SimpleHash fmModel, HttpServletResponse response)
throws TemplateException {
Map model = fmModel.toMap();
boolean condition = model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext;
assertThat(condition).isTrue();
assertThat(model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)).isInstanceOf(RequestContext.class);
RequestContext rc = (RequestContext) model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
BindStatus status = rc.getBindStatus("tb.name");
assertThat(status.getExpression()).isEqualTo("name");
@@ -136,9 +135,8 @@ public class FreeMarkerMacroTests {
fv.render(model, request, response);
}
catch (Exception ex) {
boolean condition = ex instanceof ServletException;
assertThat(condition).isTrue();
assertThat(ex.getMessage().contains(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)).isTrue();
assertThat(ex).isInstanceOf(ServletException.class);
assertThat(ex.getMessage()).contains(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
}
}
@@ -222,7 +220,7 @@ public class FreeMarkerMacroTests {
assertThat(getMacroOutput("FORM4")).isEqualTo("<textarea id=\"name\" name=\"name\" rows=10 cols=30>\nDarren</textarea>");
}
// TODO verify remaining output (fix whitespace)
// TODO verify remaining output for forms 5, 6, 7, 8, and 14 (fix whitespace)
@Test
public void testForm9() throws Exception {