KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > struts > tests > cactus > TestAbsolutePath


1 // StrutsTestCase - a JUnit extension for testing Struts actions
2
// within the context of the ActionServlet.
3
// Copyright (C) 2002 Deryl Seale
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the Apache Software License as
7
// published by the Apache Software Foundation; either version 1.1
8
// of the License, or (at your option) any later version.
9
//
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.cactus;
18
19 import servletunit.struts.CactusStrutsTestCase;
20 import org.apache.cactus.WebRequest;
21
22 import javax.servlet.http.Cookie JavaDoc;
23
24 public class TestAbsolutePath extends CactusStrutsTestCase {
25
26     static final String JavaDoc COOKIE_NAME = "config_file";
27
28     public TestAbsolutePath(String JavaDoc 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 JavaDoc 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 JavaDoc getCookieValue (Cookie JavaDoc[] cookies, String JavaDoc name) {
52         String JavaDoc 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 JavaDoc[] args) {
67         junit.textui.TestRunner.run(TestAbsolutePath.class);
68     }
69
70
71 }
72
73
Popular Tags