KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > service > container > F_JonasAdminWebContainer


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_JonasAdminWebContainer.java,v 1.4 2005/07/25 09:10:14 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.service.container;
27
28 import java.io.File JavaDoc;
29
30 import junit.framework.TestSuite;
31
32 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
33 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles;
34 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
35 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
36
37 import com.meterware.httpunit.Button;
38 import com.meterware.httpunit.HttpUnitOptions;
39 import com.meterware.httpunit.TableCell;
40 import com.meterware.httpunit.WebConversation;
41 import com.meterware.httpunit.WebForm;
42 import com.meterware.httpunit.WebLink;
43 import com.meterware.httpunit.WebResponse;
44 import com.meterware.httpunit.WebTable;
45
46 /**
47  * Class for testing web container in jonasAdmin
48  * @author Paul Kemler
49  *
50  */

51 public class F_JonasAdminWebContainer extends JonasAdminTestCase {
52
53     /**
54      * URL of Web containers
55      */

56     private static final String JavaDoc URL_JONASADMIN_WEB_CONTAINERS = "ListWebContainers.do";
57
58     /**
59      * URL of Web Container
60      */

61     private static final String JavaDoc URL_JONASADMIN_WEBAPP = "EditWebApp.do";
62
63     /**
64      * URL of edit war
65      */

66     private static final String JavaDoc URL_JONASADMIN_EDIT_WAR = "EditWar.do";
67
68     /**
69      * URL of servlets
70      */

71     private static final String JavaDoc URL_JONASADMIN_SERVLETS = "warServlets.jsp";
72
73     /**
74      * URL of web.xml
75      */

76     private static final String JavaDoc URL_JONASADMIN_WEB_XML = "warWebXml.jsp";
77
78     /**
79      * URL of web.xml
80      */

81     private static final String JavaDoc URL_JONASADMIN_JONAS_XML = "warJonasXml.jsp";
82
83     /**
84      * URL of web container: ALARM
85      */

86     private static final String JavaDoc URL_JONASADMIN_WEBAPP_ALARM = "EditWebApp.do?on=jonas%3Aj2eeType%3DWebModule%2Cname%3D%2F%2Flocalhost%2Falarm%2CJ2EEApplication%3Dalarm%2CJ2EEServer%3Djonas";
87
88     /**
89      * URL of the cancel button
90      */

91     private static final String JavaDoc BUTTON_SERVLET_CANCEL = "EditWebAppCatalina.do";
92
93     /**
94      * URL of the save all button
95      */

96     private static final String JavaDoc BUTTON_SERVLET_SAVE_ALL = "SaveCatalina.do";
97
98     /**
99      * URL of the stop button
100      */

101     private static final String JavaDoc BUTTON_WEBAPP_STOP = "javascript:submitHidden('webAppCatalinaForm','action','stop')";
102
103     /**
104      * URL of the start button
105      */

106     private static final String JavaDoc BUTTON_WEBAPP_START = "javascript:submitHidden('webAppCatalinaForm','action','start')";
107
108     /**
109      * URL of the reload button
110      */

111     private static final String JavaDoc BUTTON_WEBAPP_RELOAD = "javascript:submitHidden('webAppCatalinaForm','action','reload')";
112
113     /**
114      * number of tabs when you are in web containers
115      */

116     private static final int NUMBER_OF_TABS_FOR_WEB_CONTAINERS = 1;
117
118     /**
119      * number of tabs when you are in ROOT container
120      */

121     private static final int NUMBER_OF_TABS_FOR_ROOT = 6;
122
123     /**
124      * number of tabs when you are in stopped ROOT container
125      */

126     private static final int NUMBER_OF_TABS_FOR_STOPPED_ROOT = 4;
127
128     /**
129      * Constructor with a specified name
130      * @param s name
131      */

132     public F_JonasAdminWebContainer(String JavaDoc s) {
133         super(s, URL_JONASADMIN);
134     }
135
136     /**
137      * Constructor with a specified name and a WebConversation reference
138      * @param wc the WebConversation of the suite test
139      * @param s name
140      */

141     public F_JonasAdminWebContainer(WebConversation wc, String JavaDoc s) {
142         super(wc, s, URL_JONASADMIN);
143     }
144
145     /**
146      * Main method
147      * @param args the arguments
148      */

149     public static void main(String JavaDoc[] args) {
150
151         String JavaDoc testtorun = null;
152         // Get args
153
for (int argn = 0; argn < args.length; argn++) {
154             String JavaDoc sArg = args[argn];
155             if (sArg.equals("-n")) {
156                 testtorun = args[++argn];
157             }
158         }
159         if (testtorun == null) {
160             junit.textui.TestRunner.run(suite());
161         } else {
162             junit.textui.TestRunner.run(new F_JonasAdminWebContainer(testtorun));
163         }
164     }
165
166     /**
167      * Get a new TestSuite for this class
168      * @return a new TestSuite for this class
169      */

170     public static TestSuite suite() {
171         return new TestSuite(F_JonasAdminWebContainer.class);
172     }
173
174     /**
175      * Get a new TestSuite for this class
176      * @param wc the WebConversation
177      * @return a new TestSuite for this class with the WebConversation instance
178      */

179     public static TestSuite suite(WebConversation wc) {
180         TestSuite suite = new TestSuite();
181         suite.addTest(new F_JonasAdminWebContainer(wc, "testWebContainerNoInEar"));
182         suite.addTest(new F_JonasAdminWebContainer(wc, "testWebContainerInEar"));
183         return suite;
184     }
185
186     /**
187      * Setup need for these tests
188      * jonasAdmin is required
189      * @throws Exception if it fails
190      */

191     protected void setUp() throws Exception JavaDoc {
192         super.setUp();
193
194         if (wc.getCurrentPage().getURL() == null) {
195             useWar("jonasAdmin");
196             // login to jonas admin
197
try {
198                 JonasAdminAuth.doValidAuth(wc, url);
199             } catch (Exception JavaDoc e) {
200                 fail("authentification failed : " + e);
201             }
202         } else {
203             // if there was an error, the connection must be restablished
204
try {
205                 wc.getFrameContents(FRAME_TREE);
206             } catch (Exception JavaDoc e) {
207                 wc.getResponse(urlLogOut);
208                 // login to jonas admin
209
try {
210                     JonasAdminAuth.doValidAuth(wc, url);
211                 } catch (Exception JavaDoc auth) {
212                     fail("authentification failed : " + auth);
213                 }
214             }
215         }
216     }
217
218     /**
219      * Test a Web Container that it is not in an ear
220      * @throws Exception if error occurs
221      *
222      */

223     public void testWebContainerNoInEar() throws Exception JavaDoc {
224
225         WebResponse wr;
226         WebLink link;
227         WebTable table;
228         WebTable tabTable;
229         TableCell cell;
230         int selectedTab;
231         JonasAdminUtils utils = new JonasAdminUtils();
232
233         // Disable errors of javascript
234
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
235         // Disable exception thrown on error status
236
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
237
238         // Go to web containers
239
wr = wc.getFrameContents(FRAME_TREE);
240         link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEB_CONTAINERS);
241         link.click();
242         wr = wc.getFrameContents(FRAME_CONTENT);
243         selectedTab = 1;
244
245         // Verify there is a link for each context
246
table = utils.getTable(wr, 0);
247         for (int i = 1; i < table.getRowCount(); i++) {
248             cell = table.getTableCell(i, 0);
249             assertEquals("There is no one link for the context : " + cell.getText(), 1, cell.getLinks().length);
250         }
251
252         // Verify there is 1 tab
253
tabTable = utils.getTabTable(wr);
254         testTabs(tabTable, NUMBER_OF_TABS_FOR_WEB_CONTAINERS, selectedTab);
255
256         // Go to ROOT
257
int rowRoot = utils.getFirstRow("ROOT", table, 0).intValue();
258         link = table.getTableCell(rowRoot, 0).getLinks()[0];
259         link.click();
260         wr = wc.getFrameContents(FRAME_CONTENT);
261         selectedTab = 2;
262
263         // Verify CONTEXT
264
if (jProp.isCatalina()) {
265             table = utils.getTable(wr, 4);
266             testContextTableCatalina(table, "/", "localhost");
267         } else {
268             table = utils.getTable(wr, 1);
269             testContextTableJetty(table, "/", "JOnAS Package index", "true");
270         }
271
272         // Verify tabs
273
tabTable = utils.getTabTable(wr);
274         testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab);
275         // - links
276
assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS + " is not found in the first tab. ", tabTable
277                 .getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_CONTAINERS));
278         assertTrue("The link " + URL_JONASADMIN_EDIT_WAR + " is not found in the third tab. ", tabTable.getTableCell(0,
279                 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EDIT_WAR));
280         assertTrue("The link " + URL_JONASADMIN_SERVLETS + " is not found in the fourth tab. ", tabTable.getTableCell(
281                 0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_SERVLETS));
282         assertTrue("The link " + URL_JONASADMIN_WEB_XML + " is not found in the fifth tab. ", tabTable.getTableCell(0,
283                 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_XML));
284         assertTrue("The link " + URL_JONASADMIN_JONAS_XML + " is not found in the sixth tab. ", tabTable.getTableCell(
285                 0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JONAS_XML));
286
287         if (jProp.isCatalina()) {
288             // Verify Save button
289
wr = testSaveButton(wr);
290
291             // Verify settings
292
wr = testModifySettings(wr);
293
294             // Verify actions
295
wr = testActions(wr, utils);
296         }
297
298         // Go to EditWar
299
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_EDIT_WAR);
300         link.click();
301         wr = wc.getFrameContents(FRAME_CONTENT);
302         selectedTab = 3;
303
304         // Verify Web container
305
table = utils.getTable(wr, 1);
306         testWebContainerTable(table, "", "localhost", "ctxroot.war", "true");
307
308         // Verify it is not 'In application container'
309
try {
310             table = utils.getTable(wr, 3);
311             fail("There is the 'In application container' table. ");
312         } catch (Exception JavaDoc e) {
313             // It is ok
314
}
315
316         // Verify tabs
317
tabTable = utils.getTabTable(wr);
318         testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab);
319         // - links
320
assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS + " is not found in the first tab. ", tabTable
321                 .getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_CONTAINERS));
322         assertTrue("The link " + URL_JONASADMIN_WEBAPP + " is not found in the second tab. ", tabTable.getTableCell(0,
323                 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEBAPP));
324         assertTrue("The link " + URL_JONASADMIN_SERVLETS + " is not found in the fourth tab. ", tabTable.getTableCell(
325                 0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_SERVLETS));
326         assertTrue("The link " + URL_JONASADMIN_WEB_XML + " is not found in the fifth tab. ", tabTable.getTableCell(0,
327                 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_XML));
328         assertTrue("The link " + URL_JONASADMIN_JONAS_XML + " is not found in the sixth tab. ", tabTable.getTableCell(
329                 0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JONAS_XML));
330
331         // Go to Servlet tab
332
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVLETS);
333         link.click();
334         wr = wc.getFrameContents(FRAME_CONTENT);
335         selectedTab = 4;
336
337         // Verify servlets
338
wr = testServlet(wr, utils);
339
340         // Verify tabs
341
tabTable = utils.getTabTable(wr);
342         testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab);
343         // - links
344
assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS + " is not found in the first tab. ", tabTable
345                 .getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_CONTAINERS));
346         assertTrue("The link " + URL_JONASADMIN_WEBAPP + " is not found in the second tab. ", tabTable.getTableCell(0,
347                 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEBAPP));
348         assertTrue("The link " + URL_JONASADMIN_EDIT_WAR + " is not found in the third tab. ", tabTable.getTableCell(0,
349                 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EDIT_WAR));
350         assertTrue("The link " + URL_JONASADMIN_WEB_XML + " is not found in the fifth tab. ", tabTable.getTableCell(0,
351                 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_XML));
352         assertTrue("The link " + URL_JONASADMIN_JONAS_XML + " is not found in the sixth tab. ", tabTable.getTableCell(
353                 0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JONAS_XML));
354
355         // Go to Web.xml tab
356
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEB_XML);
357         link.click();
358         wr = wc.getFrameContents(FRAME_CONTENT);
359         selectedTab = 5;
360
361         // Verify Web Xml
362
// TODO
363

