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_JonasAdminApplicationContainer.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.JonasAdminTestCase;
032: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
033:
034: import com.meterware.httpunit.HttpUnitOptions;
035: import com.meterware.httpunit.TableCell;
036: import com.meterware.httpunit.WebLink;
037: import com.meterware.httpunit.WebResponse;
038: import com.meterware.httpunit.WebTable;
039:
040: /**
041: * Class for testing application container in jonasAdmin
042: * @author Paul Kemler
043: *
044: */
045: public class F_JonasAdminApplicationContainer extends
046: JonasAdminTestCase {
047:
048: /**
049: * URL of Application container
050: */
051: private static final String URL_JONASADMIN_APP_CONTAINER = "ListAppContainers.do";
052:
053: /**
054: * URL of the ear tab
055: */
056: private static final String URL_JONASADMIN_EAR = "/jonasAdmin/EditEar.do";
057:
058: /**
059: * URL of the web tab
060: */
061: private static final String URL_JONASADMIN_WEB = "/jonasAdmin/service/earWars.jsp";
062:
063: /**
064: * URL of the ejb tab
065: */
066: private static final String URL_JONASADMIN_JAR = "/jonasAdmin/service/earJars.jsp";
067:
068: /**
069: * URL of the resource adapter tab
070: */
071: private static final String URL_JONASADMIN_RAR = "/jonasAdmin/service/earRars.jsp";
072:
073: /**
074: * URL of the deployment descriptor tab
075: */
076: private static final String URL_JONASADMIN_XML = "/jonasAdmin/service/earXmlDeployment.jsp";
077:
078: /**
079: * number of tabs with war, jar and rar in the ear
080: */
081: private static final int NUMBER_OF_TABS_WITH_WAR_JAR_RAR = 6;
082:
083: /**
084: * number of tabs without rar in the ear
085: */
086: private static final int NUMBER_OF_TABS_WITHOUT_RAR = 5;
087:
088: /**
089: * Constructor with a specified name
090: * @param s name
091: */
092: public F_JonasAdminApplicationContainer(String s) {
093: super (s, URL_JONASADMIN);
094: }
095:
096: /**
097: * Main method
098: * @param args the arguments
099: */
100: public static void main(String[] args) {
101:
102: String testtorun = null;
103: // Get args
104: for (int argn = 0; argn < args.length; argn++) {
105: String sArg = args[argn];
106: if (sArg.equals("-n")) {
107: testtorun = args[++argn];
108: }
109: }
110: if (testtorun == null) {
111: junit.textui.TestRunner.run(suite());
112: } else {
113: junit.textui.TestRunner
114: .run(new F_JonasAdminApplicationContainer(testtorun));
115: }
116: }
117:
118: /**
119: * Get a new TestSuite for this class
120: * @return a new TestSuite for this class
121: */
122: public static TestSuite suite() {
123: return new TestSuite(F_JonasAdminApplicationContainer.class);
124: }
125:
126: /**
127: * Setup need for these tests
128: * jonasAdmin is required
129: * @throws Exception if it fails
130: */
131: protected void setUp() throws Exception {
132: super .setUp();
133:
134: if (wc.getCurrentPage().getURL() == null) {
135: useWar("jonasAdmin");
136: // login to jonas admin
137: try {
138: JonasAdminAuth.doValidAuth(wc, url);
139: } catch (Exception e) {
140: fail("authentification failed : " + e);
141: }
142: } else {
143: // if there was an error, the connection must be restablished
144: try {
145: wc.getFrameContents(FRAME_TREE);
146: } catch (Exception e) {
147: wc.getResponse(urlLogOut);
148: // login to jonas admin
149: try {
150: JonasAdminAuth.doValidAuth(wc, url);
151: } catch (Exception auth) {
152: fail("authentification failed : " + auth);
153: }
154: }
155: }
156: }
157:
158: /**
159: * Test application container when an ear with a war, a jar and a rar is deployed
160: * @throws Exception if error occurs
161: *
162: */
163: public void testAddEarWithWarJarAndRar() throws Exception {
164:
165: WebResponse wr;
166: WebLink link;
167: WebTable table;
168: WebTable tabTable;
169: TableCell selectedCell;
170: TableCell cell;
171: String ear = "earsample";
172: int selectedTab;
173: int code;
174: JonasAdminUtils utils = new JonasAdminUtils();
175:
176: // Disable errors of javascript
177: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
178: // Disable exception thrown on error status
179: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
180:
181: // Test only if there are services ear, ejb and resource
182: if (jProp.isEar() && jProp.isEjb() && jProp.isResource()) {
183: // Add earsample.ear
184: useEar(ear);
185:
186: // Go to application container
187: wr = wc.getFrameContents(FRAME_TREE);
188: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
189: URL_JONASADMIN_APP_CONTAINER);
190: link.click();
191: wr = wc.getFrameContents(FRAME_CONTENT);
192:
193: // Go to earsample page
194: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
195: ear);
196: link.click();
197: wr = wc.getFrameContents(FRAME_CONTENT);
198: selectedTab = 2;
199:
200: // Verify infos
201: try {
202: table = utils.getTable(wr, 0);
203: cell = table.getTableCell(0, 2);
204: // File
205: assertEquals("It is not the name of the ear file. ",
206: ear + ".ear", cell.getText());
207: // Path
208: String path = System.getProperty("jonas.base")
209: + File.separator + "apps" + File.separator
210: + ear + ".ear";
211: assertEquals("It is not the path of the ear file. ",
212: path, table.getTableCell(1, 2).getText());
213: } catch (ArrayIndexOutOfBoundsException e) {
214: throw new IllegalStateException(
215: "Cannot find a table in the content frame. ");
216: }
217:
218: // Verify tabs
219: tabTable = utils.getTabTable(wr);
220: testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR,
221: selectedTab, "Problem in 'earsample.ear' tab.");
222: // - links
223: assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER
224: + " is not found in the first tab. ", tabTable
225: .getTableCell(0, 0).getLinks()[0].getURLString()
226: .endsWith(URL_JONASADMIN_APP_CONTAINER));
227: assertTrue("The link " + URL_JONASADMIN_WEB
228: + " is not found in the third tab. ", tabTable
229: .getTableCell(0, 4).getLinks()[0].getURLString()
230: .endsWith(URL_JONASADMIN_WEB));
231: assertTrue("The link " + URL_JONASADMIN_JAR
232: + " is not found in the fourth tab. ", tabTable
233: .getTableCell(0, 6).getLinks()[0].getURLString()
234: .endsWith(URL_JONASADMIN_JAR));
235: assertTrue("The link " + URL_JONASADMIN_RAR
236: + " is not found in the fifth tab. ", tabTable
237: .getTableCell(0, 8).getLinks()[0].getURLString()
238: .endsWith(URL_JONASADMIN_RAR));
239: assertTrue("The link " + URL_JONASADMIN_XML
240: + " is not found in the sixth tab. ", tabTable
241: .getTableCell(0, 10).getLinks()[0].getURLString()
242: .endsWith(URL_JONASADMIN_XML));
243:
244: // Go to the Web tab
245: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
246: URL_JONASADMIN_WEB);
247: link.click();
248: wr = wc.getFrameContents(FRAME_CONTENT);
249: selectedTab = 3;
250:
251: // Verify infos
252: table = utils.getTable(wr, 0);
253:
254: // File
255: cell = table.getTableCell(1, 0);
256: if (cell.getText().equals("")) {
257: if (jProp.isCatalina()) {
258: fail("It is not the name of the war file of 'earsample'. ");
259: } else {
260: throw new IllegalStateException(
261: "Not implemented: JETTY. ");
262: }
263: } else {
264: assertEquals("It is not the name of the war file. ",
265: "earsample", cell.getText());
266: // Link
267: link = cell.getLinks()[0];
268: code = wc.sendRequest(link.getRequest())
269: .getResponseCode();
270: assertTrue(
271: "The file link does not contain 'EditWebApp.do?on='. ",
272: link.getURLString()
273: .indexOf("EditWebApp.do?on=") != -1);
274: assertEquals("The link " + link.getURLString()
275: + " is not found. ", 200, code);
276: }
277:
278: // Path
279: cell = table.getTableCell(1, 1);
280: assertTrue("It is not the path of the war file. ", cell
281: .getText().endsWith("earsample.war"));
282:
283: // Verify tabs
284: tabTable = utils.getTabTable(wr);
285: testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR,
286: selectedTab, "Problem in 'Web' tab.");
287: // - links
288: assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER
289: + " is not found in the first tab. ", tabTable
290: .getTableCell(0, 0).getLinks()[0].getURLString()
291: .endsWith(URL_JONASADMIN_APP_CONTAINER));
292: assertTrue("The link " + URL_JONASADMIN_EAR
293: + " is not found in the second tab. ", tabTable
294: .getTableCell(0, 2).getLinks()[0].getURLString()
295: .endsWith(URL_JONASADMIN_EAR));
296: assertTrue("The link " + URL_JONASADMIN_JAR
297: + " is not found in the fourth tab. ", tabTable
298: .getTableCell(0, 6).getLinks()[0].getURLString()
299: .endsWith(URL_JONASADMIN_JAR));
300: assertTrue("The link " + URL_JONASADMIN_RAR
301: + " is not found in the fifth tab. ", tabTable
302: .getTableCell(0, 8).getLinks()[0].getURLString()
303: .endsWith(URL_JONASADMIN_RAR));
304: assertTrue("The link " + URL_JONASADMIN_XML
305: + " is not found in the sixth tab. ", tabTable
306: .getTableCell(0, 10).getLinks()[0].getURLString()
307: .endsWith(URL_JONASADMIN_XML));
308:
309: // Go to the Ejb tab
310: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
311: URL_JONASADMIN_JAR);
312: link.click();
313: wr = wc.getFrameContents(FRAME_CONTENT);
314: selectedTab = 4;
315:
316: // Verify infos
317: table = utils.getTable(wr, 0);
318: cell = table.getTableCell(1, 0);
319: // File
320: assertEquals("It is not the name of the war file. ",
321: "secusb", cell.getText());
322: // Link
323: link = cell.getLinks()[0];
324: code = wc.sendRequest(link.getRequest()).getResponseCode();
325: assertTrue(
326: "The file link does not contain 'EditContainer.do?select='. ",
327: cell.getLinks()[0].getURLString().indexOf(
328: "EditContainer.do?select=") != -1);
329: assertEquals("The link " + link.getURLString()
330: + " is not found. ", 200, code);
331:
332: // Path
333: cell = table.getTableCell(1, 1);
334: assertTrue("It is not the path of the war file. ", cell
335: .getText().endsWith("secusb.jar"));
336:
337: // Verify tabs
338: tabTable = utils.getTabTable(wr);
339: testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR,
340: selectedTab, "Problem in 'Ejb' tab.");
341: // - links
342: assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER
343: + " is not found in the first tab. ", tabTable
344: .getTableCell(0, 0).getLinks()[0].getURLString()
345: .endsWith(URL_JONASADMIN_APP_CONTAINER));
346: assertTrue("The link " + URL_JONASADMIN_EAR
347: + " is not found in the second tab. ", tabTable
348: .getTableCell(0, 2).getLinks()[0].getURLString()
349: .endsWith(URL_JONASADMIN_EAR));
350: assertTrue("The link " + URL_JONASADMIN_WEB
351: + " is not found in the third tab. ", tabTable
352: .getTableCell(0, 4).getLinks()[0].getURLString()
353: .endsWith(URL_JONASADMIN_WEB));
354: assertTrue("The link " + URL_JONASADMIN_RAR
355: + " is not found in the fifth tab. ", tabTable
356: .getTableCell(0, 8).getLinks()[0].getURLString()
357: .endsWith(URL_JONASADMIN_RAR));
358: assertTrue("The link " + URL_JONASADMIN_XML
359: + " is not found in the sixth tab. ", tabTable
360: .getTableCell(0, 10).getLinks()[0].getURLString()
361: .endsWith(URL_JONASADMIN_XML));
362:
363: // Go to the RA tab
364: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
365: URL_JONASADMIN_RAR);
366: link.click();
367: wr = wc.getFrameContents(FRAME_CONTENT);
368: selectedTab = 5;
369:
370: // Verify infos
371: table = utils.getTable(wr, 0);
372: cell = table.getTableCell(1, 0);
373: // File
374: assertEquals("It is not the name of the rar file. ",
375: "earsample.ra-sample", cell.getText());
376: // Link
377: link = cell.getLinks()[0];
378: code = wc.sendRequest(link.getRequest()).getResponseCode();
379: assertTrue(
380: "The file link does not contain 'EditResourceAdapter.do?select='. ",
381: cell.getLinks()[0].getURLString().indexOf(
382: "EditResourceAdapter.do?select=") != -1);
383: assertEquals("The link " + link.getURLString()
384: + " is not found. ", 200, code);
385:
386: // Path
387: cell = table.getTableCell(1, 1);
388: assertTrue("It is not the path of the rar file. ", cell
389: .getText().endsWith("ra-sample.rar"));
390:
391: // Verify tabs
392: tabTable = utils.getTabTable(wr);
393: testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR,
394: selectedTab, "Problem in 'Resource Adapter' tab.");
395: // - links
396: assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER
397: + " is not found in the first tab. ", tabTable
398: .getTableCell(0, 0).getLinks()[0].getURLString()
399: .endsWith(URL_JONASADMIN_APP_CONTAINER));
400: assertTrue("The link " + URL_JONASADMIN_EAR
401: + " is not found in the second tab. ", tabTable
402: .getTableCell(0, 2).getLinks()[0].getURLString()
403: .endsWith(URL_JONASADMIN_EAR));
404: assertTrue("The link " + URL_JONASADMIN_WEB
405: + " is not found in the third tab. ", tabTable
406: .getTableCell(0, 4).getLinks()[0].getURLString()
407: .endsWith(URL_JONASADMIN_WEB));
408: assertTrue("The link " + URL_JONASADMIN_JAR
409: + " is not found in the fourth tab. ", tabTable
410: .getTableCell(0, 6).getLinks()[0].getURLString()
411: .endsWith(URL_JONASADMIN_JAR));
412: assertTrue("The link " + URL_JONASADMIN_XML
413: + " is not found in the sixth tab. ", tabTable
414: .getTableCell(0, 10).getLinks()[0].getURLString()
415: .endsWith(URL_JONASADMIN_XML));
416:
417: // Go to the deployement descriptor tab
418: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
419: URL_JONASADMIN_XML);
420: link.click();
421: wr = wc.getFrameContents(FRAME_CONTENT);
422: selectedTab = 6;
423:
424: // Verify tabs
425: tabTable = utils.getTabTable(wr);
426: testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR,
427: selectedTab,
428: "Problem in 'Deployment descriptor' tab.");
429: // - links
430: assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER
431: + " is not found in the first tab. ", tabTable
432: .getTableCell(0, 0).getLinks()[0].getURLString()
433: .endsWith(URL_JONASADMIN_APP_CONTAINER));
434: assertTrue("The link " + URL_JONASADMIN_EAR
435: + " is not found in the second tab. ", tabTable
436: .getTableCell(0, 2).getLinks()[0].getURLString()
437: .endsWith(URL_JONASADMIN_EAR));
438: assertTrue("The link " + URL_JONASADMIN_WEB
439: + " is not found in the third tab. ", tabTable
440: .getTableCell(0, 4).getLinks()[0].getURLString()
441: .endsWith(URL_JONASADMIN_WEB));
442: assertTrue("The link " + URL_JONASADMIN_JAR
443: + " is not found in the fourth tab. ", tabTable
444: .getTableCell(0, 6).getLinks()[0].getURLString()
445: .endsWith(URL_JONASADMIN_JAR));
446: assertTrue("The link " + URL_JONASADMIN_RAR
447: + " is not found in the fifth tab. ", tabTable
448: .getTableCell(0, 8).getLinks()[0].getURLString()
449: .endsWith(URL_JONASADMIN_RAR));
450: }
451: }
452:
453: /**
454: * Test application container without a deployed rar
455: * @throws Exception if error occurs
456: *
457: */
458: public void testAddEarWithoutRar() throws Exception {
459:
460: WebResponse wr;
461: WebLink link;
462: WebTable tabTable;
463: String ear = "alarm";
464: JonasAdminUtils utils = new JonasAdminUtils();
465:
466: // Disable errors of javascript
467: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
468: // Disable exception thrown on error status
469: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
470:
471: // Test only if there are services ear and ejb
472: if (jProp.isEar() && jProp.isEjb()) {
473: // Add alarm.ear
474: useEar(ear);
475:
476: // Go to application container
477: wr = wc.getFrameContents(FRAME_TREE);
478: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
479: URL_JONASADMIN_APP_CONTAINER);
480: link.click();
481: wr = wc.getFrameContents(FRAME_CONTENT);
482:
483: // Go to alarm page
484: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
485: ear);
486: link.click();
487: wr = wc.getFrameContents(FRAME_CONTENT);
488:
489: // Verify tabs
490: try {
491: tabTable = utils.getTabTable(wr);
492: } catch (ArrayIndexOutOfBoundsException e) {
493: throw new IllegalStateException(
494: "annot find the tab table. ");
495: }
496: // - number of tabs
497: assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR
498: + " tabs. ", NUMBER_OF_TABS_WITHOUT_RAR, (tabTable
499: .getColumnCount() + 1) / 2);
500:
501: // Go to the Web tab
502: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
503: URL_JONASADMIN_WEB);
504: link.click();
505: wr = wc.getFrameContents(FRAME_CONTENT);
506:
507: // Verify tabs
508: tabTable = utils.getTabTable(wr);
509:
510: // - number of tabs
511: assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR
512: + " tabs. ", NUMBER_OF_TABS_WITHOUT_RAR, (tabTable
513: .getColumnCount() + 1) / 2);
514:
515: // Go to the Ejb tab
516: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
517: URL_JONASADMIN_JAR);
518: link.click();
519: wr = wc.getFrameContents(FRAME_CONTENT);
520:
521: // Verify tabs
522: tabTable = utils.getTabTable(wr);
523: // - number of tabs
524: assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR
525: + " tabs. ", NUMBER_OF_TABS_WITHOUT_RAR, (tabTable
526: .getColumnCount() + 1) / 2);
527:
528: // Go to the deployement descriptor tab
529: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
530: URL_JONASADMIN_XML);
531: link.click();
532: wr = wc.getFrameContents(FRAME_CONTENT);
533:
534: // Verify tabs
535: tabTable = utils.getTabTable(wr);
536: // - number of tabs
537: assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR
538: + " tabs. ", NUMBER_OF_TABS_WITHOUT_RAR, (tabTable
539: .getColumnCount() + 1) / 2);
540: }
541: }
542:
543: /**
544: * Tear Down cleanUp action
545: * @throws Exception if an error occurs
546: */
547: public void tearDown() throws Exception {
548: super.tearDown();
549: }
550:
551: }
|