Package org.apache.tiles.request.servlet

Examples of org.apache.tiles.request.servlet.ServletRequest


        ServletContext context = ServletActionContext.getServletContext();
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();

        ApplicationContext applicationContext = ServletUtil.getApplicationContext(context);
        ServletRequest servletRequest = new ServletRequest(applicationContext, request, response);

        TilesContainer container = initTilesContainer(applicationContext, servletRequest);

        container.startContext(servletRequest);
        container.render(location, servletRequest);
View Full Code Here


        ApplicationContext applicationContext = createMock(ApplicationContext.class);

        replay(velocityContext, httpRequest, response, applicationContext);
        context = VelocityRequest.createVelocityRequest(applicationContext,
                httpRequest, response, velocityContext, writer);
        ServletRequest servletRequest = (ServletRequest) context.getWrappedRequest();
        assertEquals(httpRequest, servletRequest.getRequest());
        assertEquals(response, servletRequest.getResponse());
        verify(velocityContext, httpRequest, response, applicationContext);
    }
View Full Code Here

     * @throws IOException If something goes wrong.
     */
    @Test
    public void testRender() throws IOException {
        VelocityView view = createMock(VelocityView.class);
        ServletRequest request = createMock(ServletRequest.class);
        HttpServletRequest httpRequest = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        ViewToolContext context = createMock(ViewToolContext.class);
        Template template = createMock(Template.class);
        Writer writer = createMock(Writer.class);

        expect(request.getRequest()).andReturn(httpRequest);
        expect(request.getResponse()).andReturn(response);
        expect(view.createContext(httpRequest, response)).andReturn(context);
        expect(view.getTemplate("/test.vm")).andReturn(template);
        expect(request.getWriter()).andReturn(writer);
        view.merge(template, context, writer);

        replay(view, request, httpRequest, response, context, template, writer);
        Renderer renderer = new VelocityRenderer(view);
        renderer.render("/test.vm", request);
View Full Code Here

     * @throws ServletException If something goes wrong.
     */
    @Test
    public void testDoInclude() throws IOException, ServletException {
        String path = "this way";
        ServletRequest enclosedRequest = createMock(ServletRequest.class);
        HttpServletRequest servletRequest = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        RequestDispatcher dispatcher = createMock(RequestDispatcher.class);

        expect(servletRequest.getRequestDispatcher("this way")).andReturn(dispatcher);
        dispatcher.include(eq(servletRequest), isA(ExternalWriterHttpServletResponse.class));
        replay(servletRequest, response, dispatcher);

        expect(enclosedRequest.getRequest()).andReturn(servletRequest);
        expect(enclosedRequest.getResponse()).andReturn(response);
        expect(enclosedRequest.getAvailableScopes()).andReturn(Collections.singletonList("parent"));

        replay(velocityContext, enclosedRequest);
        context = new VelocityRequest(enclosedRequest, velocityContext, writer);
        context.doInclude(path);
        verify(velocityContext, enclosedRequest, servletRequest, response, dispatcher);
View Full Code Here

     * @throws IOException If something goes wrong.
     */
    @Test(expected = CannotRenderException.class)
    public void testRenderException() throws IOException {
        VelocityView view = createMock(VelocityView.class);
        ServletRequest request = createMock(ServletRequest.class);

        replay(view, request);
        Renderer renderer = new VelocityRenderer(view);
        try {
            renderer.render(null, request);
View Full Code Here

     * @throws IOException If something goes wrong.
     */
    @Test(expected = IOException.class)
    public void testDoIncludeNoRequestDispatcher() throws IOException {
        String path = "this way";
        ServletRequest enclosedRequest = createMock(ServletRequest.class);
        HttpServletRequest servletRequest = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);

        expect(servletRequest.getRequestDispatcher("this way")).andReturn(null);
        replay(servletRequest, response);

        expect(enclosedRequest.getRequest()).andReturn(servletRequest);
        expect(enclosedRequest.getResponse()).andReturn(response);
        expect(enclosedRequest.getAvailableScopes()).andReturn(Collections.singletonList("parent"));

        replay(velocityContext, enclosedRequest);
        context = new VelocityRequest(enclosedRequest, velocityContext, writer);
        context.doInclude(path);
        verify(velocityContext, enclosedRequest, servletRequest, response);
View Full Code Here

     * @throws ServletException If something goes wrong.
     */
    @Test(expected = IOException.class)
    public void testDoIncludeServletException() throws IOException, ServletException {
        String path = "this way";
        ServletRequest enclosedRequest = createMock(ServletRequest.class);
        HttpServletRequest servletRequest = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        RequestDispatcher dispatcher = createMock(RequestDispatcher.class);

        expect(servletRequest.getRequestDispatcher("this way")).andReturn(dispatcher);
        dispatcher.include(eq(servletRequest), isA(ExternalWriterHttpServletResponse.class));
        expectLastCall().andThrow(new ServletException());
        replay(servletRequest, response, dispatcher);

        expect(enclosedRequest.getRequest()).andReturn(servletRequest);
        expect(enclosedRequest.getResponse()).andReturn(response);
        expect(enclosedRequest.getAvailableScopes()).andReturn(Collections.singletonList("parent"));

        replay(velocityContext, enclosedRequest);
        context = new VelocityRequest(enclosedRequest, velocityContext, writer);
        context.doInclude(path);
        verify(velocityContext, enclosedRequest, servletRequest, response, dispatcher);
View Full Code Here

     * @param applicationContext The application context.
     * @param pageContext The page context.
     * @return A new JSP request.
     */
    public static JspRequest createServletJspRequest(ApplicationContext applicationContext, PageContext pageContext) {
        return new JspRequest(new ServletRequest(
                applicationContext, (HttpServletRequest) pageContext
                        .getRequest(), (HttpServletResponse) pageContext
                        .getResponse()), pageContext);
    }
View Full Code Here

        expect(context.getRequest()).andReturn(servletRequest);
        expect(context.getResponse()).andReturn(servletResponse);

        replay(context, applicationContext, servletRequest, servletResponse);
        JspRequest request = JspRequest.createServletJspRequest(applicationContext, context);
        ServletRequest wrappedRequest = (ServletRequest) request.getWrappedRequest();
        assertEquals(servletRequest, wrappedRequest.getRequest());
        assertEquals(servletResponse, wrappedRequest.getResponse());
        verify(context, applicationContext, servletRequest, servletResponse);
    }
View Full Code Here

                .setParameter("ContentType", "text/html")
                .setParameter("template_update_delay", "0")
                .setParameter("default_encoding", "ISO-8859-1")
                .setParameter("number_format", "0.##########").build();

        ServletRequest request = createMock(ServletRequest.class);
        HttpServletRequest httpRequest = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        HttpRequestHashModel requestModel = new HttpRequestHashModel(httpRequest, response, objectWrapper);
        HttpRequestParametersHashModel parametersModel = new HttpRequestParametersHashModel(httpRequest);

        expect(request.getRequest()).andReturn(httpRequest);
        expect(request.getResponse()).andReturn(response);
        expect(request.getPrintWriter()).andReturn(printWriter);
        expect(httpRequest.getSession(false)).andReturn(null);
        expect(httpRequest.getAttribute(ATTR_REQUEST_MODEL)).andReturn(requestModel);
        expect(httpRequest.getAttribute(ATTR_REQUEST_PARAMETERS_MODEL)).andReturn(parametersModel);
        response.setContentType("text/html; charset=ISO-8859-1");
        response.setHeader(eq("Cache-Control"), isA(String.class));
View Full Code Here

TOP

Related Classes of org.apache.tiles.request.servlet.ServletRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.