* @throws IOException If something goes wrong.
* @throws TemplateException If something goes wrong.
*/
@Test
public void testExecute() throws TemplateException, IOException {
InsertTemplateModel tModel = createMock(InsertTemplateModel.class);
InsertTemplateFMModel fmModel = new InsertTemplateFMModel(tModel);
TilesContainer container = createMock(TilesContainer.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
expect(request.getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME)).andReturn(null).times(2);
request.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
expectLastCall().times(2);
request.setAttribute(ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
replay(request);
HttpRequestHashModel requestModel = new HttpRequestHashModel(request, objectWrapper);
GenericServlet servlet = createMock(GenericServlet.class);
ServletContext servletContext = createMock(ServletContext.class);
expect(servlet.getServletContext()).andReturn(servletContext).times(CALL_COUNT);
expect(servletContext.getAttribute(TilesAccess.CONTAINER_ATTRIBUTE)).andReturn(container).times(2);
replay(servlet, servletContext);
ServletContextHashModel servletContextModel = new ServletContextHashModel(servlet, objectWrapper);
expect(model.get(FreemarkerServlet.KEY_REQUEST)).andReturn(requestModel).times(CALL_COUNT);
expect(model.get(FreemarkerServlet.KEY_APPLICATION)).andReturn(servletContextModel).times(2);
initEnvironment();
TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class);
Map<String, Object> params = new HashMap<String, Object>();
Attribute attribute = createMock(Attribute.class);
params.put("template", objectWrapper.wrap("myTemplate"));
params.put("templateType", objectWrapper.wrap("myTemplateType"));
params.put("templateExpression", objectWrapper.wrap("myTemplateExpression"));
params.put("role", objectWrapper.wrap("myRole"));
params.put("preparer", objectWrapper.wrap("myPreparer"));
tModel.start(container, env);
tModel.end(container, "myTemplate", "myTemplateType",
"myTemplateExpression", "myRole",
"myPreparer", env);
body.render(isA(NullWriter.class));
replay(tModel, body, container, attribute);