1 25 26 package org.objectweb.jonas.jonasadmin.test.service.container; 27 28 import java.io.File ; 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 49 public class F_JonasAdminEjbContainer extends JonasAdminTestCase { 50 51 54 private static final String URL_JONASADMIN_EJB_CONTAINER = "ListContainers.do"; 55 56 59 private static final String URL_JONASADMIN_CONTAINER = "/ViewContainer.do"; 60 61 64 private static final String URL_JONASADMIN_CONTAINER_JSP = "/jonasAdmin/service/container.jsp"; 65 66 69 private static final String URL_JONASADMIN_STATISTICS = "/EditContainerStatistic.do"; 70 71 74 private static final String URL_JONASADMIN_CONTAINERS_STATISTICS = "EditEjbContainersStatistic.do"; 75 76 79 private static final String URL_JONASADMIN_VIEW_EJB = "/ViewContainerEjbs.do"; 80 81 84 private static final String URL_JONASADMIN_MDB = "write url of MDB tab"; 85 86 89 private static final String URL_JONASADMIN_EB = "write url of EB tab"; 90 91 94 private static final String URL_JONASADMIN_VIEW_EJB_JSP = "/jonasAdmin/service/containerEjbs.jsp"; 95 96 99 private static final String URL_JONASADMIN_DEPENDENCIES = "/jonasAdmin/service/ejbDependency.jsp"; 100 101 104 private static final String URL_JONASADMIN_SYNCHRONIZE = "ExecuteEjb.do?action=synchronize"; 105 106 109 private static final String URL_JONASADMIN_REDUCE = "ExecuteEjb.do?action=reduceCache"; 110 111 114 private static final int NUMBER_OF_TABS_FOR_JAR = 4; 115 116 119 private static final int NUMBER_OF_TABS_FOR_MDB = 6; 120 121 125 public F_JonasAdminEjbContainer(String s) { 126 super(s, URL_JONASADMIN); 127 } 128 129 134 public F_JonasAdminEjbContainer(WebConversation wc, String s) { 135 super(wc, s, URL_JONASADMIN); 136 } 137 138 142 public static void main(String [] args) { 143 144 String testtorun = null; 145 for (int argn = 0; argn < args.length; argn++) { 147 String 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 163 public static TestSuite suite() { 164 return new TestSuite(F_JonasAdminEjbContainer.class); 165 } 166 167 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 184 protected void setUp() throws Exception { 185 super.setUp(); 186 187 if (wc.getCurrentPage().getURL() == null) { 188 useWar("jonasAdmin"); 189 try { 191 JonasAdminAuth.doValidAuth(wc, url); 192 } catch (Exception e) { 193 fail("authentification failed : " + e); 194 } 195 } else { 196 try { 198 wc.getFrameContents(FRAME_TREE); 199 } catch (Exception e) { 200 wc.getResponse(urlLogOut); 201 try { 203 JonasAdminAuth.doValidAuth(wc, url); 204 } catch (Exception auth) { 205 fail("authentification failed : " + auth); 206 } 207 } 208 } 209 } 210 211 216 public void testEjbContainer() throws Exception { 217 218 WebResponse wr; 219 WebLink link; 220 WebTable table; 221 WebTable tabTable; 222 TableCell selectedCell; 223 TableCell cell; 224 String ear = "alarm"; 225 int selectedTab; 226 JonasAdminUtils utils = new JonasAdminUtils(); 227 228 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 230 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 232 233 if (jProp.isEar() && jProp.isEjb()) { 234 useEar(ear); 236 237 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 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, ear); 245 link.click(); 246 wr = wc.getFrameContents(FRAME_CONTENT); 247 selectedTab = 2; 248 249 table = utils.getTable(wr, 0); 251 cell = table.getTableCell(0,2); 252 assertEquals("It is not the name of the jar. ", ear, cell.getText()); 254 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 tabTable = utils.getTabTable(wr); 260 testTabs(tabTable, NUMBER_OF_TABS_FOR_JAR, selectedTab); 261 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 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_STATISTICS); 272 link.click(); 273 wr = wc.getFrameContents(FRAME_CONTENT); 274 selectedTab = 3; 275 276 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 tabTable = utils.getTabTable(wr); 295 testTabs(tabTable, NUMBER_OF_TABS_FOR_JAR, selectedTab); 296 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 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 table = utils.getTable(wr, 0); 313 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 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 tabTable = utils.getTabTable(wr); 330 testTabs(tabTable, NUMBER_OF_TABS_FOR_JAR, selectedTab); 331 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 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 352 links[0].click(); 353 responses[0] = wc.getFrameContents(FRAME_CONTENT); 354 selectedTab = 5; 355 table = utils.getTable(responses[0], 1); 356 assertEquals("It is not the name of the MessageDrivenBean. ", "AlarmListener", table.getTableCell(0, 2).getText()); 358 assertTrue("It is not the file of the MessageDrivenBean. ", table.getTableCell(1, 2).getText().endsWith("alarm.jar")); 360 361 table = utils.getTable(responses[0], 4); 363 assertEquals("It is not the EJB class of the MessageDrivenBean. ", "org.objectweb.alarm.beans.AlarmListenerBean", table.getTableCell(0, 2).getText()); 365 assertEquals("It is not the EJB JNDI Name of the MessageDrivenBean. ", "AlarmListenerHome", table.getTableCell(1, 2).getText()); 367 assertEquals("It is not the EJB HomeClass of the MessageDrivenBean. ", "", table.getTableCell(2, 2).getText()); 369 assertEquals("It is not the EJB RemoteClass of the MessageDrivenBean. ", "", table.getTableCell(3, 2).getText()); 371 assertEquals("It is not the EJB LocalHomeClass of the MessageDrivenBean. ", "", table.getTableCell(4, 2).getText()); 373 assertEquals("It is not the EJB LocalClass of the MessageDrivenBean. ", "", table.getTableCell(5, 2).getText()); 375 376 table = utils.getTable(responses[0], 7); 378 assertEquals("It is not the JMS Destination name of the MessageDrivenBean. ", "AlarmTopic", table.getTableCell(0, 2).getText()); 380 381 tabTable = utils.getTabTable(responses[0]); 383 testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab); 384 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 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 table = utils.getTable(responses[0], 0); 404 assertEquals("The title of table is not 'JMS Destinastion'. ", "JMS Destination", table.getTableCell(0, 0).getText()); 405 table = utils.getTable(responses[0], 1); 407 assertEquals("The JMS destination is not 'AlarmTopic'. ", "AlarmTopic", table.getTableCell(0, 2).getText()); 408 409 410 tabTable = utils.getTabTable(responses[0]); 412 testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab); 413 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 429 links[2].click(); 430 responses[2] = wc.getFrameContents(FRAME_CONTENT); 431 selectedTab = 5; 432 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 assertEquals("It is not the name of the StatefulSessionBean. ", "View", table.getTableCell(0, 2).getText()); 439 assertTrue("It is not the file of the StatefulSessionBean. ", table.getTableCell(1, 2).getText().endsWith("alarm.jar")); 441 442 table = utils.getTable(responses[2], 4); 444 assertEquals("It is not the EJB class of the StatefulSessionBean. ", "org.objectweb.alarm.beans.ViewBean", table.getTableCell(0, 2).getText()); 446 assertEquals("It is not the EJB JNDI Name of the StatefulSessionBean. ", "viewhome", table.getTableCell(1, 2).getText()); 448 assertEquals("It is not the EJB HomeClass of the StatefulSessionBean. ", "org.objectweb.alarm.beans.ViewHome", table.getTableCell(2, 2).getText()); 450 assertEquals("It is not the EJB RemoteClass of the StatefulSessionBean. ", "org.objectweb.alarm.beans.View", table.getTableCell(3, 2).getText()); 452 assertEquals("It is not the EJB LocalHomeClass of the StatefulSessionBean. ", "", table.getTableCell(4, 2).getText()); 454 assertEquals("It is not the EJB LocalClass of the StatefulSessionBean. ", "", table.getTableCell(5, 2).getText()); 456 457 WebForm form = responses[2].getForms()[0]; 459 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 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 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 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 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 497 links[1].click(); 498 responses[1] = wc.getFrameContents(FRAME_CONTENT); 499 selectedTab = 5; 500 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 assertEquals("It is not the name of the EntityBean. ", "AlarmRecord", table.getTableCell(0, 2).getText()); 507 assertTrue("It is not the file of the EntityBean. ", table.getTableCell(1, 2).getText().endsWith("alarm.jar")); 509 510 table = utils.getTable(responses[1], 7); 512 assertEquals("It is not the EJB class of the EntityBean. ", "org.objectweb.alarm.beans.AlarmRecordBean", table.getTableCell(0, 2).getText()); 514 assertEquals("It is not the EJB JNDI Name of the EntityBean. ", "alarmrecord", table.getTableCell(1, 2).getText()); 516 assertEquals("It is not the EJB HomeClass of the EntityBean. ", "org.objectweb.alarm.beans.AlarmRecordHome", table.getTableCell(2, 2).getText()); 518 assertEquals("It is not the EJB RemoteClass of the EntityBean. ", "org.objectweb.alarm.beans.AlarmRecord", table.getTableCell(3, 2).getText()); 520 assertEquals("It is not the EJB LocalHomeClass of the EntityBean. ", "", table.getTableCell(4, 2).getText()); 522 assertEquals("It is not the EJB LocalClass of the EntityBean. ", "", table.getTableCell(5, 2).getText()); 524 525 table = utils.getTable(responses[1], 10); 527 assertEquals("It is not the persistency of the EntityBean. ", "Container-Managed", table.getTableCell(0, 2).getText()); 529 assertEquals("It is not the passivation timeout of the EntityBean. ", "0", table.getTableCell(1, 2).getText()); 531 assertEquals("It is not the inactivity timeout of the EntityBean. ", "0", table.getTableCell(2, 2).getText()); 533 assertEquals("It is not the lock policy of the EntityBean. ", "container-serialized", table.getTableCell(3, 2).getText()); 535 assertEquals("It is not the shared value of the EntityBean. ", "false", table.getTableCell(4, 2).getText()); 537 assertEquals("It is not the prefetch value of the EntityBean. ", "false", table.getTableCell(5, 2).getText()); 539 assertEquals("It is not the initial pool size of the EntityBean. ", "0", table.getTableCell(6, 2).getText()); 541 assertEquals("It is not the max number of instances of the EntityBean. ", "20", table.getTableCell(7, 2).getText()); 543 544 int currentPoolSize; 546 int usedInTX; 547 int usedOutsideTX; 548 int unusedButReady; 549 int markedRemoved; 550 int currentNbInstances; 551 int passivated; 552 int total; 553 createInstances(); 555 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 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 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 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 assertTrue("The number of passivated instances is not positif. ", passivated > 0); 584 585 586 tabTable = utils.getTabTable(responses[1]); 588 testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab); 589 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 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 table = utils.getTable(responses[1], 0); 610 assertEquals("The title of table is not 'Datasource'. ", "Datasource", table.getTableCell(0, 0).getText()); 611 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 tabTable = utils.getTabTable(responses[1]); 621 testTabs(tabTable, NUMBER_OF_TABS_FOR_MDB, selectedTab); 622 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 638 } 639 640 641 } 642 643 648 public void testStatistics() throws Exception { 649 650 WebResponse wr; 651 WebLink link; 652 WebTable table; 653 WebTable tabTable; 654 TableCell selectedCell; 655 TableCell cell; 656 String ear = "alarm"; 657 JonasAdminUtils utils = new JonasAdminUtils(); 658 659 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 661 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 663 664 if (jProp.isEar() && jProp.isEjb()) { 665 useEar(ear); 667 668 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 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 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 link = responses[i].getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_STATISTICS); 722 link.click(); 723 wr = wc.getFrameContents(FRAME_CONTENT); 724 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 774 private void testTabs(WebTable tabTable, int nbTabs, int selectedTab) { 775 TableCell selectedCell; 776 assertEquals("There are not " + nbTabs + " tabs. ", 778 nbTabs, (tabTable.getColumnCount() + 1) / 2); 779 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 788 private void createInstances() throws Exception { 789 WebConversation wc2 = new WebConversation(); 790 String urlAlarm = prefixUrl + "/alarm/secured/list.jsp"; 791 wc2.setAuthorization("jonas", "jonas"); 793 WebResponse wr = wc2.getResponse(urlAlarm); 794 } 795 796 } 797 | Popular Tags |