364         // Verify tabs
365
tabTable = utils.getTabTable(wr);
366         testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab);
367         // - links
368
assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS + " is not found in the first tab. ", tabTable
369                 .getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_CONTAINERS));
370         assertTrue("The link " + URL_JONASADMIN_WEBAPP + " is not found in the second tab. ", tabTable.getTableCell(0,
371                 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEBAPP));
372         assertTrue("The link " + URL_JONASADMIN_EDIT_WAR + " is not found in the third tab. ", tabTable.getTableCell(0,
373                 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EDIT_WAR));
374         assertTrue("The link " + URL_JONASADMIN_SERVLETS + " is not found in the fourth tab. ", tabTable.getTableCell(
375                 0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_SERVLETS));
376         assertTrue("The link " + URL_JONASADMIN_JONAS_XML + " is not found in the sixth tab. ", tabTable.getTableCell(
377                 0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JONAS_XML));
378
379         // Go to Jonas Xml tab
380
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_JONAS_XML);
381         link.click();
382         wr = wc.getFrameContents(FRAME_CONTENT);
383         selectedTab = 6;
384
385         // Verify jonas.xml
386
// TODO
387

388         // Verify tabs
389
tabTable = utils.getTabTable(wr);
390         testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab);
391         // - links
392
assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS + " is not found in the first tab. ", tabTable
393                 .getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_CONTAINERS));
394         assertTrue("The link " + URL_JONASADMIN_WEBAPP + " is not found in the second tab. ", tabTable.getTableCell(0,
395                 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEBAPP));
396         assertTrue("The link " + URL_JONASADMIN_EDIT_WAR + " is not found in the third tab. ", tabTable.getTableCell(0,
397                 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EDIT_WAR));
398         assertTrue("The link " + URL_JONASADMIN_SERVLETS + " is not found in the fourth tab. ", tabTable.getTableCell(
399                 0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_SERVLETS));
400         assertTrue("The link " + URL_JONASADMIN_WEB_XML + " is not found in the fifth tab. ", tabTable.getTableCell(0,
401                 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_XML));
402
403     }
404
405     /**
406      * Test a Web Container that it is in an ear
407      * @throws Exception if error occurs
408      *
409      */

