KickJava   Java API By Example, From Geeks To Geeks.

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


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_JonasAdminEjbContainer.java,v 1.4 2005/07/20 09:02:44 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.WebForm;
40 import com.meterware.httpunit.WebLink;
41 import com.meterware.httpunit.WebResponse;
42 import com.meterware.httpunit.WebTable;
43
44 /**
45  * Class for testing ejb container in jonasAdmin
46  * @author Paul Kemler
47  *
48  */

49 public class F_JonasAdminEjbContainer extends JonasAdminTestCase {
50
51     /**
52      * URL of Ejb container
53      */

54     private static final String JavaDoc URL_JONASADMIN_EJB_CONTAINER = "ListContainers.do";
55
56     /**
57      * URL of the container tab
58      */

59     private static final String JavaDoc URL_JONASADMIN_CONTAINER = "/ViewContainer.do";
60
61     /**
62      * URL of the container jsp
63      */

64     private static final String JavaDoc URL_JONASADMIN_CONTAINER_JSP = "/jonasAdmin/service/container.jsp";
65
66     /**
67      * URL of the statistic tab
68      */

69     private static final String JavaDoc URL_JONASADMIN_STATISTICS = "/EditContainerStatistic.do";
70
71     /**
72      * URL of the ejb container's' statistics tab
73      */

74     private static final String JavaDoc URL_JONASADMIN_CONTAINERS_STATISTICS = "EditEjbContainersStatistic.do";
75
76     /**
77      * URL of the view ejb container tab
78      */

79     private static final String JavaDoc URL_JONASADMIN_VIEW_EJB = "/ViewContainerEjbs.do";
80
81     /**
82      * URL of the mdb tab
83      */

84     private static final String JavaDoc URL_JONASADMIN_MDB = "write url of MDB tab";
85
86     /**
87      * URL of the entity bean tab
88      */

89     private static final String JavaDoc URL_JONASADMIN_EB = "write url of EB tab";
90
91     /**
92      * URL of the view ejb container jsp
93      */

94     private static final String JavaDoc URL_JONASADMIN_VIEW_EJB_JSP = "/jonasAdmin/service/containerEjbs.jsp";
95
96     /**
97      * URL of the ejb dependency jsp
98      */

99     private static final String JavaDoc URL_JONASADMIN_DEPENDENCIES = "/jonasAdmin/service/ejbDependency.jsp";
100
101     /**
102      * URL of the synchronize button
103      */

104     private static final String JavaDoc URL_JONASADMIN_SYNCHRONIZE = "ExecuteEjb.do?action=synchronize";
105
106     /**
107      * URL of the reduce button
108      */

109     private static final String JavaDoc URL_JONASADMIN_REDUCE = "ExecuteEjb.do?action=reduceCache";
110
111     /**
112      * number of tabs when you are in the jar tabs
113      */

114     private static final int NUMBER_OF_TABS_FOR_JAR = 4;
115
116     /**
117      * number of tabs when you are in the MDB tab
118      */

119     private static final int NUMBER_OF_TABS_FOR_MDB = 6;
120
121     /**
122      * Constructor with a specified name
123      * @param s name
124      */

125     public F_JonasAdminEjbContainer(String JavaDoc s) {
126         super(s, URL_JONASADMIN);
127     }
128
129     /**
130      * Constructor with a specified name and a WebConversation reference
131      * @param wc the WebConversation of the suite test
132      * @param s name
133      */

134     public F_JonasAdminEjbContainer(WebConversation wc, String JavaDoc s) {
135         super(wc, s, URL_JONASADMIN);
136     }
137
138     /**
139      * Main method
140      * @param args the arguments
141      */

142     public static void main(String JavaDoc[] args) {
143
144         String JavaDoc testtorun = null;
145         // Get args
146
for (int argn = 0; argn < args.length; argn++) {
147             String JavaDoc sArg = args[argn];
148             if (sArg.equals("-n")) {
149                 testtorun = args[++argn];
150             }
151         }
152         if (testtorun == null) {
153             junit.textui.TestRunner.run(suite());
154         } else {
155             junit.textui.TestRunner.run(new F_JonasAdminEjbContainer(testtorun));
156         }
157     }
158
159     /**
160      * Get a new TestSuite for this class
161      * @return a new TestSuite for this class
162      */

163     public static TestSuite suite() {
164         return new TestSuite(F_JonasAdminEjbContainer.class);
165     }
166
167     /**
168      * Get a new TestSuite for this class
169      * @param wc the WebConversation
170      * @return a new TestSuite for this class with the WebConversation instance
171      */

172     public static TestSuite suite(WebConversation wc) {
173         TestSuite suite = new TestSuite();
174         suite.addTest(new F_JonasAdminEjbContainer(wc, "testEjbContainer"));
175         suite.addTest(new F_JonasAdminEjbContainer(wc, "testStatistics"));
176         return suite;
177     }
178
179     /**
180      * Setup need for these tests
181      * jonasAdmin is required
182      * @throws Exception if it fails
183      */

184     protected void setUp() throws Exception JavaDoc {
185         super.setUp();
186
187         if (wc.getCurrentPage().getURL() == null) {
188             useWar("jonasAdmin");
189             // login to jonas admin
190
try {
191                 JonasAdminAuth.doValidAuth(wc, url);
192             } catch (Exception JavaDoc e) {
193                 fail("authentification failed : " + e);
194             }
195         } else {
196             // if there was an error, the connection must be restablished
197
try {
198                 wc.getFrameContents(FRAME_TREE);
199             } catch (Exception JavaDoc e) {
200                 wc.getResponse(urlLogOut);
201                 // login to jonas admin
202
try {
203                     JonasAdminAuth.doValidAuth(wc, url);
204                 } catch (Exception JavaDoc auth) {
205                     fail("authentification failed : " + auth);
206                 }
207             }
208         }
209     }
210
211     /**
212      * Test ejb container with alarm.ear
213      * @throws Exception if error occurs
214      *
215      */

216     public void testEjbContainer() throws Exception JavaDoc {
217
218         WebResponse wr;
219         WebLink link;
220         WebTable table;
221         WebTable tabTable;
222         TableCell selectedCell;
223         TableCell cell;
224         String JavaDoc ear = "alarm";
225         int selectedTab;
226         JonasAdminUtils utils = new JonasAdminUtils();
227
228         // Disable errors of javascript
229
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
230         // Disable exception thrown on error status
231
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
232
233         if (jProp.isEar() && jProp.isEjb()) {
234             // Add alarm.ear
235
useEar(ear);
236
237             // Go to ejb container
238
wr = wc.getFrameContents(FRAME_TREE);
239             link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_EJB_CONTAINER);
240             link.click();
241             wr = wc.getFrameContents(FRAME_CONTENT);
242
243             // Go to alarm.jar page
244
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, ear);
245             link.click();
246             wr = wc.getFrameContents(FRAME_CONTENT);
247             selectedTab = 2;
248
249             // Verify infos
250
table = utils.getTable(wr, 0);
251             cell = table.getTableCell(0,2);
252             // Name
253
assertEquals("It is not the name of the jar. ", ear, cell.getText());
254             // Path
255
cell = table.getTableCell(1, 2);
256             assertTrue("It is not the path of the jar file. ", cell.getText().endsWith(File.separator + "alarm.jar"));
257
258             // Verify tabs
259
tabTable = utils.getTabTable(wr);
260             testTabs(tabTable, NUMBER_OF_TABS_FOR_JAR, selectedTab);
261             // - links
262
assertTrue("The link " + URL_JONASADMIN_EJB_CONTAINER + " is not found in the first tab. ",
263                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EJB_CONTAINER));
264             assertTrue("The link " + URL_JONASADMIN_STATISTICS + " is not found in the third tab. ",
265                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_STATISTICS));
266             assertTrue("The link " + URL_JONASADMIN_VIEW_EJB + " is not found in the fourth tab. ",
267                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_VIEW_EJB));
268
269
270             // Go to the statistic tab
271
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_STATISTICS);
272             link.click();
273             wr = wc.getFrameContents(FRAME_CONTENT);
274             selectedTab = 3;
275
276             // Verify stats
277
table = utils.getTable(wr, 1);
278
279             int alarmBMP = Integer.parseInt(table.getTableCell(1, 2).getText());
280             int alarmCMP = Integer.parseInt(table.getTableCell(2, 2).getText());
281             int alarmStateful = Integer.parseInt(table.getTableCell(3, 2).getText());
282             int alarmStateless = Integer.parseInt(table.getTableCell(4, 2).getText());
283             int alarmMDB = Integer.parseInt(table.getTableCell(5, 2).getText());
284             int alarmTotal = Integer.parseInt(table.getTableCell(0, 2).getText());
285
286             assertEquals("It is not the number of Entity with Bean-Managed Persistence in alarm.jar. ", 0, alarmBMP);
287             assertEquals("It is not the number of Entity with Container-Managed Persistence in alarm.jar. ", 1, alarmCMP);
288             assertEquals("It is not the number of Stateful Session Bean in alarm.jar. ", 1, alarmStateful);
289             assertEquals("It is not the number of Stateless Session Bean in alarm.jar. ", 0, alarmStateless);
290             assertEquals("It is not the number of Message Driven Bean in alarm.jar. ", 1, alarmMDB);
291             assertEquals("It is not the number of EJBs in alarm.jar. ", 3, alarmTotal);
292
293             // Verify tabs
294
tabTable = utils.getTabTable(wr);
295             testTabs(tabTable, NUMBER_OF_TABS_FOR_JAR, selectedTab);
296             // - links
297
assertTrue("The link " + URL_JONASADMIN_EJB_CONTAINER + " is not found in the first tab. ",
298                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EJB_CONTAINER));
299             assertTrue("The link " + URL_JONASADMIN_CONTAINER_JSP + " is not found in the second tab. ",
300                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_CONTAINER_JSP));
301             assertTrue("The link " + URL_JONASADMIN_VIEW_EJB_JSP + " is not found in the fourth tab. ",
302                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_VIEW_EJB_JSP));
303
304
305             // Go to the Ejb tab
306
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_VIEW_EJB_JSP);
307             link.click();
308             wr = wc.getFrameContents(FRAME_CONTENT);
309             selectedTab = 4;
310
311             // Verify infos
312
table = utils.getTable(wr, 0);
313             // Name
314
cell = table.getTableCell(1, 0);
315             assertEquals("It is not the name of the EJB. ", "AlarmListener", cell.getText());
316             cell = table.getTableCell(2, 0);
317             assertEquals("It is not the name of the EJB. ", "AlarmRecord", cell.getText());
318             cell = table.getTableCell(3, 0);
319             assertEquals("It is not the name of the EJB. ", "View", cell.getText());
320             // Type
321
cell = table.getTableCell(1, 2);
322             assertEquals("It is not the type of the AlarmListener EJB. ", "MessageDrivenBean", cell.getText());
323             cell = table.getTableCell(2, 2);
324             assertEquals("It is not the type of the AlarmRecord EJB. ", "EntityBean", cell.getText());
325             cell = table.getTableCell(3, 2);
326             assertEquals("It is not the type of the View EJB. ", "StatefulSessionBean", cell.getText());
327
328             // Verify tabs
329
tabTable = utils.getTabTable(wr);
330             testTabs(tabTable, NUMBER_OF_TABS_FOR_JAR, selectedTab);
331             // - links
332
assertTrue("The link " + URL_JONASADMIN_EJB_CONTAINER + " is not found in the first tab. ",
333                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EJB_CONTAINER));
334             assertTrue("The link " + URL_JONASADMIN_CONTAINER + " is not found in the second tab. ",
335                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_CONTAINER));
336             assertTrue("The link " + URL_JONASADMIN_STATISTICS + " is not found in the third tab. ",
337                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_STATISTICS));
338
339
340             // Get links
341
int nbLink = table.getRowCount() -1;
342             WebLink[] links = new WebLink[nbLink];
343             WebResponse[] responses = new WebResponse[nbLink];
344             for (int i = 0; i < nbLink; i++) {
345                 links[i] = table.getTableCell(i + 1, 0).getLinks()[0];
346             }
347
348
349             /*
350              * Verify the MessageDrivenBean: AlarmListener
351              */

