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_JonasAdminActivatedMonitoring.java 7381 2005-09-14 16:00:02Z kemlerp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jonasadmin.test.monitoring;
027:
028: import junit.framework.TestSuite;
029:
030: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
031: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
032:
033: import com.meterware.httpunit.HttpUnitOptions;
034: import com.meterware.httpunit.TableCell;
035: import com.meterware.httpunit.WebForm;
036: import com.meterware.httpunit.WebLink;
037: import com.meterware.httpunit.WebResponse;
038:
039: /**
040: * Define a class to test the JOnAS Admin console
041: * Test monitoring activation
042: * @author kemlerp
043: *
044: */
045: public class F_JonasAdminActivatedMonitoring extends JonasAdminTestCase {
046:
047: /**
048: * URL of the deployment of EARs
049: */
050: private static final String URL_JONASADMIN_MONITORING = "/jonasAdmin/EditMonitoring.do";
051:
052: /**
053: * Constructor with a specified name
054: * @param s name
055: */
056: public F_JonasAdminActivatedMonitoring(String s) {
057: super (s, URL_JONASADMIN);
058: }
059:
060: /**
061: * Main method
062: * @param args the arguments
063: */
064: public static void main(String[] args) {
065:
066: String testtorun = null;
067: // Get args
068: for (int argn = 0; argn < args.length; argn++) {
069: String sArg = args[argn];
070: if (sArg.equals("-n")) {
071: testtorun = args[++argn];
072: }
073: }
074: if (testtorun == null) {
075: junit.textui.TestRunner.run(suite());
076: } else {
077: junit.textui.TestRunner
078: .run(new F_JonasAdminActivatedMonitoring(testtorun));
079: }
080: }
081:
082: /**
083: * Get a new TestSuite for this class
084: * @return a new TestSuite for this class
085: */
086: public static TestSuite suite() {
087: return new TestSuite(F_JonasAdminActivatedMonitoring.class);
088: }
089:
090: /**
091: * Setup need for these tests
092: * jonasAdmin is required
093: * @throws Exception if it fails
094: */
095: protected void setUp() throws Exception {
096: super .setUp();
097:
098: if (wc.getCurrentPage().getURL() == null) {
099: useWar("jonasAdmin");
100: // login to jonas admin
101: try {
102: JonasAdminAuth.doValidAuth(wc, url);
103: } catch (Exception e) {
104: fail("authentification failed : " + e);
105: }
106: } else {
107: // if there was an error, the connection must be restablished
108: try {
109: wc.getFrameContents(FRAME_TREE);
110: } catch (Exception e) {
111: wc.getResponse(urlLogOut);
112: // login to jonas admin
113: try {
114: JonasAdminAuth.doValidAuth(wc, url);
115: } catch (Exception auth) {
116: fail("authentification failed : " + auth);
117: }
118: }
119: }
120: }
121:
122: /**
123: * Test activation monitoring
124: * @throws Exception if error occurs
125: */
126: public void testMonitoringActivation() throws Exception {
127:
128: // Disable errors of javascript
129: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
130: // Disable exception thrown on error status
131: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
132:
133: // Go to Monitoring
134: WebResponse wr = wc
135: .getResponse(getAbsoluteUrl(URL_JONASADMIN_MONITORING));
136: WebForm[] webForms = wr.getForms();
137: WebForm webForm = webForms[0];
138:
139: // deactivate monitoring
140: webForm.setCheckbox("activated", "on", false);
141:
142: wr = webForm.submit();
143: assertEquals("there is more one tab. ", -1, wr.getText()
144: .indexOf("class=\"tab\""));
145:
146: // Go to another page
147: wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN));
148: wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MONITORING));
149: assertEquals("there is more one tab. ", -1, wr.getText()
150: .indexOf("class=\"tab\""));
151:
152: // reactivate monitoring
153: webForms = wr.getForms();
154: webForm = webForms[0];
155: webForm.setCheckbox("activated", "on", true);
156:
157: wr = webForm.submit();
158: assertFalse("there is not at least two tabs. ", wr.getText()
159: .indexOf("class=\"tab\"") == -1);
160:
161: // verify link tab
162: TableCell cell = wr.getTables()[0].getTableCell(0, 0)
163: .getTables()[0].getTableCell(0, 2);
164: String attribut;
165: WebLink[] links;
166:
167: attribut = cell.getAttribute("class");
168: assertEquals("the tab is not in the wanted cell. ", "tab",
169: attribut);
170: links = cell.getLinks();
171: assertNotNull("there is no link", links);
172: assertEquals("link is not \"/jonasAdmin/EditMemory.do\"",
173: "/jonasAdmin/EditMemory.do", links[0]
174: .getAttribute("href"));
175:
176: // Go to another page
177: wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN));
178: wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MONITORING));
179: assertFalse("there is not at least two tabs. ", wr.getText()
180: .indexOf("class=\"tab\"") == -1);
181: }
182:
183: /**
184: * Tear Down cleanUp action
185: * @throws Exception if an error occurs
186: */
187: public void tearDown() throws Exception {
188: super.tearDown();
189: }
190: }
|