410     public void testWebContainerInEar() throws Exception JavaDoc {
411
412         WebResponse wr;
413         WebLink link;
414         WebTable table;
415         TableCell cell;
416         JonasAdminUtils utils = new JonasAdminUtils();
417
418         // Disable errors of javascript
419
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
420         // Disable exception thrown on error status
421
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
422
423         // Add alarm.ear
424
useEar("alarm");
425
426         // Go to web containers
427
wr = wc.getFrameContents(FRAME_TREE);
428         link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEB_CONTAINERS);
429         link.click();
430         wr = wc.getFrameContents(FRAME_CONTENT);
431
432         // Go to ALARM
433
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEBAPP_ALARM);
434         link.click();
435         wr = wc.getFrameContents(FRAME_CONTENT);
436
437         // Go to EditWar
438
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_EDIT_WAR);
439         link.click();
440         wr = wc.getFrameContents(FRAME_CONTENT);
441
442         // Verify 'In application container'
443
table = utils.getTable(wr, 1);
444         try {
445             table = utils.getTable(wr, 4);
446         } catch (Exception JavaDoc e) {
447             fail("There is not the 'In application container' table. ");
448         }
449         testInApplicationContainer(table);
450
451     }
452
453     /**
454      * Verify number of tabs and the selected tab
455      * @param tabTable the tab table
456      * @param nbTabs number of tabs
457      * @param selectedTab the numero of the selected tab
458      */

