* @throws IOException If something goes wrong.
* @throws TemplateException If something goes wrong.
*/
@Test
public void testExecute() throws TemplateException, IOException {
DefinitionModel tModel = createMock(DefinitionModel.class);
DefinitionFMModel fmModel = new DefinitionFMModel(tModel);
MutableTilesContainer container = createMock(MutableTilesContainer.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
ArrayStack<Object> composeStack = new ArrayStack<Object>();
expect(request.getAttribute(FreeMarkerUtil.COMPOSE_STACK_ATTRIBUTE_NAME)).andReturn(composeStack).times(2);
expect(request.getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME)).andReturn(null);
request.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
replay(request);
HttpRequestHashModel requestModel = new HttpRequestHashModel(request, objectWrapper);
GenericServlet servlet = createMock(GenericServlet.class);
ServletContext servletContext = createMock(ServletContext.class);
expect(servlet.getServletContext()).andReturn(servletContext).times(2);
expect(servletContext.getAttribute(TilesAccess.CONTAINER_ATTRIBUTE)).andReturn(container);
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);
initEnvironment();
TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class);
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", objectWrapper.wrap("myName"));
params.put("template", objectWrapper.wrap("myTemplate"));
params.put("role", objectWrapper.wrap("myRole"));
params.put("extends", objectWrapper.wrap("myExtends"));
params.put("preparer", objectWrapper.wrap("myPreparer"));
tModel.start(composeStack, "myName", "myTemplate", "myRole", "myExtends", "myPreparer");
tModel.end(container, composeStack, env);
body.render(isA(NullWriter.class));
replay(tModel, body, container);
fmModel.execute(env, params, null, body);
verify(template, model, request, tModel, body, container, servlet, servletContext);