KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > monitoring > F_JonasAdminActivatedMonitoring


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_JonasAdminActivatedMonitoring.java,v 1.4 2005/07/12 13:20:01 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.monitoring;
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.TableCell;
35 import com.meterware.httpunit.WebConversation;
36 import com.meterware.httpunit.WebForm;
37 import com.meterware.httpunit.WebLink;
38 import com.meterware.httpunit.WebResponse;
39
40
41 /**
42  * Define a class to test the JOnAS Admin console
43  * Test monitoring activation
44  * @author kemlerp
45  *
46  */

47 public class F_JonasAdminActivatedMonitoring extends JonasAdminTestCase {
48
49     /**
50      * URL of the deployment of EARs
51      */

52     private static final String JavaDoc URL_JONASADMIN_MONITORING = "/jonasAdmin/EditMonitoring.do";
53
54
55     /**
56      * Constructor with a specified name
57      * @param s name
58      */

59     public F_JonasAdminActivatedMonitoring(String JavaDoc s) {
60         super(s, URL_JONASADMIN);
61     }
62
63     /**
64      * Constructor with a specified name
65      * @param wc the WebConversation of the suite test
66      * @param s name
67      */

68     public F_JonasAdminActivatedMonitoring(WebConversation wc, String JavaDoc s) {
69         super(wc, s, URL_JONASADMIN);
70     }
71
72     /**
73      * Main method
74      * @param args the arguments
75      */

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

97     public static TestSuite suite() {
98         return new TestSuite(F_JonasAdminActivatedMonitoring.class);
99     }
100
101     /**
102      * Get a new TestSuite for this class
103      * @param wc the WebConversation
104      * @return a new TestSuite for this class with the WebConversation instance
105      */

106     public static TestSuite suite(WebConversation wc) {
107         TestSuite suite = new TestSuite();
108         suite.addTest(new F_JonasAdminActivatedMonitoring(wc, "testMonitoringActivation"));
109         return suite;
110     }
111
112     /**
113      * Setup need for these tests
114      * jonasAdmin is required
115      * @throws Exception if it fails
116      */

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

148     public void testMonitoringActivation() throws Exception JavaDoc {
149
150         // Disable errors of javascript
151
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
152         // Disable exception thrown on error status
153
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
154
155         // Go to Monitoring
156
WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MONITORING));
157         WebForm[] webForms = wr.getForms();
158         WebForm webForm = webForms[0];
159
160         // deactivate monitoring
161
webForm.setCheckbox("activated", "on", false);
162
163         wr = webForm.submit();
164         assertEquals("there is more one tab. ", -1, wr.getText().indexOf("class=\"tab\""));
165
166         // Go to another page
167
wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN));
168         wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MONITORING));
169         assertEquals("there is more one tab. ", -1, wr.getText().indexOf("class=\"tab\""));
170
171
172         // reactivate monitoring
173
webForms = wr.getForms();
174         webForm = webForms[0];
175         webForm.setCheckbox("activated", "on", true);
176
177         wr = webForm.submit();
178         assertFalse("there is not at least two tabs. ", wr.getText().indexOf("class=\"tab\"") == -1);
179
180         // verify link tab
181
TableCell cell = wr.getTables()[0].getTableCell(0, 0).getTables()[0].getTableCell(0, 2);
182         String JavaDoc attribut;
183         WebLink[] links;
184
185         attribut = cell.getAttribute("class");
186         assertEquals("the tab is not in the wanted cell. ", "tab", attribut);
187         links = cell.getLinks();
188         assertNotNull("there is no link", links);
189         assertEquals("link is not \"/jonasAdmin/EditMemory.do\"", "/jonasAdmin/EditMemory.do", links[0].getAttribute("href"));
190
191         // Go to another page
192
wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN));
193         wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MONITORING));
194         assertFalse("there is not at least two tabs. ", wr.getText().indexOf("class=\"tab\"") == -1);
195     }
196 }
197
Popular Tags