VelocityAutotagRuntime extends Directive implements AutotagRuntime<Request> { @Override public Request createRequest() { ViewContext viewContext = (ViewContext) context.getInternalUserContext(); HttpServletRequest request = viewContext.getRequest(); HttpServletResponse response = viewContext.getResponse(); ServletContext servletContext = viewContext.getServletContext(); return VelocityRequest.createVelocityRequest(ServletUtil.getApplicationContext(servletContext), request, response, context, writer); }  @Override Request createRequest(); @Override ModelBody createModelBody(); @Override @SuppressWarnings("unchecked") T getParameter(String name, Class<T> type, T defaultValue); @Override String getName(); @Override int getType(); @Override boolean render(InternalContextAdapter context, Writer writer, Node node);  }
@Test public void testCreateRequest() { InternalContextAdapter context = createMock(InternalContextAdapter.class); Writer writer = createMock(Writer.class); Node node = createMock(Node.class); ViewToolContext viewContext = createMock(ViewToolContext.class); HttpServletRequest request = createMock(HttpServletRequest.class); HttpServletResponse response = createMock(HttpServletResponse.class); ServletContext servletContext = createMock(ServletContext.class); ApplicationContext applicationContext = createMock(ApplicationContext.class); expect(context.getInternalUserContext()).andReturn(viewContext); expect(viewContext.getRequest()).andReturn(request); expect(viewContext.getResponse()).andReturn(response); expect(viewContext.getServletContext()).andReturn(servletContext); expect(servletContext.getAttribute(ApplicationAccess.APPLICATION_CONTEXT_ATTRIBUTE)).andReturn(applicationContext); replay(context, writer, node, viewContext, request, response, servletContext, applicationContext); VelocityAutotagRuntime runtime = new VelocityAutotagRuntime(); runtime.render(context, writer, node); Request velocityRequest = runtime.createRequest(); assertTrue(velocityRequest instanceof VelocityRequest); verify(context, writer, node, viewContext, request, response, servletContext, applicationContext); }