459     private void testTabs(WebTable tabTable, int nbTabs, int selectedTab) {
460         TableCell selectedCell;
461         // - number of tabs
462
assertEquals("There are not " + nbTabs + " tabs. ", nbTabs, (tabTable.getColumnCount() + 1) / 2);
463         // - selected tab
464
selectedCell = tabTable.getTableCell(1, (selectedTab * 2) - 2);
465         assertEquals("It is not the selected tab. ", 1, selectedCell.getElementsWithAttribute("src",
466                 "/jonasAdmin/images/dot.gif").length);
467     }
468
469     /**
470      * Test path and host in the context table
471      * @param table the context table
472      * @param path the expected value of the path
473      * @param host the expected value of the host
474      * @throws Exception if an error occurs for going to the url
475      */

476     private void testContextTableCatalina(WebTable table, String JavaDoc path, String JavaDoc host) throws Exception JavaDoc {
477         WebConversation wc2 = new WebConversation();
478         // Path /
479
assertEquals("It is not the expected path. ", path, table.getTableCell(0, 2).getText());
480         String JavaDoc urlRoot = prefixUrl + path;
481         int code = wc2.getResponse(urlRoot).getResponseCode();
482         assertEquals("The page " + urlRoot + " is not found. ", 200, code);
483         // Host localhost
484
assertEquals("It is not the expected host. ", host, table.getTableCell(1, 2).getText());
485     }
486
487     /**
488      * Test path and host in the context table
489      * @param table the context table
490      * @param path the expected value of the path
491      * @param name the expected value of the context name
492      * @param started the expected value of 'Started'
493      * @throws Exception if an error occurs for going to the url
494      */