352             links[0].click();
353             responses[0] = wc.getFrameContents(FRAME_CONTENT);
354             selectedTab = 5;
355             table = utils.getTable(responses[0], 1);
356             // Name AlarmListener
357
assertEquals("It is not the name of the MessageDrivenBean. ", "AlarmListener", table.getTableCell(0, 2).getText());
358             // File .../alarm.jar
359
assertTrue("It is not the file of the MessageDrivenBean. ", table.getTableCell(1, 2).getText().endsWith("alarm.jar"));
360
361             // Naming and Classes
362
table = utils.getTable(responses[0], 4);
363             // EJB class org.objectweb.alarm.beans.AlarmListenerBean
364
assertEquals("It is not the EJB class of the MessageDrivenBean. ", "org.objectweb.alarm.beans.AlarmListenerBean", table.getTableCell(0, 2).getText());
365             // EJB JNDI Name AlarmListenerHome
366
assertEquals("It is not the EJB JNDI Name of the MessageDrivenBean. ", "AlarmListenerHome", table.getTableCell(1, 2).getText());
367             // EJB HomeClass
368
assertEquals("It is not the EJB HomeClass of the MessageDrivenBean. ", "", table.getTableCell(2, 2).getText());
369             // EJB RemoteClass
370
assertEquals("It is not the EJB RemoteClass of the MessageDrivenBean. ", "", table.getTableCell(3, 2).getText());
371             // EJB LocalHomeClass
372
assertEquals("It is not the EJB LocalHomeClass of the MessageDrivenBean. ", "", table.getTableCell(4, 2).getText());
373             // EJB LocalClass
374
assertEquals("It is not the EJB LocalClass of the MessageDrivenBean. ", "", table.getTableCell(5, 2).getText());
375
376             // Mdb Configuration
377
table = utils.getTable(responses[0], 7);
378             // JMS Destination name AlarmTopic
379
assertEquals("It is not the JMS Destination name of the MessageDrivenBean. ", "AlarmTopic", table.getTableCell(0, 2).getText());
380
381             // Verify tabs
382
tabTable = utils.getTabTable(responses[0]);
383             testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab);
384             // - links
385
assertTrue("The link " + URL_JONASADMIN_EJB_CONTAINER + " is not found in the first tab. ",
386                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EJB_CONTAINER));
387             assertTrue("The link " + URL_JONASADMIN_CONTAINER + " is not found in the second tab. ",
388                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_CONTAINER));
389             assertTrue("The link " + URL_JONASADMIN_STATISTICS + " is not found in the third tab. ",
390                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_STATISTICS));
391             assertTrue("The link " + URL_JONASADMIN_VIEW_EJB + " is not found in the fourth tab. ",
392                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_VIEW_EJB));
393             assertTrue("The link " + URL_JONASADMIN_DEPENDENCIES + " is not found in the sixth tab. ",
394                     tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPENDENCIES));
395
396             // Go to Dependency
397
link = responses[0].getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_DEPENDENCIES);
398             link.click();
399             responses[0] = wc.getFrameContents(FRAME_CONTENT);
400             selectedTab = 6;
401
402             // JMS Destination
403
table = utils.getTable(responses[0], 0);
404             assertEquals("The title of table is not 'JMS Destinastion'. ", "JMS Destination", table.getTableCell(0, 0).getText());
405             // Topic AlarmTopic
406
table = utils.getTable(responses[0], 1);
407             assertEquals("The JMS destination is not 'AlarmTopic'. ", "AlarmTopic", table.getTableCell(0, 2).getText());
408
409
410             // Verify tabs
411
tabTable = utils.getTabTable(responses[0]);
412             testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab);
413             // - links
414
assertTrue("The link " + URL_JONASADMIN_EJB_CONTAINER + " is not found in the first tab. ",
415                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EJB_CONTAINER));
416             assertTrue("The link " + URL_JONASADMIN_CONTAINER + " is not found in the second tab. ",
417                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_CONTAINER));
418             assertTrue("The link " + URL_JONASADMIN_STATISTICS + " is not found in the third tab. ",
419                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_STATISTICS));
420             assertTrue("The link " + URL_JONASADMIN_VIEW_EJB + " is not found in the fourth tab. ",
421                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_VIEW_EJB));
422             assertTrue("The link " + URL_JONASADMIN_MDB + " is not found in the sixth tab. ",
423                     tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_MDB));
424
425
426             /*
427              * Verify the StatefulSessionBean: View
428              */

