private MockServerHttpResponse renderViewWithModel( String viewUrl, Map<String, Object> model, Class<?> configuration) throws Exception { ScriptTemplateView view = createViewWithUrl(viewUrl, configuration); MockServerHttpRequest request = new MockServerHttpRequest(); MockServerHttpResponse response = new MockServerHttpResponse(); WebSessionManager manager = new DefaultWebSessionManager(); ServerWebExchange exchange = new DefaultServerWebExchange(request, response, manager); view.renderInternal(model, MediaType.TEXT_HTML, exchange).block(); return response; }
private ScriptTemplateView createViewWithUrl(String viewUrl, Class<?> configuration) throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(configuration); ctx.refresh(); ScriptTemplateView view = new ScriptTemplateView(); view.setApplicationContext(ctx); view.setUrl(viewUrl); view.afterPropertiesSet(); return view; }