495     private void testContextTableJetty(WebTable table, String JavaDoc path, String JavaDoc name, String JavaDoc started) throws Exception JavaDoc {
496         WebConversation wc2 = new WebConversation();
497         // Path /
498
assertEquals("It is not the expected path. ", path, table.getTableCell(0, 2).getText());
499         String JavaDoc urlRoot = prefixUrl + path;
500         int code = wc2.getResponse(urlRoot).getResponseCode();
501         assertEquals("The page " + urlRoot + " is not found. ", 200, code);
502         // Name JOnAS Package index
503
assertEquals("It is not the expected name of the context. ", name, table.getTableCell(1, 2).getText());
504         // Started true
505
assertEquals("It is not the expected value of 'Started'. ", name, table.getTableCell(2, 2).getText());
506     }
507
508     /**
509      * Test context root, host name, path and Java 2 delegation model in the web container table
510      * @param table the web container table
511      * @param contextRoot the expected value of the context root
512      * @param hostName the expected value of the host name
513      * @param path the end of the path value
514      * @param model the expected value of the Java 2 delegation model
515      */

516     private void testWebContainerTable(WebTable table, String JavaDoc contextRoot, String JavaDoc hostName, String JavaDoc path, String JavaDoc model) {
517         // Context root
518
assertEquals("It is not the context root. ", contextRoot, table.getTableCell(0, 2).getText());
519         // Host name localhost
520
assertEquals("It is not the host name. ", hostName, table.getTableCell(1, 2).getText());
521         // Path /home/kemlerp/base/jonas/webapps/autoload/ctxroot.war
522
assertTrue("It is not the end of the path. ", table.getTableCell(2, 2).getText().endsWith(path));
523         // Java 2 delegation model true
524
assertEquals("It is not the Java 2 delegation model value. ", model, table.getTableCell(3, 2).getText());
525     }
526
527     /**
528      * Test if the save button goes to the servlet server page and if save all and cancel buttons return to the previous page
529      * @param wr the content frame in the WebApp tab and catalina is used.
530      * @return wr the content frame in the WebApp tab.
531      * @throws Exception if an error occurs.
532      */