429             links[2].click();
430             responses[2] = wc.getFrameContents(FRAME_CONTENT);
431             selectedTab = 5;
432             // StatefulSessionBean
433
table = utils.getTable(responses[2], 0);
434             assertEquals("The title of table is not 'StatefulSessionBean'. ", "StatefulSessionBean", table.getTableCell(0, 0).getText());
435
436             table = utils.getTable(responses[2], 1);
437             // Name AlarmListener
438
assertEquals("It is not the name of the StatefulSessionBean. ", "View", table.getTableCell(0, 2).getText());
439             // File .../alarm.jar
440
assertTrue("It is not the file of the StatefulSessionBean. ", table.getTableCell(1, 2).getText().endsWith("alarm.jar"));
441
442             // Naming and Classes
443
table = utils.getTable(responses[2], 4);
444             // EJB class org.objectweb.alarm.beans.ViewBean
445
assertEquals("It is not the EJB class of the StatefulSessionBean. ", "org.objectweb.alarm.beans.ViewBean", table.getTableCell(0, 2).getText());
446             // EJB JNDI Name viewhome
447
assertEquals("It is not the EJB JNDI Name of the StatefulSessionBean. ", "viewhome", table.getTableCell(1, 2).getText());
448             // EJB HomeClass org.objectweb.alarm.beans.ViewHome
449
assertEquals("It is not the EJB HomeClass of the StatefulSessionBean. ", "org.objectweb.alarm.beans.ViewHome", table.getTableCell(2, 2).getText());
450             // EJB RemoteClass org.objectweb.alarm.beans.View
451
assertEquals("It is not the EJB RemoteClass of the StatefulSessionBean. ", "org.objectweb.alarm.beans.View", table.getTableCell(3, 2).getText());
452             // EJB LocalHomeClass
453
assertEquals("It is not the EJB LocalHomeClass of the StatefulSessionBean. ", "", table.getTableCell(4, 2).getText());
454             // EJB LocalClass
455
assertEquals("It is not the EJB LocalClass of the StatefulSessionBean. ", "", table.getTableCell(5, 2).getText());
456
457             // Session Configuration
458
WebForm form = responses[2].getForms()[0];
459             // sessionTimeOut = 0
460
form.setParameter("sessionTimeOut", "0");
461             responses[2] = form.submit();
462             form = responses[2].getForms()[0];
463             assertTrue("The value of sessionTimeOut is not 'no limit'/'pas de limite'. ", form.getParameterValue("sessionTimeOut").indexOf("limit") != -1);
464             // sessionTimeOut = 10
465
form.setParameter("sessionTimeOut", "10");
466             responses[2] = form.submit();
467             form = responses[2].getForms()[0];
468             assertEquals("The value of sessionTimeOut is not '10'. ", "10", form.getParameterValue("sessionTimeOut"));
469             // empty
470
form.setParameter("sessionTimeOut", "");
471             responses[2] = form.submit();
472             form = responses[2].getForms()[0];
473             table = utils.getTable(responses[2], 0);
474             cell = table.getTableCell(0, 0);
475             assertEquals("There is not an error. ", "errors", cell.getAttribute("class"));
476             assertEquals("The message is not 'Session timeout cannot be empty'. ", "Session timeout cannot be empty", cell.getText());
477             // not a valid integer
478
form.setParameter("sessionTimeOut", "10.5");
479             responses[2] = form.submit();
480             form = responses[2].getForms()[0];
481             table = utils.getTable(responses[2], 0);
482             cell = table.getTableCell(0, 0);
483             assertEquals("There is not an error. ", "errors", cell.getAttribute("class"));
484             assertEquals("The message is not 'Session timeout not a valid integer !'. ", "Session timeout not a valid integer !", cell.getText());
485             // negative value
486
form.setParameter("sessionTimeOut", "-1");
487             responses[2] = form.submit();
488             table = utils.getTable(responses[2], 0);
489             cell = table.getTableCell(0, 0);
490             assertEquals("There is not an error. ", "errors", cell.getAttribute("class"));
491             assertFalse("There is no message. ", cell.getText().equals(""));
492
493
494             /*
495              * Verify the EntityBean: AlarmRecord
496              */

