Package com.mockrunner.mock.web

Examples of com.mockrunner.mock.web.MockFilterChain


        assertEquals(0, handler.getEnded());

        filter.doFilter(
                new MockHttpServletRequest(),
                new MockHttpServletResponse(),
                new MockFilterChain());
        assertEquals(1, handler.getStarted());
        assertEquals(1, handler.getEnded());

        filter.doFilter(
                new MockHttpServletRequest(),
                new MockHttpServletResponse(),
                new MockFilterChain());
        assertEquals(2, handler.getStarted());
        assertEquals(2, handler.getEnded());
    }
View Full Code Here


       
    MockHttpServletRequest request   = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    SecurityContextHolder.setContext(new SecurityContextImpl());
    request.addCookie(new Cookie("__ac", generateCookie("cdwinslow")));
    testFilter.doFilter(request, response, new MockFilterChain());
    assertEquals(
        SecurityContextHolder.getContext()
        .getAuthentication()
        .getPrincipal()
        .toString(),
View Full Code Here

     MockHttpServletRequest request = new MockHttpServletRequest();
     MockHttpServletResponse response = new MockHttpServletResponse();
     request.addCookie(new Cookie("__ac", "this is an invalid cookie"));
    
     SecurityContextHolder.setContext(new SecurityContextImpl());
     testFilter.doFilter(request, response, new MockFilterChain());
    
     assertNull(SecurityContextHolder.getContext().getAuthentication());
    
    
  }
View Full Code Here

        req.setScheme(url.getProtocol());
        req.setServerPort(url.getPort() == -1 ? 80 : url.getPort());
        req.setContextPath(url.getPath());

        MockHttpServletResponse res = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain();
        MockHttpSession session = new MockHttpSession();
        req.setSession(session);

        MockServletContext servletContext = new MockServletContext();
        session.setupServletContext(servletContext);

        filter.init(config);

        // the servlet to call at the end of the chain, just writes the provided content out
        // to the response
        Servlet servlet = new HttpServlet() {
            public void service(ServletRequest req, ServletResponse res) throws ServletException,
                    IOException {
                res.setContentType(contentType);
                PrintWriter writer = res.getWriter();
                BufferedReader reader = new BufferedReader(new StringReader(content));
                String line;
                while ((line = reader.readLine()) != null) {
                    writer.println(line);
                }
                writer.flush();
            }
        };
        chain.setServlet(servlet);
        filter.doFilter(req, res, chain);

        String result = res.getOutputStreamContent();
        return result;
    }
View Full Code Here

        assertEquals(0, handler.getEnded());

        filter.doFilter(
                new MockHttpServletRequest(),
                new MockHttpServletResponse(),
                new MockFilterChain());
        assertEquals(1, handler.getStarted());
        assertEquals(1, handler.getEnded());

        filter.doFilter(
                new MockHttpServletRequest(),
                new MockHttpServletResponse(),
                new MockFilterChain());
        assertEquals(2, handler.getStarted());
        assertEquals(2, handler.getEnded());
    }
View Full Code Here

        HttpSession session = new MockHttpSession();
        session.setAttribute(ServletUtil.DATA_CONTEXT_KEY, dataContext);
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setSession(session);
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain();

        TestFilter testFilter = new TestFilter();

        chain.addFilter(filter);
        chain.addFilter(testFilter);

        // check no thread DC before
        try {
            DataContext.getThreadDataContext();
            fail("There is a DataContext bound to thread already.");
        }
        catch (IllegalStateException ex) {
            // expected
        }

        chain.doFilter(request, response);

        assertSame(dataContext, testFilter.threadContext);

        // check no thread DC after
        try {
View Full Code Here

        assertEquals(0, handler.getEnded());

        filter.doFilter(
                new MockHttpServletRequest(),
                new MockHttpServletResponse(),
                new MockFilterChain());
        assertEquals(1, handler.getStarted());
        assertEquals(1, handler.getEnded());

        filter.doFilter(
                new MockHttpServletRequest(),
                new MockHttpServletResponse(),
                new MockFilterChain());
        assertEquals(2, handler.getStarted());
        assertEquals(2, handler.getEnded());
    }