533     private WebResponse testSaveButton(WebResponse wr) throws Exception JavaDoc {
534         String JavaDoc beginTime;
535         String JavaDoc endTime;
536         WebLink link;
537         WebForm form = wr.getForms()[0];
538         String JavaDoc previousPage = wr.getElementsWithAttribute("class", "contentTitle")[0].getText();
539         // Get the 3rd button : 'btnSave'
540
Button button = form.getButtons()[2];
541         button.click();
542         wr = wc.getFrameContents(FRAME_CONTENT);
543         assertTrue("The save button doesn't go to 'jonasserver/servletServer.jsp'. ", wr.getText().indexOf(
544                 "jonasserver/servletServer.jsp") != -1);
545         // Get time
546
beginTime = getTime();
547         link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, BUTTON_SERVLET_SAVE_ALL);
548         WebResponse wrSaveAll = wc.sendRequest(link.getRequest());
549         // Get time
550
endTime = getTime();
551         // Delete created files: server.xml
552
JonasAdminFiles.recoverServerConf(beginTime, endTime);
553         assertEquals("The cancel button of the servlet server page doesn't go back to '" + previousPage + "' page. !",
554                 previousPage, wrSaveAll.getElementsWithAttribute("class", "contentTitle")[0].getText());
555
556         link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, BUTTON_SERVLET_CANCEL);
557         link.click();
558         wr = wc.getFrameContents(FRAME_CONTENT);
559         assertEquals("The cancel button of the servlet server page doesn't go back to '" + previousPage + "' page. !",
560                 previousPage, wr.getElementsWithAttribute("class", "contentTitle")[0].getText());
561
562         return wr;
563     }
564
565     /**
566      * Test modification of settings
567      * @param wr the content frame in the WebApp tab.
568      * @return wr the content frame in the WebApp tab.
569      * @throws Exception if an error occurs.
570      */

571     private WebResponse testModifySettings(WebResponse wr) throws Exception JavaDoc {
572         WebForm form = wr.getForms()[0];
573         form.setParameter("cookies", "false");
574         form.setParameter("reloadable", "true");
575         form.setParameter("swallowOutput", "true");
576         Button button = form.getSubmitButton("btn_apply");
577         button.click();
578         wr = wc.getFrameContents(FRAME_CONTENT);
579         form = wr.getForms()[0];
580         String JavaDoc cookies = form.getParameterValue("cookies");
581         String JavaDoc reloadable = form.getParameterValue("reloadable");
582         String JavaDoc swallowOutput = form.getParameterValue("swallowOutput");
583
584         assertEquals("The value of the cookie parameter is not 'false'. ", "false", cookies);
585         assertEquals("The value of the reloadable parameter is not 'true'. ", "true", reloadable);
586         assertEquals("The value of the swallowOutput parameter is not 'true'. ", "true", swallowOutput);
587
588         return wr;
589     }
590
591     /**
592      * Test actions Start, Stop and Reload
593      * @param wr the content frame in the WebApp tab.
594      * @param selectedTab the selected Tab.
595      * @return the content frame in the WebApp tab.
596      * @throws Exception if an error occurs.
597      */

