KickJava   Java API By Example, From Geeks To Geeks.

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


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_JonasAdminApplicationContainer.java,v 1.3 2005/07/20 08:52:16 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.JonasAdminTestCase;
34 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
35
36 import com.meterware.httpunit.HttpUnitOptions;
37 import com.meterware.httpunit.TableCell;
38 import com.meterware.httpunit.WebConversation;
39 import com.meterware.httpunit.WebLink;
40 import com.meterware.httpunit.WebResponse;
41 import com.meterware.httpunit.WebTable;
42
43 /**
44  * Class for testing application container in jonasAdmin
45  * @author Paul Kemler
46  *
47  */

48 public class F_JonasAdminApplicationContainer extends JonasAdminTestCase {
49
50     /**
51      * URL of Application container
52      */

53     private static final String JavaDoc URL_JONASADMIN_APP_CONTAINER = "ListAppContainers.do";
54
55     /**
56      * URL of the ear tab
57      */

58     private static final String JavaDoc URL_JONASADMIN_EAR = "/jonasAdmin/EditEar.do";
59
60     /**
61      * URL of the web tab
62      */

63     private static final String JavaDoc URL_JONASADMIN_WEB = "/jonasAdmin/service/earWars.jsp";
64
65     /**
66      * URL of the ejb tab
67      */

68     private static final String JavaDoc URL_JONASADMIN_JAR = "/jonasAdmin/service/earJars.jsp";
69
70     /**
71      * URL of the resource adapter tab
72      */

73     private static final String JavaDoc URL_JONASADMIN_RAR = "/jonasAdmin/service/earRars.jsp";
74
75     /**
76      * URL of the deployment descriptor tab
77      */

78     private static final String JavaDoc URL_JONASADMIN_XML = "/jonasAdmin/service/earXmlDeployment.jsp";
79
80     /**
81      * number of tabs with war, jar and rar in the ear
82      */

83     private static final int NUMBER_OF_TABS_WITH_WAR_JAR_RAR = 6;
84
85     /**
86      * number of tabs without rar in the ear
87      */

88     private static final int NUMBER_OF_TABS_WITHOUT_RAR = 5;
89
90     /**
91      * Constructor with a specified name
92      * @param s name
93      */

94     public F_JonasAdminApplicationContainer(String JavaDoc s) {
95         super(s, URL_JONASADMIN);
96     }
97
98     /**
99      * Constructor with a specified name and a WebConversation reference
100      * @param wc the WebConversation of the suite test
101      * @param s name
102      */

103     public F_JonasAdminApplicationContainer(WebConversation wc, String JavaDoc s) {
104         super(wc, s, URL_JONASADMIN);
105     }
106
107     /**
108      * Main method
109      * @param args the arguments
110      */

111     public static void main(String JavaDoc[] args) {
112
113         String JavaDoc testtorun = null;
114         // Get args
115
for (int argn = 0; argn < args.length; argn++) {
116             String JavaDoc sArg = args[argn];
117             if (sArg.equals("-n")) {
118                 testtorun = args[++argn];
119             }
120         }
121         if (testtorun == null) {
122             junit.textui.TestRunner.run(suite());
123         } else {
124             junit.textui.TestRunner.run(new F_JonasAdminApplicationContainer(testtorun));
125         }
126     }
127
128     /**
129      * Get a new TestSuite for this class
130      * @return a new TestSuite for this class
131      */

132     public static TestSuite suite() {
133         return new TestSuite(F_JonasAdminApplicationContainer.class);
134     }
135
136     /**
137      * Get a new TestSuite for this class
138      * @param wc the WebConversation
139      * @return a new TestSuite for this class with the WebConversation instance
140      */

141     public static TestSuite suite(WebConversation wc) {
142         TestSuite suite = new TestSuite();
143         suite.addTest(new F_JonasAdminApplicationContainer(wc, "testAddEarWithWarJarAndRar"));
144         suite.addTest(new F_JonasAdminApplicationContainer(wc, "testAddEarWithoutRar"));
145         return suite;
146     }
147
148     /**
149      * Setup need for these tests
150      * jonasAdmin is required
151      * @throws Exception if it fails
152      */

153     protected void setUp() throws Exception JavaDoc {
154         super.setUp();
155
156         if (wc.getCurrentPage().getURL() == null) {
157             useWar("jonasAdmin");
158             // login to jonas admin
159
try {
160                 JonasAdminAuth.doValidAuth(wc, url);
161             } catch (Exception JavaDoc e) {
162                 fail("authentification failed : " + e);
163             }
164         } else {
165             // if there was an error, the connection must be restablished
166
try {
167                 wc.getFrameContents(FRAME_TREE);
168             } catch (Exception JavaDoc e) {
169                 wc.getResponse(urlLogOut);
170                 // login to jonas admin
171
try {
172                     JonasAdminAuth.doValidAuth(wc, url);
173                 } catch (Exception JavaDoc auth) {
174                     fail("authentification failed : " + auth);
175                 }
176             }
177         }
178     }
179
180     /**
181      * Test application container when an ear with a war, a jar and a rar is deployed
182      * @throws Exception if error occurs
183      *
184      */

185     public void testAddEarWithWarJarAndRar() throws Exception JavaDoc {
186
187         WebResponse wr;
188         WebLink link;
189         WebTable table;
190         WebTable tabTable;
191         TableCell selectedCell;
192         TableCell cell;
193         String JavaDoc ear = "earsample";
194         int selectedTab;
195         int code;
196         JonasAdminUtils utils = new JonasAdminUtils();
197
198         // Disable errors of javascript
199
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
200         // Disable exception thrown on error status
201
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
202
203         // Test only if there are services ear, ejb and resource
204
if (jProp.isEar() && jProp.isEjb() && jProp.isResource()) {
205             // Add earsample.ear
206
useEar(ear);
207
208             // Go to application container
209
wr = wc.getFrameContents(FRAME_TREE);
210             link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_APP_CONTAINER);
211             link.click();
212             wr = wc.getFrameContents(FRAME_CONTENT);
213
214             // Go to earsample page
215
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, ear);
216             link.click();
217             wr = wc.getFrameContents(FRAME_CONTENT);
218             selectedTab = 2;
219
220             // Verify infos
221
table = utils.getTable(wr, 0);
222             cell = table.getTableCell(0,2);
223             // File
224
assertEquals("It is not the name of the ear file. ", ear + ".ear", cell.getText());
225             // Path
226
String JavaDoc path = System.getProperty("jonas.base") + File.separator + "apps" + File.separator + ear + ".ear";
227             assertEquals("It is not the path of the ear file. ", path, table.getTableCell(1,2).getText());
228
229             // Verify tabs
230
tabTable = utils.getTabTable(wr);
231             testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab);
232             // - links
233
assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ",
234                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER));
235             assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ",
236                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB));
237             assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ",
238                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR));
239             assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ",
240                     tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR));
241             assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ",
242                     tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML));
243
244
245             // Go to the Web tab
246
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, 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             // File
254
cell = table.getTableCell(1, 0);
255             assertEquals("It is not the name of the war file. ", "earsample", cell.getText());
256             // Link
257
link = cell.getLinks()[0];
258             code = wc.sendRequest(link.getRequest()).getResponseCode();
259             assertTrue("The file link does not contain 'EditWebApp.do?on='. ", link.getURLString().indexOf("EditWebApp.do?on=") != -1);
260             assertEquals("The link " + link.getURLString() + " is not found. ", 200, code);
261
262             // Path
263
cell = table.getTableCell(1, 1);
264             assertTrue("It is not the path of the war file. ", cell.getText().endsWith("earsample.war"));
265
266             // Verify tabs
267
tabTable = utils.getTabTable(wr);
268             testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab);
269             // - links
270
assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ",
271                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER));
272             assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ",
273                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR));
274             assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ",
275                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR));
276             assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ",
277                     tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR));
278             assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ",
279                     tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML));
280
281
282             // Go to the Ejb tab
283
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_JAR);
284             link.click();
285             wr = wc.getFrameContents(FRAME_CONTENT);
286             selectedTab = 4;
287
288             // Verify infos
289
table = utils.getTable(wr, 0);
290             cell = table.getTableCell(1, 0);
291             // File
292
assertEquals("It is not the name of the war file. ", "secusb", cell.getText());
293             // Link
294
link = cell.getLinks()[0];
295             code = wc.sendRequest(link.getRequest()).getResponseCode();
296             assertTrue("The file link does not contain 'EditContainer.do?select='. ", cell.getLinks()[0].getURLString().indexOf("EditContainer.do?select=") != -1);
297             assertEquals("The link " + link.getURLString() + " is not found. ", 200, code);
298
299             // Path
300
cell = table.getTableCell(1, 1);
301             assertTrue("It is not the path of the war file. ", cell.getText().endsWith("secusb.jar"));
302
303             // Verify tabs
304
tabTable = utils.getTabTable(wr);
305             testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab);
306             // - links
307
assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ",
308                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER));
309             assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ",
310                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR));
311             assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ",
312                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB));
313             assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ",
314                     tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR));
315             assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ",
316                     tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML));
317
318
319             // Go to the RA tab
320
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_RAR);
321             link.click();
322             wr = wc.getFrameContents(FRAME_CONTENT);
323             selectedTab = 5;
324
325             // Verify infos
326
table = utils.getTable(wr, 0);
327             cell = table.getTableCell(1, 0);
328             // File
329
assertEquals("It is not the name of the rar file. ", "earsample.ra-sample", cell.getText());
330             // Link
331
link = cell.getLinks()[0];
332             code = wc.sendRequest(link.getRequest()).getResponseCode();
333             assertTrue("The file link does not contain 'EditResourceAdapter.do?select='. ", cell.getLinks()[0].getURLString().indexOf("EditResourceAdapter.do?select=") != -1);
334             assertEquals("The link " + link.getURLString() + " is not found. ", 200, code);
335
336             // Path
337
cell = table.getTableCell(1, 1);
338             assertTrue("It is not the path of the rar file. ", cell.getText().endsWith("ra-sample.rar"));
339
340             // Verify tabs
341
tabTable = utils.getTabTable(wr);
342             testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab);
343             // - links
344
assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ",
345                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER));
346             assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ",
347                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR));
348             assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ",
349                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB));
350             assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ",
351                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR));
352             assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ",
353                     tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML));
354
355
356             // Go to the deployement descriptor tab
357
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_XML);
358             link.click();
359             wr = wc.getFrameContents(FRAME_CONTENT);
360             selectedTab = 6;
361
362             // Verify tabs
363
tabTable = utils.getTabTable(wr);
364             testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab);
365             // - links
366
assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ",
367                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER));
368             assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ",
369                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR));
370             assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ",
371                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB));
372             assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ",
373                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR));
374             assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ",
375                     tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR));
376         }
377     }
378
379     /**
380      * Test application container without a deployed rar
381      * @throws Exception if error occurs
382      *
383      */

