KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > navigation > F_JonasAdminLogout


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_JonasAdminLogout.java,v 1.4 2005/07/12 13:20:01 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.navigation;
27
28 import junit.framework.TestSuite;
29
30 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
31 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
32
33 import com.meterware.httpunit.HttpUnitOptions;
34 import com.meterware.httpunit.WebConversation;
35 import com.meterware.httpunit.WebLink;
36 import com.meterware.httpunit.WebResponse;
37
38 /**
39  * Class to test jonasAdmin log out
40  * @author kemlerp
41  *
42  */

43 public class F_JonasAdminLogout extends JonasAdminTestCase {
44
45     /**
46      * URL of log out
47      */

48     private static final String JavaDoc URL_JONASADMIN_LOGOUT = "logOut.do";
49
50     /**
51      * Constructor with a specified name
52      * @param s name
53      */

54     public F_JonasAdminLogout(String JavaDoc s) {
55         super(s, URL_JONASADMIN);
56     }
57
58     /**
59      * Constructor with a specified name
60      * @param wc the WebConversation of the suite test
61      * @param s name
62      */

63     public F_JonasAdminLogout(WebConversation wc, String JavaDoc s) {
64         super(wc, s, URL_JONASADMIN);
65     }
66
67     /**
68      * Main method
69      * @param args the arguments
70      */

71     public static void main(String JavaDoc[] args) {
72
73         String JavaDoc testtorun = null;
74         // Get args
75
for (int argn = 0; argn < args.length; argn++) {
76             String JavaDoc sArg = args[argn];
77             if (sArg.equals("-n")) {
78                 testtorun = args[++argn];
79             }
80         }
81         if (testtorun == null) {
82             junit.textui.TestRunner.run(suite());
83         } else {
84             junit.textui.TestRunner.run(new F_JonasAdminLogout(testtorun));
85         }
86     }
87
88     /**
89      * Get a new TestSuite for this class
90      * @return a new TestSuite for this class
91      */

92     public static TestSuite suite() {
93         return new TestSuite(F_JonasAdminLogout.class);
94     }
95
96     /**
97      * Get a new TestSuite for this class
98      * @param wc the WebConversation
99      * @return a new TestSuite for this class with the WebConversation instance
100      */

101     public static TestSuite suite(WebConversation wc) {
102         TestSuite suite = new TestSuite();
103         suite.addTest(new F_JonasAdminLogout(wc, "testLogout"));
104         return suite;
105     }
106
107     /**
108      * Setup need for these tests
109      * jonasAdmin is required
110      * @throws Exception if it fails
111      */

112     protected void setUp() throws Exception JavaDoc {
113         super.setUp();
114
115         if (wc.getCurrentPage().getURL() == null) {
116             useWar("jonasAdmin");
117             // login to jonas admin
118
try {
119                 JonasAdminAuth.doValidAuth(wc, url);
120             } catch (Exception JavaDoc e) {
121                 fail("authentification failed : " + e);
122             }
123         } else {
124             // if there was an error, the connection must be restablished
125
try {
126                 wc.getFrameContents(FRAME_TREE);
127             } catch (Exception JavaDoc e) {
128                 wc.getResponse(urlLogOut);
129                 // login to jonas admin
130
try {
131                     JonasAdminAuth.doValidAuth(wc, url);
132                 } catch (Exception JavaDoc auth) {
133                     fail("authentification failed : " + auth);
134                 }
135             }
136         }
137     }
138
139     /**
140      *
141      * @throws Exception if error occurs
142      *
143      */

144     public void testLogout() throws Exception JavaDoc {
145
146         WebResponse wr;
147         WebResponse topFrame;
148         WebLink link;
149
150         // Disable errors of javascript
151
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
152         // Disable exception thrown on error status
153
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
154
155         // Get the frame "top"
156
topFrame = wc.getFrameContents(FRAME_TOP);
157
158         link = topFrame.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_LOGOUT);
159         wr = link.click();
160
161         assertTrue("It is not the login page. ", wr.getText().indexOf("login.jsp") != -1);
162         try {
163             wc.getFrameContents(FRAME_TREE);
164             fail("There is tree frame. ");
165         } catch (Exception JavaDoc e){
166             // It is OK
167
}
168
169
170         // Go to Welcome.do
171
wc.getResponse(getAbsoluteUrl(URL_JONASADMIN + "/Welcome.do"));
172
173         // login to jonas admin
174
try {
175             JonasAdminAuth.doValidAuth(wc, url);
176         } catch (Exception JavaDoc e) {
177             fail("authentification failed : " + e);
178         }
179
180         try {
181             assertNotNull("There is not tree frame. ", wc.getFrameContents(FRAME_TREE));
182         } catch (Exception JavaDoc e) {
183             fail("There is not tree frame. ");
184         }
185     }
186 }
Popular Tags