598     private WebResponse testActions(WebResponse wr, JonasAdminUtils utils) throws Exception JavaDoc {
599         WebLink link;
600         TableCell reloadCell;
601         TableCell startCell;
602         TableCell stopCell;
603         WebTable tabTable;
604         WebConversation wc2 = new WebConversation();
605         int selectedTab = 2;
606         WebTable table = utils.getTable(wr, 1).getTableCell(0, 0).getTables()[0];
607         startCell = table.getTableCell(0, 1);
608         // No link for start button
609
assertEquals("There is a link for the 'Start' button. ", 0, startCell.getLinks().length);
610         // Disabled button
611
assertEquals("The 'Start' button is not grey. ", 1,
612                 startCell.getElementsWithAttribute("class", "btnDisabled").length);
613
614         // Stop action
615
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, BUTTON_WEBAPP_STOP);
616         link.click();
617         wr = wc.getFrameContents(FRAME_CONTENT);
618         table = utils.getTable(wr, 1).getTableCell(0, 0).getTables()[0];
619         reloadCell = table.getTableCell(0, 0);
620         startCell = table.getTableCell(0, 1);
621         stopCell = table.getTableCell(0, 2);
622         // No link for stop button and reload button
623
assertEquals("There is a link for the 'Reload' button. ", 0, reloadCell.getLinks().length);
624         assertEquals("There is a link for the 'Stop' button. ", 0, stopCell.getLinks().length);
625         // Disabled button
626
assertEquals("The 'Reload' button is not grey. ", 1, reloadCell
627                 .getElementsWithAttribute("class", "btnDisabled").length);
628         assertEquals("The 'Start' button is grey. ", 0,
629                 startCell.getElementsWithAttribute("class", "btnDisabled").length);
630         assertEquals("The 'Stop' button is not grey. ", 1,
631                 stopCell.getElementsWithAttribute("class", "btnDisabled").length);
632         // Verify URL
633
String JavaDoc urlRoot = prefixUrl + "/";
634         int code = wc2.getResponse(urlRoot).getResponseCode();
635         assertTrue("The page " + urlRoot + " is found. ", code != 200);
636
637         // Verify tabs
638
tabTable = utils.getTabTable(wr);
639         testTabs(tabTable, NUMBER_OF_TABS_FOR_STOPPED_ROOT, selectedTab);
640         // - links
641
assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS + " is not found in the first tab. ", tabTable
642                 .getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB_CONTAINERS));
643         assertTrue("The link " + URL_JONASADMIN_EDIT_WAR + " is not found in the second tab. ", tabTable.getTableCell(
644                 0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EDIT_WAR));
645         assertTrue("The link " + URL_JONASADMIN_JONAS_XML + " is not found in the sixth tab. ", tabTable.getTableCell(
646                 0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JONAS_XML));
647
648         // Start action
649
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, BUTTON_WEBAPP_START);
650         link.click();
651         wr = wc.getFrameContents(FRAME_CONTENT);
652         table = utils.getTable(wr, 1).getTableCell(0, 0).getTables()[0];
653         reloadCell = table.getTableCell(0, 0);
654         startCell = table.getTableCell(0, 1);
655         stopCell = table.getTableCell(0, 2);
656         // No link for start button
657
assertEquals("There is a link for the 'Start' button. ", 0, startCell.getLinks().length);
658         // Disabled button
659
assertEquals("The 'Reload' button is grey. ", 0,
660                 reloadCell.getElementsWithAttribute("class", "btnDisabled").length);
661         assertEquals("The 'Start' button is not grey. ", 1,
662                 startCell.getElementsWithAttribute("class", "btnDisabled").length);
663         assertEquals("The 'Stop' button is grey. ", 0, stopCell.getElementsWithAttribute("class", "btnDisabled").length);
664         // Verify URL
665
code = wc2.getResponse(urlRoot).getResponseCode();
666         assertEquals("The page " + urlRoot + " is not found. ", 200, code);
667
668         // Reload action
669
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, BUTTON_WEBAPP_RELOAD);
670         link.click();
671         wr = wc.getFrameContents(FRAME_CONTENT);
672         table = utils.getTable(wr, 1).getTableCell(0, 0).getTables()[0];
673         reloadCell = table.getTableCell(0, 0);
674         startCell = table.getTableCell(0, 1);
675         stopCell = table.getTableCell(0, 2);
676         // No link for start button
677
assertEquals("There is a link for the 'Start' button. ", 0, startCell.getLinks().length);
678         // Disabled button
679
assertEquals("The 'Reload' button is grey. ", 0,
680                 reloadCell.getElementsWithAttribute("class", "btnDisabled").length);
681         assertEquals("The 'Start' button is not grey. ", 1,
682                 startCell.getElementsWithAttribute("class", "btnDisabled").length);
683         assertEquals("The 'Stop' button is grey. ", 0, stopCell.getElementsWithAttribute("class", "btnDisabled").length);
684         // Verify URL
685
code = wc2.getResponse(urlRoot).getResponseCode();
686         assertEquals("The page " + urlRoot + " is not found. ", 200, code);
687
688         return wr;
689     }
690
691     /**
692      * Test servlet infos
693      * @param wr the content frame in the Servlet tab.
694      * @param utils jonasAdmin utils
695      * @return WebResponse the content frame
696      * @throws Exception if an error occurs
697      */