497             links[1].click();
498             responses[1] = wc.getFrameContents(FRAME_CONTENT);
499             selectedTab = 5;
500             // EntityBean
501
table = utils.getTable(responses[1], 3);
502             assertEquals("The title of table is not 'EntityBean'. ", "EntityBean", table.getTableCell(0, 0).getText());
503
504             table = utils.getTable(responses[1], 4);
505             // Name AlarmRecord
506
assertEquals("It is not the name of the EntityBean. ", "AlarmRecord", table.getTableCell(0, 2).getText());
507             // File .../alarm.jar
508
assertTrue("It is not the file of the EntityBean. ", table.getTableCell(1, 2).getText().endsWith("alarm.jar"));
509
510             // Naming and Classes
511
table = utils.getTable(responses[1], 7);
512             // EJB class org.objectweb.alarm.beans.AlarmRecordBean
513
assertEquals("It is not the EJB class of the EntityBean. ", "org.objectweb.alarm.beans.AlarmRecordBean", table.getTableCell(0, 2).getText());
514             // EJB JNDI Name alarmrecord
515
assertEquals("It is not the EJB JNDI Name of the EntityBean. ", "alarmrecord", table.getTableCell(1, 2).getText());
516             // EJB HomeClass org.objectweb.alarm.beans.AlarmRecordHome
517
assertEquals("It is not the EJB HomeClass of the EntityBean. ", "org.objectweb.alarm.beans.AlarmRecordHome", table.getTableCell(2, 2).getText());
518             // EJB RemoteClass org.objectweb.alarm.beans.AlarmRecord
519
assertEquals("It is not the EJB RemoteClass of the EntityBean. ", "org.objectweb.alarm.beans.AlarmRecord", table.getTableCell(3, 2).getText());
520             // EJB LocalHomeClass
521
assertEquals("It is not the EJB LocalHomeClass of the EntityBean. ", "", table.getTableCell(4, 2).getText());
522             // EJB LocalClass
523
assertEquals("It is not the EJB LocalClass of the EntityBean. ", "", table.getTableCell(5, 2).getText());
524
525             // Entity Configuration
526
table = utils.getTable(responses[1], 10);
527             // Persistency Container-Managed Type of Persistency (CMP/BMP)
528
assertEquals("It is not the persistency of the EntityBean. ", "Container-Managed", table.getTableCell(0, 2).getText());
529             // Passivation Timeout 0 Value in seconds
530
assertEquals("It is not the passivation timeout of the EntityBean. ", "0", table.getTableCell(1, 2).getText());
531             // Inactivity Timeout 0 Maximum time of inactivity (in sec.) before freeing objects
532
assertEquals("It is not the inactivity timeout of the EntityBean. ", "0", table.getTableCell(2, 2).getText());
533             // Lock Policy container-serialized one among CS/CRC/CRU/DB
534
assertEquals("It is not the lock policy of the EntityBean. ", "container-serialized", table.getTableCell(3, 2).getText());
535             // Shared false True if bean accessed outside this ejb server.
536
assertEquals("It is not the shared value of the EntityBean. ", "false", table.getTableCell(4, 2).getText());
537             // Prefetch false True if prefetch optimization wanted.
538
assertEquals("It is not the prefetch value of the EntityBean. ", "false", table.getTableCell(5, 2).getText());
539             // Initial Pool size 0 Nb of instances preallocated
540
assertEquals("It is not the initial pool size of the EntityBean. ", "0", table.getTableCell(6, 2).getText());
541             // Max number of instances 20 Max nb of instances in memory
542
assertEquals("It is not the max number of instances of the EntityBean. ", "20", table.getTableCell(7, 2).getText());
543
544             // Memory Management
545
int currentPoolSize;
546             int usedInTX;
547             int usedOutsideTX;
548             int unusedButReady;
549             int markedRemoved;
550             int currentNbInstances;
551             int passivated;
552             int total;
553             // Create instances
554
createInstances();
555             // Synchronize
556
link = responses[1].getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SYNCHRONIZE);
557             link.click();
558             responses[1] = wc.getFrameContents(FRAME_CONTENT);
559             table = utils.getTable(responses[1], 13);
560             currentPoolSize = Integer.parseInt(table.getTableCell(0, 2).getText());
561             usedInTX = Integer.parseInt(table.getTableCell(1, 2).getText());
562             usedOutsideTX = Integer.parseInt(table.getTableCell(2, 2).getText());
563             unusedButReady = Integer.parseInt(table.getTableCell(3, 2).getText());
564             markedRemoved = Integer.parseInt(table.getTableCell(4, 2).getText());
565             currentNbInstances = Integer.parseInt(table.getTableCell(5, 2).getText());
566             passivated = Integer.parseInt(table.getTableCell(6, 2).getText());
567             total = currentPoolSize + usedInTX + usedOutsideTX + unusedButReady + markedRemoved;
568             // Current number of instances 2
569
assertEquals("The current number of instances doesn't correspond to the sum of instances. ", total, currentNbInstances);
570             assertEquals("It is not the current number of instances. ", 2, currentNbInstances);
571             assertEquals("The number of passivated instances is not 0. ", 0, passivated);
572             // Reduce
573
link = responses[1].getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_REDUCE);
574             link.click();
575             responses[1] = wc.getFrameContents(FRAME_CONTENT);
576             table = utils.getTable(responses[1], 13);
577             // Current number of instances is less big than previous number of instances
578
int previousNbInstances = currentNbInstances;
579             currentNbInstances = Integer.parseInt(table.getTableCell(5, 2).getText());
580             passivated = Integer.parseInt(table.getTableCell(6, 2).getText());
581             assertTrue("The number of instances doesn't decrease when reduce button is clicked. ", previousNbInstances > currentNbInstances);
582             // Passivated > 0
583
assertTrue("The number of passivated instances is not positif. ", passivated > 0);
584
585
586             // Verify tabs
587
tabTable = utils.getTabTable(responses[1]);
588             testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab);
589             // - links
590
assertTrue("The link " + URL_JONASADMIN_EJB_CONTAINER + " is not found in the first tab. ",
591                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EJB_CONTAINER));
592             assertTrue("The link " + URL_JONASADMIN_CONTAINER + " is not found in the second tab. ",
593                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_CONTAINER));
594             assertTrue("The link " + URL_JONASADMIN_STATISTICS + " is not found in the third tab. ",
595                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_STATISTICS));
596             assertTrue("The link " + URL_JONASADMIN_VIEW_EJB + " is not found in the fourth tab. ",
597                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_VIEW_EJB));
598             assertTrue("The link " + URL_JONASADMIN_DEPENDENCIES + " is not found in the sixth tab. ",
599                     tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPENDENCIES));
600
601
602             // Go to Dependency
603
link = responses[1].getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_DEPENDENCIES);
604             link.click();
605             responses[1] = wc.getFrameContents(FRAME_CONTENT);
606             selectedTab = 6;
607
608             // Datasource
609
table = utils.getTable(responses[1], 0);
610             assertEquals("The title of table is not 'Datasource'. ", "Datasource", table.getTableCell(0, 0).getText());
611             // jdbc_1 postgres
612
table = utils.getTable(responses[1], 1);
613             assertEquals("It is not 'jdbc_1'. ", "jdbc_1", table.getTableCell(0, 0).getText());
614             assertEquals("The datasource is not 'postgres'. ", "postgres", table.getTableCell(0, 2).getText());
615             link = table.getTableCell(0, 2).getLinks()[0];
616             assertTrue("It is not the postgres URL. ", link.getURLString().endsWith("EditDatasource.do?name=postgres"));
617             assertEquals("The link is not correct. ", 200, wc.sendRequest(link.getRequest()).getResponseCode());
618
619             // Verify tabs
620
tabTable = utils.getTabTable(responses[1]);
621             testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab);
622             // - links
623
assertTrue("The link " + URL_JONASADMIN_EJB_CONTAINER + " is not found in the first tab. ",
624                     tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EJB_CONTAINER));
625             assertTrue("The link " + URL_JONASADMIN_CONTAINER + " is not found in the second tab. ",
626                     tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_CONTAINER));
627             assertTrue("The link " + URL_JONASADMIN_STATISTICS + " is not found in the third tab. ",
628                     tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_STATISTICS));
629             assertTrue("The link " + URL_JONASADMIN_VIEW_EJB + " is not found in the fourth tab. ",
630                     tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_VIEW_EJB));
631             assertTrue("The link " + URL_JONASADMIN_EB + " is not found in the sixth tab. ",
632                     tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EB));
633
634
635             /*
636              * TODO : verify the StatelessSessionBean
637              */

