FileDocCategorySizeDatePackage
TestLoginFilter.javaAPI DocExample3619Thu Dec 15 22:18:04 GMT 2005com.oreilly.jent.people.servlet

TestLoginFilter

public class TestLoginFilter extends org.apache.cactus.FilterTestCase
In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Java Enterprise in a Nutshell, Third Edition, by Jim Farley and William Crawford with Prakash Malani, John G. Norman, and Justin Gehtland. Copyright 2006 O'Reilly Media, Inc., 0-596-10142-2." If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com.

Fields Summary
private LoginFilter
mFilter
An instance of the filter under test
Constructors Summary
public TestLoginFilter()
Default constructor


       
      
        super();
    
public TestLoginFilter(String arg0)
Constructor with test name

        super(arg0);
    
public TestLoginFilter(String arg0, Test arg1)
Constructor used to wrap a test with a Cactus test

        super(arg0, arg1);
    
Methods Summary
public voidendLoginRedirect(org.apache.cactus.WebResponse response)

        // The response should contain an HTTP "MOVED TEMPORARILY" 
        // status with a redirect
        assertEquals("Unexpected status code seen in response",
                     response.getStatusCode(),
                     HttpServletResponse.SC_MOVED_TEMPORARILY);
    
public voidsetUp()

        mFilter = new LoginFilter();
        try {
            mFilter.init(this.config);
        }
        catch (ServletException se) {
            fail("Unexpected servlet exception: " + se.getMessage());
        }
    
public voidtearDown()

        mFilter.destroy();
        mFilter = null;
    
public voidtestLoginRedirect()
Ensure that the filter performs a redirect when no authentication credentials are present in the user session, and no login username or password are provided as request parameters.

        // Ensure that the user session is clear of our authentication
        // credentials
        HttpSession session = this.request.getSession();
        if (session != null) {
            session.removeAttribute(LoginFilter.AUTHN_ID_VAR);
        }
        try {
            // Invoke the filter
            mFilter.doFilter(this.request, this.response, this.filterChain);
        }
        catch (IOException ioe) {
            fail("Unexpected I/O exception while invoking filter: "
                 + ioe.getMessage());
        }
        catch (ServletException se) {
            fail("Unexpected servlet exception while invoking filter: "
                 + se.getMessage());
        }