698     private WebResponse testServlet(WebResponse wr, JonasAdminUtils utils) throws Exception JavaDoc {
699         WebLink link;
700         WebTable table;
701         table = utils.getTable(wr, 0);
702         int nbServlets = Integer.parseInt(table.getTableCell(0, 2).getText());
703
704         table = utils.getTable(wr, 2);
705         // Number of rows = number of servlets
706
assertEquals("There are not '" + nbServlets + "' rows in the 'Name' table. ", nbServlets, table.getRowCount());
707
708         // Verify Servlets with a MBean link
709
for (int i = 0; i < nbServlets; i++) {
710             String JavaDoc name = table.getTableCell(i, 0).getText();
711             int code = wc.getResponse(prefixUrl + "/jonasAdmin/ListMBeanDetails.do?select=" + name).getResponseCode();
712             assertEquals("The MBean details for '" + name + "' are not found. ", 200, code);
713         }
714
715         wc.getResponse(urlWelcome);
716         wr = wc.getFrameContents(FRAME_TREE);
717         link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEB_CONTAINERS);
718         link.click();
719         wr = wc.getFrameContents(FRAME_CONTENT);
720         table = utils.getTable(wr, 0);
721         int rowRoot = utils.getFirstRow("ROOT", table, 0).intValue();
722         if (rowRoot != -1) {
723             link = table.getTableCell(rowRoot, 0).getLinks()[0];
724             link.click();
725         } else {
726             fail("The WebContainer 'ROOT' was not found in the web container list. ");
727         }
728         wr = wc.getFrameContents(FRAME_CONTENT);
729         link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVLETS);
730         link.click();
731         wr = wc.getFrameContents(FRAME_CONTENT);
732
733         return wr;
734     }
735
736     private void testInApplicationContainer(WebTable table) throws Exception JavaDoc {
737         // Verify path
738
String JavaDoc path = table.getTableCell(0, 2).getText();
739         assertTrue("The path doesn't end with 'apps" + File.separator + "alarm.ear'. ", path.endsWith("apps"
740                 + File.separator + "alarm.ear"));
741
742         // Verify link
743
String JavaDoc name = table.getTableCell(0, 0).getText();
744         assertEquals("The name of the application container is not 'alarm.ear'. ", "alarm.ear", name);
745         WebLink link = table.getTableCell(0, 0).getLinks()[0];
746         try {
747             int code = wc.sendRequest(link.getRequest()).getResponseCode();
748             assertEquals("The page 'alarm.ear' is not found (link = '" + link.getURLString() + "'). ", 200, code);
749         } catch (Exception JavaDoc e) {
750             fail("The link '" + link.getURLString() + "' creates an error. ");
751         }
752     }
753 }
754
Popular Tags