638         }
639
640
641     }
642
643     /**
644      * Test statistic
645      * @throws Exception if error occurs
646      *
647      */

648     public void testStatistics() throws Exception JavaDoc {
649
650         WebResponse wr;
651         WebLink link;
652         WebTable table;
653         WebTable tabTable;
654         TableCell selectedCell;
655         TableCell cell;
656         String JavaDoc ear = "alarm";
657         JonasAdminUtils utils = new JonasAdminUtils();
658
659         // Disable errors of javascript
660
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
661         // Disable exception thrown on error status
662
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
663
664         if (jProp.isEar() && jProp.isEjb()) {
665             // Add alarm.ear
666
useEar(ear);
667
668             // Go to ejb container
669
wr = wc.getFrameContents(FRAME_TREE);
670             link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_EJB_CONTAINER);
671             link.click();
672             wr = wc.getFrameContents(FRAME_CONTENT);
673
674             // Get jar Links
675
table = utils.getTable(wr, 0);
676             int nbLink = table.getRowCount() -1;
677             WebLink[] links = new WebLink[nbLink];
678             WebResponse[] responses = new WebResponse[nbLink];
679             WebTable tableStat;
680             int[] jarBMP = new int[nbLink];
681             int[] jarCMP = new int[nbLink];
682             int[] jarStateful = new int[nbLink];
683             int[] jarStateless = new int[nbLink];
684             int[] jarMDB = new int[nbLink];
685             int[] jarTotal = new int[nbLink];
686
687             int totalBMP = 0;
688             int totalCMP = 0;
689             int totalStateful = 0;
690             int totalStateless = 0;
691             int totalMDB = 0;
692             int totalTotal = 0;
693
694             int allBMP;
695             int allCMP;
696             int allStateful;
697             int allStateless;
698             int allMDB;
699             int allTotal;
700
701             // Go to statistics
702
link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_CONTAINERS_STATISTICS);
703             link.click();
704             wr = wc.getFrameContents(FRAME_CONTENT);
705             tableStat = utils.getTable(wr, 1);
706             allBMP = Integer.parseInt(tableStat.getTableCell(1, 2).getText());
707             allCMP = Integer.parseInt(tableStat.getTableCell(2, 2).getText());
708             allStateful = Integer.parseInt(tableStat.getTableCell(3, 2).getText());
709             allStateless = Integer.parseInt(tableStat.getTableCell(4, 2).getText());
710             allMDB = Integer.parseInt(tableStat.getTableCell(5, 2).getText());
711             allTotal = Integer.parseInt(tableStat.getTableCell(0, 2).getText());
712             int total = allBMP + allCMP + allStateful + allStateless + allMDB;
713             assertEquals("It is not the number of EJBs in all EJB containers. ", total, allTotal);
714
715             for (int i = 0; i < nbLink; i++) {
716                 links[i] = table.getTableCell(i + 1, 0).getLinks()[0];
717                 links[i].click();
718                 responses[i] = wc.getFrameContents(FRAME_CONTENT);
719
720                 // Go to the statistic tab
721
link = responses[i].getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_STATISTICS);
722                 link.click();
723                 wr = wc.getFrameContents(FRAME_CONTENT);
724                 // Verify stats
725
tableStat = utils.getTable(wr, 1);
726
727                 jarBMP[i] = Integer.parseInt(tableStat.getTableCell(1, 2).getText());
728                 jarCMP[i] = Integer.parseInt(tableStat.getTableCell(2, 2).getText());
729                 jarStateful[i] = Integer.parseInt(tableStat.getTableCell(3, 2).getText());
730                 jarStateless[i] = Integer.parseInt(tableStat.getTableCell(4, 2).getText());
731                 jarMDB[i] = Integer.parseInt(tableStat.getTableCell(5, 2).getText());
732                 jarTotal[i] = Integer.parseInt(tableStat.getTableCell(0, 2).getText());
733                 total = jarBMP[i] + jarCMP[i] + jarStateful[i] +jarStateless[i] + jarMDB[i];
734                 assertEquals("It is not the number of EJBs in " + links[i].getText(), total, jarTotal[i]);
735
736                 tableStat = utils.getTable(wr, 4);
737                 int allTmpBMP = Integer.parseInt(tableStat.getTableCell(1, 2).getText());
738                 int allTmpCMP = Integer.parseInt(tableStat.getTableCell(2, 2).getText());
739                 int allTmpStateful = Integer.parseInt(tableStat.getTableCell(3, 2).getText());
740                 int allTmpStateless = Integer.parseInt(tableStat.getTableCell(4, 2).getText());
741                 int allTmpMDB = Integer.parseInt(tableStat.getTableCell(5, 2).getText());
742                 int allTmpTotal = Integer.parseInt(tableStat.getTableCell(0, 2).getText());
743
744                 assertEquals("It is not the number of BMP in all EJB containers for the jar " + links[i].getText() + ". ", allBMP, allTmpBMP);
745                 assertEquals("It is not the number of CMP in all EJB containers for the jar " + links[i].getText() + ". ", allCMP, allTmpCMP);
746                 assertEquals("It is not the number of Stateful SB in all EJB containers for the jar " + links[i].getText() + ". ", allStateful, allTmpStateful);
747                 assertEquals("It is not the number of Stateless SB in all EJB containers for the jar " + links[i].getText() + ". ", allStateless, allTmpStateless);
748                 assertEquals("It is not the number of MDB in all EJB containers for the jar " + links[i].getText() + ". ", allMDB, allTmpMDB);
749                 assertEquals("It is not the number of all EJBs in all EJB containers for the jar " + links[i].getText() + ". ", allTotal, allTmpTotal);
750
751                 totalBMP += jarBMP[i];
752                 totalCMP += jarCMP[i];
753                 totalStateful += jarStateful[i];
754                 totalStateless += jarStateless[i];
755                 totalMDB += jarMDB[i];
756                 totalTotal += jarTotal[i];
757             }
758
759             assertEquals("It is not the number of all BMPs. ", totalBMP, allBMP);
760             assertEquals("It is not the number of all CMPs. ", totalCMP, allCMP);
761             assertEquals("It is not the number of all stateful SBs. ", totalStateful, allStateful);
762             assertEquals("It is not the number of all stateless SBs. ", totalStateless, allStateless);
763             assertEquals("It is not the number of all MDBs. ", totalMDB, allMDB);
764             assertEquals("It is not the number of all EJBs. ", totalTotal, allTotal);
765         }
766     }
767
768     /**
769      * Verify number of tabs and the selected tab
770      * @param tabTable the tab table
771      * @param nbTabs number of tabs
772      * @param selectedTab the numero of the selected tab
773      */

774     private void testTabs(WebTable tabTable, int nbTabs, int selectedTab) {
775         TableCell selectedCell;
776         // - number of tabs
777
assertEquals("There are not " + nbTabs + " tabs. ",
778                 nbTabs, (tabTable.getColumnCount() + 1) / 2);
779         // - selected tab
780
selectedCell = tabTable.getTableCell(1, (selectedTab * 2) - 2);
781         assertEquals("It is not the selected tab. ", 1, selectedCell.getElementsWithAttribute("src", "/jonasAdmin/images/dot.gif").length);
782     }
783
784     /**
785      * Use Alarm Demo for creating instances
786      * @throws Exception if an error occurs
787      */

788     private void createInstances() throws Exception JavaDoc {
789         WebConversation wc2 = new WebConversation();
790         String JavaDoc urlAlarm = prefixUrl + "/alarm/secured/list.jsp";
791         // Start the alarm demo
792
wc2.setAuthorization("jonas", "jonas");
793         WebResponse wr = wc2.getResponse(urlAlarm);
794     }
795
796 }
797
Popular Tags