@Test public void renderTemplate() throws Exception { Map<String, Object> model = new HashMap<>(); model.put("title", "Layout example"); model.put("body", "This is the body"); String url = "org/springframework/web/servlet/view/script/nashorn/template.html"; MockHttpServletResponse response = render(url, model, ScriptTemplatingConfiguration.class); assertEquals("<html><head><title>Layout example</title></head><body><p>This is the body</p></body></html>", response.getContentAsString()); }
private MockHttpServletResponse render(String viewUrl, Map<String, Object> model, Class<?> configuration) throws Exception { ScriptTemplateView view = createViewWithUrl(viewUrl, configuration); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); view.renderMergedOutputModel(model, request, response); return response; }
@Test // SPR-13453 public void renderTemplateWithUrl() throws Exception { String url = "org/springframework/web/servlet/view/script/nashorn/template.html"; MockHttpServletResponse response = render(url, null, ScriptTemplatingWithUrlConfiguration.class); assertEquals("<html><head><title>Check url parameter</title></head><body><p>" + url + "</p></body></html>", response.getContentAsString()); }