View Full Code Here

    public void testSimple() throws Exception {
        DummyMonitorDAO dao = new DummyMonitorDAO();
       
        MonitorFilter filter = new MonitorFilter(new Monitor(dao), new MonitorRequestFilter());
       
        MockFilterChain chain = new MockFilterChain();
      
        HttpServletRequest req = request("GET", "/foo/bar", "12.34.56.78", null);
        filter.doFilter(req, response(), chain);
     
        RequestData data = dao.getLast();
        assertEquals("GET", data.getHttpMethod());
        assertEquals("/foo/bar", data.getPath());
        assertEquals("12.34.56.78", data.getRemoteAddr());
       
        chain.setServlet(new HttpServlet() {
            @Override
            public void service(ServletRequest req, ServletResponse res) throws ServletException,
                    IOException {
                req.getInputStream().read(new byte[10]);
                res.getOutputStream().write("hello".getBytes());
View Full Code Here

       
        dispatcher.setContextConfigLocation(GeoServerAbstractTestSupport.class.getResource("dispatcher-servlet.xml").toString());
        dispatcher.init(config);
       
        // build a filter chain so that we can test with filters as well
        MockFilterChain chain = new MockFilterChain();
        List<Filter> filters = getFilters();
        if(filters != null) {
            for (Filter filter : filters) {
                chain.addFilter(filter);
            }
        }
        chain.setServlet(new HttpServlet() {
            @Override
            protected void service(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {
                try {
                    //excute the pre handler step
                    Collection interceptors =
                        GeoServerExtensions.extensions(HandlerInterceptor.class, applicationContext );
                    for ( Iterator i = interceptors.iterator(); i.hasNext(); ) {
                        HandlerInterceptor interceptor = (HandlerInterceptor) i.next();
                        interceptor.preHandle( request, response, dispatcher );
                    }
                   
                    //execute
                    //dispatcher.handleRequest( request, response );
                    dispatcher.service(request, response);
                   
                    //execute the post handler step
                    for ( Iterator i = interceptors.iterator(); i.hasNext(); ) {
                        HandlerInterceptor interceptor = (HandlerInterceptor) i.next();
                        interceptor.postHandle( request, response, dispatcher, null );
                    }
                } catch(RuntimeException e) {
                    throw e;
                } catch(IOException e) {
                    throw e;
                } catch(ServletException e) {
                    throw e;
                } catch(Exception e) {
                    throw (IOException) new IOException("Failed to handle the request").initCause(e);
                }
            }
        });
       
        chain.doFilter(request, response);
       
    }
View Full Code Here

        req.setScheme(url.getProtocol());
        req.setServerPort(url.getPort() == -1 ? 80 : url.getPort());
        req.setContextPath(url.getPath());

        MockHttpServletResponse res = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain();
        MockHttpSession session = new MockHttpSession();
        req.setSession(session);

        MockServletContext servletContext = new MockServletContext();
        session.setupServletContext(servletContext);

        filter.init(config);

        // the servlet to call at the end of the chain, just writes the provided content out
        // to the response
        Servlet servlet = new HttpServlet() {
            public void service(ServletRequest req, ServletResponse res) throws ServletException,
                    IOException {
                res.setContentType(contentType);
                PrintWriter writer = res.getWriter();
                BufferedReader reader = new BufferedReader(new StringReader(content));
                String line;
                while ((line = reader.readLine()) != null) {
                    writer.println(line);
                }
                writer.flush();
            }
        };
        chain.setServlet(servlet);
        filter.doFilter(req, res, chain);

        String result = res.getOutputStreamContent();
        return result;
    }
View Full Code Here

TOP

Related Classes of com.mockrunner.mock.web.MockFilterChain

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.