01: // StrutsTestCase - a JUnit extension for testing Struts actions
02: // within the context of the ActionServlet.
03: // Copyright (C) 2002 Deryl Seale
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the Apache Software License as
07: // published by the Apache Software Foundation; either version 1.1
08: // of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: // Apache Software Foundation Licens for more details.
14: //
15: // You may view the full text here: http://www.apache.org/LICENSE.txt
16:
17: package servletunit.struts.tests;
18:
19: import servletunit.struts.MockStrutsTestCase;
20: import servletunit.ServletContextSimulator;
21:
22: import java.io.File;
23:
24: public class TestAbsolutePath extends MockStrutsTestCase {
25:
26: String rootPath;
27:
28: public TestAbsolutePath(String testName) {
29: super (testName);
30: }
31:
32: public void setUp() throws Exception {
33: super .setUp();
34: rootPath = System.getProperty("basedir");
35: setServletConfigFile(rootPath + "/src/examples/WEB-INF/web.xml");
36: }
37:
38: public void testSuccessfulLogin() {
39: setConfigFile(rootPath
40: + "/src/examples/WEB-INF/struts-config.xml");
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(
48: "authentication"));
49: verifyNoActionErrors();
50: }
51:
52: public void testContextDirectory() {
53: this .setContextDirectory(new File(rootPath + "/src/examples"));
54: setConfigFile("/WEB-INF/struts-config.xml");
55: addRequestParameter("username", "deryl");
56: addRequestParameter("password", "radar");
57: setRequestPathInfo("/login");
58: actionPerform();
59: verifyForward("success");
60: verifyForwardPath("/main/success.jsp");
61: assertEquals("deryl", getSession().getAttribute(
62: "authentication"));
63: verifyNoActionErrors();
64: }
65:
66: public static void main(String[] args) {
67: junit.textui.TestRunner.run(TestAbsolutePath.class);
68: }
69:
70: }
|