FileDocCategorySizeDatePackage
TestSecurityFilter.javaAPI DocExample1370Sat Mar 15 19:39:50 GMT 2003com.oreilly.javaxp.cactus.filter

TestSecurityFilter.java

package com.oreilly.javaxp.cactus.filter;

import org.apache.cactus.FilterTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.client.authentication.BasicAuthentication;

/**
 * @author Brian M. Coyner
 * $version $Id: TestSecurityFilter.java,v 1.2 2003/02/27 00:24:43 jepc Exp $
 */
public class TestSecurityFilter extends FilterTestCase {

    private SecurityFilter filter;
    private MockFilterChain mockChain;

    public TestSecurityFilter(String name) {
        super(name);
    }

    public void setUp() {
        this.filter = new SecurityFilter();
        this.mockChain = new MockFilterChain();
    }

    public void beginAuthenticatedUser(WebRequest webRequest) {
        webRequest.setRedirectorName("SecureFilterRedirector");
        webRequest.setAuthentication(
                new BasicAuthentication("coyner_b", "secret"));
    }

    public void testAuthenticatedUser() throws Exception {
        this.mockChain.setExpectedInvocation(true);
        this.filter.doFilter(this.request, this.response, this.mockChain);
        this.mockChain.verify();
    }

    public void testNonAuthenticatedUser() throws Exception {
        this.mockChain.setExpectedInvocation(false);
        this.filter.doFilter(this.request, this.response, this.mockChain);
        this.mockChain.verify();
    }
}