use of org.springframework.web.reactive.result.view.BindStatus in project spring-framework by spring-projects.
the class FreeMarkerMacroTests method springMacroRequestContextIsAutomaticallyExposedAsModelAttribute.
@Test
public void springMacroRequestContextIsAutomaticallyExposedAsModelAttribute() throws Exception {
storeTemplateInTempDir("<@spring.bind \"testBean.name\"/>\nHi ${spring.status.value}");
FreeMarkerView view = new FreeMarkerView() {
@Override
protected Mono<Void> renderInternal(Map<String, Object> renderAttributes, MediaType contentType, ServerWebExchange exchange) {
Object value = renderAttributes.get(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
assertThat(value).isInstanceOf(RequestContext.class);
BindStatus status = ((RequestContext) value).getBindStatus("testBean.name");
assertThat(status.getExpression()).isEqualTo("name");
assertThat(status.getValue()).isEqualTo("Dilbert");
return super.renderInternal(renderAttributes, contentType, exchange);
}
};
view.setApplicationContext(this.applicationContext);
view.setBeanName("myView");
view.setUrl("tmp.ftl");
view.setConfiguration(this.freeMarkerConfig);
view.render(singletonMap("testBean", new TestBean("Dilbert", 99)), null, this.exchange).subscribe();
assertThat(getOutput()).containsExactly("Hi Dilbert");
}
Aggregations