1 17 package servletunit.struts.tests.cactus; 18 19 import servletunit.struts.CactusStrutsTestCase; 20 import org.apache.cactus.WebRequest; 21 22 import javax.servlet.http.Cookie ; 23 24 public class TestAbsolutePath extends CactusStrutsTestCase { 25 26 static final String COOKIE_NAME = "config_file"; 27 28 public TestAbsolutePath(String testName) { 29 super(testName); 30 } 31 32 public void beginSuccessfulLogin(WebRequest theRequest) { 33 if (logger.isDebugEnabled()) 34 logger.debug("setting cookie to " + System.getProperty("basedir") + "/src/examples/WEB-INF/struts-config.xml"); 35 theRequest.addCookie(COOKIE_NAME, System.getProperty("basedir") + "/src/examples/WEB-INF/struts-config.xml"); 36 } 37 38 public void testSuccessfulLogin() { 39 String fileName = getCookieValue(request.getCookies(), COOKIE_NAME); 40 setConfigFile(fileName); 41 addRequestParameter("username","deryl"); 42 addRequestParameter("password","radar"); 43 setRequestPathInfo("/login"); 44 actionPerform(); 45 verifyForward("success"); 46 verifyForwardPath("/main/success.jsp"); 47 assertEquals("deryl",getSession().getAttribute("authentication")); 48 verifyNoActionErrors(); 49 } 50 51 private String getCookieValue (Cookie [] cookies, String name) { 52 String value = null; 53 if (cookies != null) { 54 for (int i = 0; i < cookies.length; i++) { 55 logger.debug ("checking cookie " + cookies[i].getName()); 56 57 if (cookies[i].getName().equals(name)) { 58 value = cookies[i].getValue(); 59 break; 60 } 61 } 62 } 63 return value; 64 } 65 66 public static void main(String [] args) { 67 junit.textui.TestRunner.run(TestAbsolutePath.class); 68 } 69 70 71 } 72 73 | Popular Tags |