384     public void testAddEarWithoutRar() throws Exception JavaDoc {
385
386         WebResponse wr;
387         WebLink link;
388         WebTable tabTable;
389         String JavaDoc ear = "alarm";
390         JonasAdminUtils utils = new JonasAdminUtils();
391
392         // Disable errors of javascript
393
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
394         // Disable exception thrown on error status
395
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
396
397         // Test only if there are services earand ejb
398
if (jProp.isEar() && jProp.isEjb() && jProp.isResource()) {
399             // Add earsample.ear
400
useEar(ear);
401
402             // Go to application container
403
wr = wc.getFrameContents(FRAME_TREE);
404             link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_APP_CONTAINER);
405             link.click();
406             wr = wc.getFrameContents(FRAME_CONTENT);
407
408             // Go to earsample page
409
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, ear);
410             link.click();
411             wr = wc.getFrameContents(FRAME_CONTENT);
412
413             // Verify tabs
414
tabTable = utils.getTabTable(wr);
415             // - number of tabs
416
assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ",
417                     NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2);
418
419
420             // Go to the Web tab
421
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEB);
422             link.click();
423             wr = wc.getFrameContents(FRAME_CONTENT);
424
425             // Verify tabs
426
tabTable = utils.getTabTable(wr);
427             // - number of tabs
428
assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ",
429                     NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2);
430
431
432             // Go to the Ejb tab
433
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_JAR);
434             link.click();
435             wr = wc.getFrameContents(FRAME_CONTENT);
436
437             // Verify tabs
438
tabTable = utils.getTabTable(wr);
439             // - number of tabs
440
assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ",
441                     NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2);
442
443
444             // Go to the deployement descriptor tab
445
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_XML);
446             link.click();
447             wr = wc.getFrameContents(FRAME_CONTENT);
448
449             // Verify tabs
450
tabTable = utils.getTabTable(wr);
451             // - number of tabs
452
assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ",
453                     NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2);
454         }
455     }
456
457     /**
458      * Verify number of tabs and the selected tab
459      * @param tabTable the tab table
460      * @param nbTabs number of tabs
461      * @param selectedTab the numero of the selected tab
462      */

463     private void testTabs(WebTable tabTable, int nbTabs, int selectedTab) {
464         TableCell selectedCell;
465         // - number of tabs
466
assertEquals("There are not " + nbTabs + " tabs. ",
467                 nbTabs, (tabTable.getColumnCount() + 1) / 2);
468         // - selected tab
469
selectedCell = tabTable.getTableCell(1, (selectedTab * 2) - 2);
470         assertEquals("It is not the selected tab. ", 1, selectedCell.getElementsWithAttribute("src", "/jonasAdmin/images/dot.gif").length);
471     }
472
473 }
474
Popular Tags