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_JonasAdminWebContainer.java 7381 2005-09-14 16:00:02Z kemlerp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jonasadmin.test.service.container;
025:
026: import java.io.File;
027:
028: import junit.framework.TestSuite;
029:
030: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
031: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles;
032: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
033: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
034:
035: import com.meterware.httpunit.Button;
036: import com.meterware.httpunit.HttpUnitOptions;
037: import com.meterware.httpunit.TableCell;
038: import com.meterware.httpunit.WebConversation;
039: import com.meterware.httpunit.WebForm;
040: import com.meterware.httpunit.WebLink;
041: import com.meterware.httpunit.WebResponse;
042: import com.meterware.httpunit.WebTable;
043:
044: /**
045: * Class for testing web container in jonasAdmin
046: * @author Paul Kemler
047: *
048: */
049: public class F_JonasAdminWebContainer extends JonasAdminTestCase {
050:
051: /**
052: * URL of Web containers
053: */
054: private static final String URL_JONASADMIN_WEB_CONTAINERS = "ListWebContainers.do";
055:
056: /**
057: * URL of Web Container
058: */
059: private static final String URL_JONASADMIN_WEBAPP = "EditWebApp.do";
060:
061: /**
062: * URL of edit war
063: */
064: private static final String URL_JONASADMIN_EDIT_WAR = "EditWar.do";
065:
066: /**
067: * URL of servlets
068: */
069: private static final String URL_JONASADMIN_SERVLETS = "warServlets.jsp";
070:
071: /**
072: * URL of web.xml
073: */
074: private static final String URL_JONASADMIN_WEB_XML = "warWebXml.jsp";
075:
076: /**
077: * URL of web.xml
078: */
079: private static final String URL_JONASADMIN_JONAS_XML = "warJonasXml.jsp";
080:
081: /**
082: * URL of web container: ALARM
083: */
084: private static final String URL_JONASADMIN_WEBAPP_ALARM = "alarm";
085:
086: /**
087: * URL of the cancel button
088: */
089: private static final String BUTTON_SERVLET_CANCEL = "EditWebAppCatalina.do";
090:
091: /**
092: * URL of the save all button
093: */
094: private static final String BUTTON_SERVLET_SAVE_ALL = "SaveCatalina.do";
095:
096: /**
097: * URL of the stop button
098: */
099: private static final String BUTTON_WEBAPP_STOP = "javascript:submitHidden('webAppCatalinaForm','action','stop')";
100:
101: /**
102: * URL of the start button
103: */
104: private static final String BUTTON_WEBAPP_START = "javascript:submitHidden('webAppCatalinaForm','action','start')";
105:
106: /**
107: * URL of the reload button
108: */
109: private static final String BUTTON_WEBAPP_RELOAD = "javascript:submitHidden('webAppCatalinaForm','action','reload')";
110:
111: /**
112: * number of tabs when you are in web containers
113: */
114: private static final int NUMBER_OF_TABS_FOR_WEB_CONTAINERS = 1;
115:
116: /**
117: * number of tabs when you are in ROOT container
118: */
119: private static final int NUMBER_OF_TABS_FOR_ROOT = 6;
120:
121: /**
122: * number of tabs when you are in stopped ROOT container
123: */
124: private static final int NUMBER_OF_TABS_FOR_STOPPED_ROOT = 4;
125:
126: /**
127: * Constructor with a specified name
128: * @param s name
129: */
130: public F_JonasAdminWebContainer(String s) {
131: super (s, URL_JONASADMIN);
132: }
133:
134: /**
135: * Main method
136: * @param args the arguments
137: */
138: public static void main(String[] args) {
139:
140: String testtorun = null;
141: // Get args
142: for (int argn = 0; argn < args.length; argn++) {
143: String sArg = args[argn];
144: if (sArg.equals("-n")) {
145: testtorun = args[++argn];
146: }
147: }
148: if (testtorun == null) {
149: junit.textui.TestRunner.run(suite());
150: } else {
151: junit.textui.TestRunner.run(new F_JonasAdminWebContainer(
152: testtorun));
153: }
154: }
155:
156: /**
157: * Get a new TestSuite for this class
158: * @return a new TestSuite for this class
159: */
160: public static TestSuite suite() {
161: return new TestSuite(F_JonasAdminWebContainer.class);
162: }
163:
164: /**
165: * Setup need for these tests
166: * jonasAdmin is required
167: * @throws Exception if it fails
168: */
169: protected void setUp() throws Exception {
170: super .setUp();
171:
172: if (wc.getCurrentPage().getURL() == null) {
173: useWar("jonasAdmin");
174: // login to jonas admin
175: try {
176: JonasAdminAuth.doValidAuth(wc, url);
177: } catch (Exception e) {
178: fail("authentification failed : " + e);
179: }
180: } else {
181: // if there was an error, the connection must be restablished
182: try {
183: wc.getFrameContents(FRAME_TREE);
184: } catch (Exception e) {
185: wc.getResponse(urlLogOut);
186: // login to jonas admin
187: try {
188: JonasAdminAuth.doValidAuth(wc, url);
189: } catch (Exception auth) {
190: fail("authentification failed : " + auth);
191: }
192: }
193: }
194: }
195:
196: /**
197: * Test a Web Container that it is not in an ear
198: * @throws Exception if error occurs
199: *
200: */
201: public void testWebContainerNoInEar() throws Exception {
202:
203: WebResponse wr;
204: WebLink link;
205: WebTable table;
206: WebTable tabTable;
207: TableCell cell;
208: int selectedTab;
209: JonasAdminUtils utils = new JonasAdminUtils();
210:
211: // Disable errors of javascript
212: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
213: // Disable exception thrown on error status
214: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
215:
216: // Go to web containers
217: wr = wc.getFrameContents(FRAME_TREE);
218: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
219: URL_JONASADMIN_WEB_CONTAINERS);
220: link.click();
221: wr = wc.getFrameContents(FRAME_CONTENT);
222: selectedTab = 1;
223:
224: // Verify there is a link for each context
225: table = utils.getTable(wr, 0);
226: for (int i = 1; i < table.getRowCount(); i++) {
227: cell = table.getTableCell(i, 0);
228: assertEquals("There is no one link for the context : "
229: + cell.getText(), 1, cell.getLinks().length);
230: }
231:
232: // Verify there is 1 tab
233: tabTable = utils.getTabTable(wr);
234: testTabs(tabTable, NUMBER_OF_TABS_FOR_WEB_CONTAINERS,
235: selectedTab, "Problem in 'Web Containers' tab.");
236:
237: // Go to ROOT
238: int rowRoot = utils.getFirstRow("ROOT", table, 0).intValue();
239: if (rowRoot == -1) {
240: fail("'ROOT' is not found in the table of Web Containers page. ");
241: }
242: link = table.getTableCell(rowRoot, 0).getLinks()[0];
243: link.click();
244: wr = wc.getFrameContents(FRAME_CONTENT);
245: selectedTab = 2;
246:
247: // Verify CONTEXT
248: if (jProp.isCatalina()) {
249: table = utils.getTable(wr, 4);
250: testContextTableCatalina(table, "/", "localhost");
251: } else {
252: table = utils.getTable(wr, 1);
253: testContextTableJetty(table, "/", "JOnAS Package index",
254: "true");
255: }
256:
257: // Verify tabs
258: tabTable = utils.getTabTable(wr);
259: if (!jProp.isCatalina()) {
260: if (NUMBER_OF_TABS_FOR_ROOT != (tabTable.getColumnCount() + 1) / 2) {
261: // There is not Servlet tab.
262: throw new IllegalStateException(
263: "Not implemented: JETTY. ");
264: }
265: }
266: testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab,
267: "Problem in 'ROOT' tab.");
268: // - links
269: assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS
270: + " is not found in the first tab. ", tabTable
271: .getTableCell(0, 0).getLinks()[0].getURLString()
272: .endsWith(URL_JONASADMIN_WEB_CONTAINERS));
273: assertTrue("The link " + URL_JONASADMIN_EDIT_WAR
274: + " is not found in the third tab. ", tabTable
275: .getTableCell(0, 4).getLinks()[0].getURLString()
276: .endsWith(URL_JONASADMIN_EDIT_WAR));
277: assertTrue("The link " + URL_JONASADMIN_SERVLETS
278: + " is not found in the fourth tab. ", tabTable
279: .getTableCell(0, 6).getLinks()[0].getURLString()
280: .endsWith(URL_JONASADMIN_SERVLETS));
281: assertTrue("The link " + URL_JONASADMIN_WEB_XML
282: + " is not found in the fifth tab. ", tabTable
283: .getTableCell(0, 8).getLinks()[0].getURLString()
284: .endsWith(URL_JONASADMIN_WEB_XML));
285: assertTrue("The link " + URL_JONASADMIN_JONAS_XML
286: + " is not found in the sixth tab. ", tabTable
287: .getTableCell(0, 10).getLinks()[0].getURLString()
288: .endsWith(URL_JONASADMIN_JONAS_XML));
289:
290: if (jProp.isCatalina()) {
291: // Verify Save button
292: wr = testSaveButton(wr);
293:
294: // Verify settings
295: wr = testModifySettings(wr);
296:
297: // Verify actions
298: wr = testActions(wr, utils);
299: }
300:
301: // Go to EditWar
302: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
303: URL_JONASADMIN_EDIT_WAR);
304: link.click();
305: wr = wc.getFrameContents(FRAME_CONTENT);
306: selectedTab = 3;
307:
308: // Verify Web container
309: table = utils.getTable(wr, 1);
310: testWebContainerTable(table, "", "localhost", "ctxroot.war",
311: "true");
312:
313: // Verify it is not 'In application container'
314: try {
315: table = utils.getTable(wr, 3);
316: fail("There is the 'In application container' table. ");
317: } catch (Exception e) {
318: // It is ok
319: }
320:
321: // Verify tabs
322: tabTable = utils.getTabTable(wr);
323: testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab,
324: "Problem in 'autoload/ctxroot.war' tab.");
325: // - links
326: assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS
327: + " is not found in the first tab. ", tabTable
328: .getTableCell(0, 0).getLinks()[0].getURLString()
329: .endsWith(URL_JONASADMIN_WEB_CONTAINERS));
330: assertTrue("The link " + URL_JONASADMIN_WEBAPP
331: + " is not found in the second tab. ", tabTable
332: .getTableCell(0, 2).getLinks()[0].getURLString()
333: .endsWith(URL_JONASADMIN_WEBAPP));
334: assertTrue("The link " + URL_JONASADMIN_SERVLETS
335: + " is not found in the fourth tab. ", tabTable
336: .getTableCell(0, 6).getLinks()[0].getURLString()
337: .endsWith(URL_JONASADMIN_SERVLETS));
338: assertTrue("The link " + URL_JONASADMIN_WEB_XML
339: + " is not found in the fifth tab. ", tabTable
340: .getTableCell(0, 8).getLinks()[0].getURLString()
341: .endsWith(URL_JONASADMIN_WEB_XML));
342: assertTrue("The link " + URL_JONASADMIN_JONAS_XML
343: + " is not found in the sixth tab. ", tabTable
344: .getTableCell(0, 10).getLinks()[0].getURLString()
345: .endsWith(URL_JONASADMIN_JONAS_XML));
346:
347: // Go to Servlet tab
348: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
349: URL_JONASADMIN_SERVLETS);
350: link.click();
351: wr = wc.getFrameContents(FRAME_CONTENT);
352: selectedTab = 4;
353:
354: // Verify servlets
355: wr = testServlet(wr, utils);
356:
357: // Verify tabs
358: tabTable = utils.getTabTable(wr);
359: testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab,
360: "Problem in 'Servlets' tab.");
361: // - links
362: assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS
363: + " is not found in the first tab. ", tabTable
364: .getTableCell(0, 0).getLinks()[0].getURLString()
365: .endsWith(URL_JONASADMIN_WEB_CONTAINERS));
366: assertTrue("The link " + URL_JONASADMIN_WEBAPP
367: + " is not found in the second tab. ", tabTable
368: .getTableCell(0, 2).getLinks()[0].getURLString()
369: .endsWith(URL_JONASADMIN_WEBAPP));
370: assertTrue("The link " + URL_JONASADMIN_EDIT_WAR
371: + " is not found in the third tab. ", tabTable
372: .getTableCell(0, 4).getLinks()[0].getURLString()
373: .endsWith(URL_JONASADMIN_EDIT_WAR));
374: assertTrue("The link " + URL_JONASADMIN_WEB_XML
375: + " is not found in the fifth tab. ", tabTable
376: .getTableCell(0, 8).getLinks()[0].getURLString()
377: .endsWith(URL_JONASADMIN_WEB_XML));
378: assertTrue("The link " + URL_JONASADMIN_JONAS_XML
379: + " is not found in the sixth tab. ", tabTable
380: .getTableCell(0, 10).getLinks()[0].getURLString()
381: .endsWith(URL_JONASADMIN_JONAS_XML));
382:
383: // Go to Web.xml tab
384: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
385: URL_JONASADMIN_WEB_XML);
386: link.click();
387: wr = wc.getFrameContents(FRAME_CONTENT);
388: selectedTab = 5;
389:
390: // Verify Web Xml
391: // TODO
392:
393: // Verify tabs
394: tabTable = utils.getTabTable(wr);
395: testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab,
396: "Problem in 'Web xml' tab.");
397: // - links
398: assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS
399: + " is not found in the first tab. ", tabTable
400: .getTableCell(0, 0).getLinks()[0].getURLString()
401: .endsWith(URL_JONASADMIN_WEB_CONTAINERS));
402: assertTrue("The link " + URL_JONASADMIN_WEBAPP
403: + " is not found in the second tab. ", tabTable
404: .getTableCell(0, 2).getLinks()[0].getURLString()
405: .endsWith(URL_JONASADMIN_WEBAPP));
406: assertTrue("The link " + URL_JONASADMIN_EDIT_WAR
407: + " is not found in the third tab. ", tabTable
408: .getTableCell(0, 4).getLinks()[0].getURLString()
409: .endsWith(URL_JONASADMIN_EDIT_WAR));
410: assertTrue("The link " + URL_JONASADMIN_SERVLETS
411: + " is not found in the fourth tab. ", tabTable
412: .getTableCell(0, 6).getLinks()[0].getURLString()
413: .endsWith(URL_JONASADMIN_SERVLETS));
414: assertTrue("The link " + URL_JONASADMIN_JONAS_XML
415: + " is not found in the sixth tab. ", tabTable
416: .getTableCell(0, 10).getLinks()[0].getURLString()
417: .endsWith(URL_JONASADMIN_JONAS_XML));
418:
419: // Go to Jonas Xml tab
420: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
421: URL_JONASADMIN_JONAS_XML);
422: link.click();
423: wr = wc.getFrameContents(FRAME_CONTENT);
424: selectedTab = 6;
425:
426: // Verify jonas.xml
427: // TODO
428:
429: // Verify tabs
430: tabTable = utils.getTabTable(wr);
431: testTabs(tabTable, NUMBER_OF_TABS_FOR_ROOT, selectedTab,
432: "Problem in 'JOnAS xml' tab.");
433: // - links
434: assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS
435: + " is not found in the first tab. ", tabTable
436: .getTableCell(0, 0).getLinks()[0].getURLString()
437: .endsWith(URL_JONASADMIN_WEB_CONTAINERS));
438: assertTrue("The link " + URL_JONASADMIN_WEBAPP
439: + " is not found in the second tab. ", tabTable
440: .getTableCell(0, 2).getLinks()[0].getURLString()
441: .endsWith(URL_JONASADMIN_WEBAPP));
442: assertTrue("The link " + URL_JONASADMIN_EDIT_WAR
443: + " is not found in the third tab. ", tabTable
444: .getTableCell(0, 4).getLinks()[0].getURLString()
445: .endsWith(URL_JONASADMIN_EDIT_WAR));
446: assertTrue("The link " + URL_JONASADMIN_SERVLETS
447: + " is not found in the fourth tab. ", tabTable
448: .getTableCell(0, 6).getLinks()[0].getURLString()
449: .endsWith(URL_JONASADMIN_SERVLETS));
450: assertTrue("The link " + URL_JONASADMIN_WEB_XML
451: + " is not found in the fifth tab. ", tabTable
452: .getTableCell(0, 8).getLinks()[0].getURLString()
453: .endsWith(URL_JONASADMIN_WEB_XML));
454:
455: }
456:
457: /**
458: * Test a Web Container that it is in an ear
459: * @throws Exception if error occurs
460: *
461: */
462: public void testWebContainerInEar() throws Exception {
463:
464: WebResponse wr;
465: WebLink link;
466: WebTable table;
467: TableCell cell;
468: JonasAdminUtils utils = new JonasAdminUtils();
469:
470: // Disable errors of javascript
471: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
472: // Disable exception thrown on error status
473: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
474:
475: // Add alarm.ear
476: useEar("alarm");
477:
478: // Go to web containers
479: wr = wc.getFrameContents(FRAME_TREE);
480: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
481: URL_JONASADMIN_WEB_CONTAINERS);
482: link.click();
483: wr = wc.getFrameContents(FRAME_CONTENT);
484:
485: // Go to ALARM
486: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
487: URL_JONASADMIN_WEBAPP_ALARM);
488: link.click();
489: wr = wc.getFrameContents(FRAME_CONTENT);
490:
491: // Go to EditWar
492: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
493: URL_JONASADMIN_EDIT_WAR);
494: link.click();
495: wr = wc.getFrameContents(FRAME_CONTENT);
496:
497: // Verify 'In application container'
498: table = utils.getTable(wr, 1);
499: try {
500: table = utils.getTable(wr, 4);
501: } catch (Exception e) {
502: fail("There is not the 'In application container' table. ");
503: }
504: testInApplicationContainer(table);
505:
506: }
507:
508: /**
509: * Test path and host in the context table
510: * @param table the context table
511: * @param path the expected value of the path
512: * @param host the expected value of the host
513: * @throws Exception if an error occurs for going to the url
514: */
515: private void testContextTableCatalina(WebTable table, String path,
516: String host) throws Exception {
517: WebConversation wc2 = new WebConversation();
518: // Path /
519: assertEquals("It is not the expected path. ", path, table
520: .getTableCell(0, 2).getText());
521: String urlRoot = prefixUrl + path;
522: int code = wc2.getResponse(urlRoot).getResponseCode();
523: assertEquals("The page " + urlRoot + " is not found. ", 200,
524: code);
525: // Host localhost
526: assertEquals("It is not the expected host. ", host, table
527: .getTableCell(1, 2).getText());
528: }
529:
530: /**
531: * Test path and host in the context table
532: * @param table the context table
533: * @param path the expected value of the path
534: * @param name the expected value of the context name
535: * @param started the expected value of 'Started'
536: * @throws Exception if an error occurs for going to the url
537: */
538: private void testContextTableJetty(WebTable table, String path,
539: String name, String started) throws Exception {
540: WebConversation wc2 = new WebConversation();
541: // Path /
542: assertEquals("It is not the expected path. ", path, table
543: .getTableCell(0, 2).getText());
544: String urlRoot = prefixUrl + path;
545: int code = wc2.getResponse(urlRoot).getResponseCode();
546: assertEquals("The page " + urlRoot + " is not found. ", 200,
547: code);
548: // Name JOnAS Package index
549: assertEquals("It is not the expected name of the context. ",
550: name, table.getTableCell(1, 2).getText());
551: // Started true
552: assertEquals("It is not the expected value of 'Started'. ",
553: started, table.getTableCell(2, 2).getText());
554: }
555:
556: /**
557: * Test context root, host name, path and Java 2 delegation model in the web container table
558: * @param table the web container table
559: * @param contextRoot the expected value of the context root
560: * @param hostName the expected value of the host name
561: * @param path the end of the path value
562: * @param model the expected value of the Java 2 delegation model
563: */
564: private void testWebContainerTable(WebTable table,
565: String contextRoot, String hostName, String path,
566: String model) {
567: // Context root
568: assertEquals("It is not the context root. ", contextRoot, table
569: .getTableCell(0, 2).getText());
570: // Host name localhost
571: assertEquals("It is not the host name. ", hostName, table
572: .getTableCell(1, 2).getText());
573: // Path /home/kemlerp/base/jonas/webapps/autoload/ctxroot.war
574: assertTrue("It is not the end of the path. ", table
575: .getTableCell(2, 2).getText().endsWith(path));
576: // Java 2 delegation model true
577: assertEquals("It is not the Java 2 delegation model value. ",
578: model, table.getTableCell(3, 2).getText());
579: }
580:
581: /**
582: * Test if the save button goes to the servlet server page and if save all and cancel buttons return to the previous page
583: * @param wr the content frame in the WebApp tab and catalina is used.
584: * @return wr the content frame in the WebApp tab.
585: * @throws Exception if an error occurs.
586: */
587: private WebResponse testSaveButton(WebResponse wr) throws Exception {
588: String beginTime;
589: String endTime;
590: WebLink link;
591: WebForm form = wr.getForms()[0];
592: String previousPage = wr.getElementsWithAttribute("class",
593: "contentTitle")[0].getText();
594: // Get the 3rd button : 'btnSave'
595: Button button = form.getButtons()[2];
596: button.click();
597: wr = wc.getFrameContents(FRAME_CONTENT);
598: assertTrue(
599: "The save button doesn't go to 'jonasserver/servletServer.jsp'. ",
600: wr.getText().indexOf("jonasserver/servletServer.jsp") != -1);
601: // Get time
602: beginTime = getTime();
603: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
604: BUTTON_SERVLET_SAVE_ALL);
605: WebResponse wrSaveAll = wc.sendRequest(link.getRequest());
606: // Get time
607: endTime = getTime();
608: // Delete created files: server.xml
609: JonasAdminFiles.recoverServerConf(beginTime, endTime);
610: assertEquals(
611: "The cancel button of the servlet server page doesn't go back to '"
612: + previousPage + "' page. !", previousPage,
613: wrSaveAll.getElementsWithAttribute("class",
614: "contentTitle")[0].getText());
615:
616: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
617: BUTTON_SERVLET_CANCEL);
618: link.click();
619: wr = wc.getFrameContents(FRAME_CONTENT);
620: assertEquals(
621: "The cancel button of the servlet server page doesn't go back to '"
622: + previousPage + "' page. !", previousPage, wr
623: .getElementsWithAttribute("class",
624: "contentTitle")[0].getText());
625:
626: return wr;
627: }
628:
629: /**
630: * Test modification of settings
631: * @param wr the content frame in the WebApp tab.
632: * @return wr the content frame in the WebApp tab.
633: * @throws Exception if an error occurs.
634: */
635: private WebResponse testModifySettings(WebResponse wr)
636: throws Exception {
637: WebForm form = wr.getForms()[0];
638: form.setParameter("cookies", "false");
639: form.setParameter("reloadable", "true");
640: form.setParameter("swallowOutput", "true");
641: Button button = form.getSubmitButton("btn_apply");
642: button.click();
643: wr = wc.getFrameContents(FRAME_CONTENT);
644: form = wr.getForms()[0];
645: String cookies = form.getParameterValue("cookies");
646: String reloadable = form.getParameterValue("reloadable");
647: String swallowOutput = form.getParameterValue("swallowOutput");
648:
649: assertEquals(
650: "The value of the cookie parameter is not 'false'. ",
651: "false", cookies);
652: assertEquals(
653: "The value of the reloadable parameter is not 'true'. ",
654: "true", reloadable);
655: assertEquals(
656: "The value of the swallowOutput parameter is not 'true'. ",
657: "true", swallowOutput);
658:
659: return wr;
660: }
661:
662: /**
663: * Test actions Start, Stop and Reload
664: * @param wr the content frame in the WebApp tab.
665: * @param selectedTab the selected Tab.
666: * @return the content frame in the WebApp tab.
667: * @throws Exception if an error occurs.
668: */
669: private WebResponse testActions(WebResponse wr,
670: JonasAdminUtils utils) throws Exception {
671: WebLink link;
672: TableCell reloadCell;
673: TableCell startCell;
674: TableCell stopCell;
675: WebTable tabTable;
676: WebConversation wc2 = new WebConversation();
677: int selectedTab = 2;
678: WebTable table = utils.getTable(wr, 1).getTableCell(0, 0)
679: .getTables()[0];
680: startCell = table.getTableCell(0, 1);
681: // No link for start button
682: assertEquals("There is a link for the 'Start' button. ", 0,
683: startCell.getLinks().length);
684: // Disabled button
685: assertEquals("The 'Start' button is not grey. ", 1,
686: startCell.getElementsWithAttribute("class",
687: "btnDisabled").length);
688:
689: // Stop action
690: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
691: BUTTON_WEBAPP_STOP);
692: link.click();
693: wr = wc.getFrameContents(FRAME_CONTENT);
694: table = utils.getTable(wr, 1).getTableCell(0, 0).getTables()[0];
695: reloadCell = table.getTableCell(0, 0);
696: startCell = table.getTableCell(0, 1);
697: stopCell = table.getTableCell(0, 2);
698: // No link for stop button and reload button
699: assertEquals("There is a link for the 'Reload' button. ", 0,
700: reloadCell.getLinks().length);
701: assertEquals("There is a link for the 'Stop' button. ", 0,
702: stopCell.getLinks().length);
703: // Disabled button
704: assertEquals("The 'Reload' button is not grey. ", 1,
705: reloadCell.getElementsWithAttribute("class",
706: "btnDisabled").length);
707: assertEquals("The 'Start' button is grey. ", 0,
708: startCell.getElementsWithAttribute("class",
709: "btnDisabled").length);
710: assertEquals("The 'Stop' button is not grey. ", 1,
711: stopCell.getElementsWithAttribute("class",
712: "btnDisabled").length);
713: // Verify URL
714: String urlRoot = prefixUrl + "/";
715: int code = wc2.getResponse(urlRoot).getResponseCode();
716: assertTrue("The page " + urlRoot + " is found. ", code != 200);
717:
718: // Verify tabs
719: tabTable = utils.getTabTable(wr);
720: testTabs(tabTable, NUMBER_OF_TABS_FOR_STOPPED_ROOT,
721: selectedTab, "Problem in 'ROOT' tab.");
722: // - links
723: assertTrue("The link " + URL_JONASADMIN_WEB_CONTAINERS
724: + " is not found in the first tab. ", tabTable
725: .getTableCell(0, 0).getLinks()[0].getURLString()
726: .endsWith(URL_JONASADMIN_WEB_CONTAINERS));
727: assertTrue("The link " + URL_JONASADMIN_EDIT_WAR
728: + " is not found in the second tab. ", tabTable
729: .getTableCell(0, 4).getLinks()[0].getURLString()
730: .endsWith(URL_JONASADMIN_EDIT_WAR));
731: assertTrue("The link " + URL_JONASADMIN_JONAS_XML
732: + " is not found in the sixth tab. ", tabTable
733: .getTableCell(0, 6).getLinks()[0].getURLString()
734: .endsWith(URL_JONASADMIN_JONAS_XML));
735:
736: // Start action
737: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
738: BUTTON_WEBAPP_START);
739: link.click();
740: wr = wc.getFrameContents(FRAME_CONTENT);
741: table = utils.getTable(wr, 1).getTableCell(0, 0).getTables()[0];
742: reloadCell = table.getTableCell(0, 0);
743: startCell = table.getTableCell(0, 1);
744: stopCell = table.getTableCell(0, 2);
745: // No link for start button
746: assertEquals("There is a link for the 'Start' button. ", 0,
747: startCell.getLinks().length);
748: // Disabled button
749: assertEquals("The 'Reload' button is grey. ", 0,
750: reloadCell.getElementsWithAttribute("class",
751: "btnDisabled").length);
752: assertEquals("The 'Start' button is not grey. ", 1,
753: startCell.getElementsWithAttribute("class",
754: "btnDisabled").length);
755: assertEquals("The 'Stop' button is grey. ", 0,
756: stopCell.getElementsWithAttribute("class",
757: "btnDisabled").length);
758: // Verify URL
759: code = wc2.getResponse(urlRoot).getResponseCode();
760: assertEquals("The page " + urlRoot + " is not found. ", 200,
761: code);
762:
763: // Reload action
764: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
765: BUTTON_WEBAPP_RELOAD);
766: link.click();
767: wr = wc.getFrameContents(FRAME_CONTENT);
768: table = utils.getTable(wr, 1).getTableCell(0, 0).getTables()[0];
769: reloadCell = table.getTableCell(0, 0);
770: startCell = table.getTableCell(0, 1);
771: stopCell = table.getTableCell(0, 2);
772: // No link for start button
773: assertEquals("There is a link for the 'Start' button. ", 0,
774: startCell.getLinks().length);
775: // Disabled button
776: assertEquals("The 'Reload' button is grey. ", 0,
777: reloadCell.getElementsWithAttribute("class",
778: "btnDisabled").length);
779: assertEquals("The 'Start' button is not grey. ", 1,
780: startCell.getElementsWithAttribute("class",
781: "btnDisabled").length);
782: assertEquals("The 'Stop' button is grey. ", 0,
783: stopCell.getElementsWithAttribute("class",
784: "btnDisabled").length);
785: // Verify URL
786: code = wc2.getResponse(urlRoot).getResponseCode();
787: assertEquals("The page " + urlRoot + " is not found. ", 200,
788: code);
789:
790: return wr;
791: }
792:
793: /**
794: * Test servlet infos
795: * @param wr the content frame in the Servlet tab.
796: * @param utils jonasAdmin utils
797: * @return WebResponse the content frame
798: * @throws Exception if an error occurs
799: */
800: private WebResponse testServlet(WebResponse wr,
801: JonasAdminUtils utils) throws Exception {
802: WebLink link;
803: WebTable table;
804: table = utils.getTable(wr, 0);
805: int nbServlets = Integer.parseInt(table.getTableCell(0, 2)
806: .getText());
807:
808: table = utils.getTable(wr, 2);
809: // Number of rows = number of servlets
810: assertEquals("There are not '" + nbServlets
811: + "' rows in the 'Name' table. ", nbServlets, table
812: .getRowCount());
813:
814: // Verify Servlets with a MBean link
815: for (int i = 0; i < nbServlets; i++) {
816: String name = table.getTableCell(i, 0).getText();
817: int code = wc.getResponse(
818: prefixUrl
819: + "/jonasAdmin/ListMBeanDetails.do?select="
820: + name).getResponseCode();
821: assertEquals("The MBean details for '" + name
822: + "' are not found. ", 200, code);
823: }
824:
825: wc.getResponse(urlWelcome);
826: wr = wc.getFrameContents(FRAME_TREE);
827: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
828: URL_JONASADMIN_WEB_CONTAINERS);
829: link.click();
830: wr = wc.getFrameContents(FRAME_CONTENT);
831: table = utils.getTable(wr, 0);
832: int rowRoot = utils.getFirstRow("ROOT", table, 0).intValue();
833: if (rowRoot != -1) {
834: link = table.getTableCell(rowRoot, 0).getLinks()[0];
835: link.click();
836: } else {
837: fail("The WebContainer 'ROOT' was not found in the web container list. ");
838: }
839: wr = wc.getFrameContents(FRAME_CONTENT);
840: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
841: URL_JONASADMIN_SERVLETS);
842: link.click();
843: wr = wc.getFrameContents(FRAME_CONTENT);
844:
845: return wr;
846: }
847:
848: private void testInApplicationContainer(WebTable table)
849: throws Exception {
850: // Verify path
851: String path = table.getTableCell(0, 2).getText();
852: assertTrue("The path doesn't end with 'apps" + File.separator
853: + "alarm.ear'. ", path.endsWith("apps" + File.separator
854: + "alarm.ear"));
855:
856: // Verify link
857: String name = table.getTableCell(0, 0).getText();
858: assertEquals(
859: "The name of the application container is not 'alarm.ear'. ",
860: "alarm.ear", name);
861: WebLink link = table.getTableCell(0, 0).getLinks()[0];
862: try {
863: int code = wc.sendRequest(link.getRequest())
864: .getResponseCode();
865: assertEquals("The page 'alarm.ear' is not found (link = '"
866: + link.getURLString() + "'). ", 200, code);
867: } catch (Exception e) {
868: fail("The link '" + link.getURLString()
869: + "' creates an error. ");
870: }
871: }
872:
873: /**
874: * Tear Down cleanUp action
875: * @throws Exception if an error occurs
876: */
877: public void tearDown() throws Exception {
878: super.tearDown();
879: }
880: }
|