package examples;
import servletunit.struts.MockStrutsTestCase;

public class TestLoginAction extends MockStrutsTestCase {

    public TestLoginAction(String testName) {
        super(testName);
    }

    public void setUp() throws Exception {
        super.setUp();
        setInitParameter("validating","false");
    }

    public void testSuccessfulLogin() {

        addRequestParameter("username","deryl");
        addRequestParameter("password","radar");
        setRequestPathInfo("/login");
        actionPerform();
        verifyForward("success");
        verifyForwardPath("/main/success.jsp");
        assertEquals("deryl",getSession().getAttribute("authentication"));
        verifyNoActionErrors();
    }

    public void testFailedLogin() {

        addRequestParameter("username","deryl");
        addRequestParameter("password","express");
        setRequestPathInfo("/login");
        actionPerform();
        verifyForward("login");
        verifyForwardPath("/login/login.jsp");
        verifyInputForward();
        verifyActionErrors(new String[] {"error.password.mismatch"});
        assertNull(getSession().getAttribute("authentication"));
    }

}

