TestProcessResults.java :  » Testing » StrutsTestCase » servletunit » struts » tests » cactus » Java Open Source

Java Open Source » Testing » StrutsTestCase 
StrutsTestCase » servletunit » struts » tests » cactus » TestProcessResults.java
package servletunit.struts.tests.cactus;

import servletunit.struts.CactusStrutsTestCase;
import org.apache.cactus.WebResponse;

public class TestProcessResults extends CactusStrutsTestCase {

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

    public void endSuccessfulLogin(WebResponse response) {
        assertEquals("unexpected response code",200,response.getStatusCode());
        String[] text = response.getTextAsArray();
        for (int i = 0; i < text.length; i++) {
            String line = text[i];
            if (line != null && 
                    !line.equals("<h2>You have successfully logged in!</h2>") &&
                    !line.equals("<a href=\"/test/login/login.jsp\">Go back</a>") &&
                    !line.equals(""))
                fail("unexpected text: " + line);

        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.