@Test
  public void testDoFilterOk() throws IOException, ServletException {
    req.setRequestURI("/img/blub.jpg");
    me.doFilter(req, resp, chain);

    assertEquals(req, chain.getLastRequest());
    assertEquals(resp, chain.getLastResponse());
  }
  @SuppressWarnings("unchecked")
  @Test
  public void testDoFilterRedirectLogin() throws IOException, ServletException {
    req.setRequestURI("/admin/bla.jsp");
    me.doFilter(req, resp, chain);

    assertNull(chain.getLastRequest());
    assertNull(chain.getLastResponse());

    assertFalse(resp.wasRedirectSent());
    Map<String, MockRequestDispatcher> m = req.getRequestDispatcherMap();
    assertEquals("/login.jsp", m.get(m.keySet().iterator().next()).getPath());
  }
  @Before
  public void setUp() throws Exception {
    ctx = new MockServletContext();
    ctx.setInitParameter("security-config", "/WEB-INF/security-config.xml");
    ctx.setResourceAsStream(
        "/WEB-INF/security-config.xml", SecConfigTest.getSecurityConfigInputStream());

    MockFilterConfig conf = new MockFilterConfig();
    conf.setupServletContext(ctx);

    req = new MockHttpServletRequest();
    req.setContextPath("contextPath/");

    resp = new MockHttpServletResponse();
    chain = new MockFilterChain();

    me = new SecFilter();
    me.init(conf);
  }
  @SuppressWarnings("unchecked")
  @Test
  public void testDoFilterRedirectDeny() throws IOException, ServletException {
    req.setRequestURI("/admin/bla.jsp");

    // getSession() returns null otherwise - violation of the spec
    req.setSession(new MockHttpSession());

    SessionToken tok = new SessionToken("login", 1234, false);
    SecManager.getInstance(ctx).setSessionToken(req, tok);

    me.doFilter(req, resp, chain);

    assertNull(chain.getLastRequest());
    assertNull(chain.getLastResponse());

    assertFalse(resp.wasRedirectSent());
    Map<String, MockRequestDispatcher> m = req.getRequestDispatcherMap();
    assertEquals("/deny.do", m.get(m.keySet().iterator().next()).getPath());
  }
 /**
  * Initializes a newly created {@link SecFilterMapping} object which associates the {@link
  * SecFilter} to the specified URL pattern.
  *
  * <p>The filter is mapped to the {@link SecFilter}'s canonical class name.
  *
  * @param url the URL pattern which the {@link SecFilter} is mapped to
  * @param filter the {@link SecFilter} to be mapped to the specified URL pattern
  * @since 1.0
  */
 public DefaultSecFilterMapping(String url, SecFilter filter) {
   this(url, filter.getFilterName());
 }
 @Test
 public void testDestroy() {
   me.destroy();
 }