Search in sources :

Example 1 with MockFilterChain

use of com.mockrunner.mock.web.MockFilterChain in project pentaho-platform by pentaho.

the class PentahoAwareCharacterEncodingFilterTest method doFilter_ignoreFlagIsSet.

@Test
public void doFilter_ignoreFlagIsSet() throws Exception {
    filterConfig.addInitParameter("ignore", Boolean.TRUE.toString());
    filter.init(filterConfig);
    filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
    assertEquals(NEW_ENCODING, request.getCharacterEncoding());
}
Also used : MockFilterChain(com.mockrunner.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 2 with MockFilterChain

use of com.mockrunner.mock.web.MockFilterChain in project pentaho-platform by pentaho.

the class PentahoAwareCharacterEncodingFilterTest method doFilter_ignoreFlagIsCleared_requestEncodingNotNull.

@Test
public void doFilter_ignoreFlagIsCleared_requestEncodingNotNull() throws Exception {
    filterConfig.addInitParameter("ignore", Boolean.FALSE.toString());
    request.setCharacterEncoding(NEW_ENCODING);
    filter.init(filterConfig);
    filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
    assertEquals(NEW_ENCODING, request.getCharacterEncoding());
}
Also used : MockFilterChain(com.mockrunner.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with MockFilterChain

use of com.mockrunner.mock.web.MockFilterChain in project cayenne by apache.

the class CayenneFilterTest method testDoFilter.

@Test
public void testDoFilter() throws Exception {
    MockFilterConfig config = new MockFilterConfig();
    config.setFilterName("abc");
    config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, CayenneFilter_DispatchModule.class.getName());
    MockServletContext context = new MockServletContext();
    config.setupServletContext(context);
    CayenneFilter filter = new CayenneFilter();
    filter.init(config);
    CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
    CayenneFilter_DispatchRequestHandler handler = (CayenneFilter_DispatchRequestHandler) runtime.getInjector().getInstance(RequestHandler.class);
    assertEquals(0, handler.getStarted());
    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());
}
Also used : MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockFilterChain(com.mockrunner.mock.web.MockFilterChain) MockServletContext(com.mockrunner.mock.web.MockServletContext) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Example 4 with MockFilterChain

use of com.mockrunner.mock.web.MockFilterChain in project pentaho-platform by pentaho.

the class PentahoAwareCharacterEncodingFilterTest method doFilter_ignoreFlagIsCleared_requestEncodingIsNull.

@Test
public void doFilter_ignoreFlagIsCleared_requestEncodingIsNull() throws Exception {
    filterConfig.addInitParameter("ignore", Boolean.FALSE.toString());
    request.setCharacterEncoding(null);
    filter.init(filterConfig);
    filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
    assertEquals(NEW_ENCODING, request.getCharacterEncoding());
}
Also used : MockFilterChain(com.mockrunner.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 5 with MockFilterChain

use of com.mockrunner.mock.web.MockFilterChain in project pentaho-platform by pentaho.

the class PentahoAwareCharacterEncodingFilterTest method doFilter_noEncodingIsProvided.

@Test
public void doFilter_noEncodingIsProvided() throws Exception {
    filterConfig.addInitParameter("ignore", Boolean.FALSE.toString());
    request.setCharacterEncoding(null);
    MockServletContext ctx = (MockServletContext) request.getSession().getServletContext();
    ctx.addInitParameter(PentahoAwareCharacterEncodingFilter.INIT_PARAM_ENCODING, "");
    filter.init(filterConfig);
    filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
    assertEquals(PentahoAwareCharacterEncodingFilter.DEFAULT_CHAR_ENCODING, request.getCharacterEncoding());
}
Also used : MockFilterChain(com.mockrunner.mock.web.MockFilterChain) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockFilterChain (com.mockrunner.mock.web.MockFilterChain)5 Test (org.junit.Test)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 MockFilterConfig (com.mockrunner.mock.web.MockFilterConfig)1 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)1 MockServletContext (com.mockrunner.mock.web.MockServletContext)1 CayenneRuntime (org.apache.cayenne.configuration.CayenneRuntime)1 MockServletContext (org.springframework.mock.web.MockServletContext)1