001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_JonasAdminLogout.java 7381 2005-09-14 16:00:02Z kemlerp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jonasadmin.test.navigation;
025:
026: import junit.framework.TestSuite;
027:
028: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
029: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
030:
031: import com.meterware.httpunit.HttpUnitOptions;
032: import com.meterware.httpunit.WebLink;
033: import com.meterware.httpunit.WebResponse;
034:
035: /**
036: * Class to test jonasAdmin log out
037: * @author kemlerp
038: *
039: */
040: public class F_JonasAdminLogout extends JonasAdminTestCase {
041:
042: /**
043: * URL of log out
044: */
045: private static final String URL_JONASADMIN_LOGOUT = "logOut.do";
046:
047: /**
048: * Constructor with a specified name
049: * @param s name
050: */
051: public F_JonasAdminLogout(String s) {
052: super (s, URL_JONASADMIN);
053: }
054:
055: /**
056: * Main method
057: * @param args the arguments
058: */
059: public static void main(String[] args) {
060:
061: String testtorun = null;
062: // Get args
063: for (int argn = 0; argn < args.length; argn++) {
064: String sArg = args[argn];
065: if (sArg.equals("-n")) {
066: testtorun = args[++argn];
067: }
068: }
069: if (testtorun == null) {
070: junit.textui.TestRunner.run(suite());
071: } else {
072: junit.textui.TestRunner.run(new F_JonasAdminLogout(
073: testtorun));
074: }
075: }
076:
077: /**
078: * Get a new TestSuite for this class
079: * @return a new TestSuite for this class
080: */
081: public static TestSuite suite() {
082: return new TestSuite(F_JonasAdminLogout.class);
083: }
084:
085: /**
086: * Setup need for these tests
087: * jonasAdmin is required
088: * @throws Exception if it fails
089: */
090: protected void setUp() throws Exception {
091: super .setUp();
092:
093: if (wc.getCurrentPage().getURL() == null) {
094: useWar("jonasAdmin");
095: // login to jonas admin
096: try {
097: JonasAdminAuth.doValidAuth(wc, url);
098: } catch (Exception e) {
099: fail("authentification failed : " + e);
100: }
101: } else {
102: // if there was an error, the connection must be restablished
103: try {
104: wc.getFrameContents(FRAME_TREE);
105: } catch (Exception e) {
106: wc.getResponse(urlLogOut);
107: // login to jonas admin
108: try {
109: JonasAdminAuth.doValidAuth(wc, url);
110: } catch (Exception auth) {
111: fail("authentification failed : " + auth);
112: }
113: }
114: }
115: }
116:
117: /**
118: *
119: * @throws Exception if error occurs
120: *
121: */
122: public void testLogout() throws Exception {
123:
124: WebResponse wr;
125: WebResponse topFrame;
126: WebLink link;
127:
128: // Disable errors of javascript
129: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
130: // Disable exception thrown on error status
131: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
132:
133: // Get the frame "top"
134: topFrame = wc.getFrameContents(FRAME_TOP);
135:
136: link = topFrame.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
137: URL_JONASADMIN_LOGOUT);
138: wr = link.click();
139:
140: assertTrue("It is not the login page. ", wr.getText().indexOf(
141: "login.jsp") != -1);
142: try {
143: wc.getFrameContents(FRAME_TREE);
144: fail("There is tree frame. ");
145: } catch (Exception e) {
146: // It is OK
147: }
148:
149: // Go to Welcome.do
150: wc.getResponse(getAbsoluteUrl(URL_JONASADMIN + "/Welcome.do"));
151:
152: // login to jonas admin
153: try {
154: JonasAdminAuth.doValidAuth(wc, url);
155: } catch (Exception e) {
156: fail("authentification failed : " + e);
157: }
158:
159: try {
160: assertNotNull("There is not tree frame. ", wc
161: .getFrameContents(FRAME_TREE));
162: } catch (Exception e) {
163: fail("There is not tree frame. ");
164: }
165: }
166:
167: /**
168: * Tear Down cleanUp action
169: * @throws Exception if an error occurs
170: */
171: public void tearDown() throws Exception {
172: super.tearDown();
173: }
174: }
|