1 25 26 package org.objectweb.jonas.jonasadmin.test.navigation; 27 28 import java.io.IOException ; 29 import java.util.Vector ; 30 31 import junit.framework.TestSuite; 32 33 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth; 34 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles; 35 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase; 36 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTree; 37 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils; 38 import org.xml.sax.SAXException ; 39 40 import com.meterware.httpunit.HttpException; 41 import com.meterware.httpunit.HttpNotFoundException; 42 import com.meterware.httpunit.HttpUnitOptions; 43 import com.meterware.httpunit.TableCell; 44 import com.meterware.httpunit.WebConversation; 45 import com.meterware.httpunit.WebLink; 46 import com.meterware.httpunit.WebResponse; 47 import com.meterware.httpunit.WebTable; 48 49 55 public class F_JonasAdminNavigation extends JonasAdminTestCase { 56 57 60 private static final int HTTP_SUCCESS_CODE = 200; 61 62 65 private static final String EAR_LINK_NAME = "Applications (EAR)"; 66 67 70 private static final String URL_JONASADMIN_ALARM_RECORD = "/jonasAdmin/EditEjbEnt.do?select=jonas:j2eeType=EntityBean,name=AlarmRecord,EJBModule=alarm,J2EEApplication=alarm,J2EEServer=jonas"; 71 72 75 private static final String URL_JONASADMIN_SYNCHRONIZE = "/jonasAdmin/ExecuteEjb.do?action=synchronize"; 76 77 80 private static final String URL_JONASADMIN_REDUCE = "/jonasAdmin/ExecuteEjb.do?action=reduceCache"; 81 82 85 private static final String URL_JONASADMIN_REDUCE_POOL = "/jonasAdmin/ExecuteEjb.do?action=reducePool"; 86 87 90 private static final String URL_JONASADMIN_NEW_GROUP = "/jonasAdmin/EditNewGroupMemoryRealm.do?action=create"; 91 92 95 private static final String URL_JONASADMIN_NEW_USER = "/jonasAdmin/EditNewUserMemoryRealm.do?action=create"; 96 97 100 private static final String CLASS_TREE_CONTROL_SELECTED = "tree-control-selected"; 101 102 105 private static final String NAVIGATION_MBEAN = "navigation.mbean"; 106 107 110 private static final String NAVIGATION_LINK = "navigation.link"; 111 112 115 private static final String NAVIGATION_CONTENT_TITLE = "navigation.contentTitle"; 116 117 120 private static final String NAVIGATION_SELECTED_ITEM = "navigation.selectedItem"; 121 122 125 private static final String NAVIGATION_TITLE_TOM_THUMB = "navigation.titleTomThumb"; 126 127 130 private static final String NAVIGATION_RAR_IN_EAR = "navigation.rarInEar"; 131 132 135 private String beginTime; 136 137 140 private String endTime; 141 142 143 147 public F_JonasAdminNavigation(String s) { 148 super(s, URL_JONASADMIN); 149 } 150 151 156 public F_JonasAdminNavigation(WebConversation wc, String s) { 157 super(wc, s, URL_JONASADMIN); 158 } 159 160 164 public static void main(String [] args) { 165 166 String testtorun = null; 167 for (int argn = 0; argn < args.length; argn++) { 169 String sArg = args[argn]; 170 if (sArg.equals("-n")) { 171 testtorun = args[++argn]; 172 } 173 } 174 if (testtorun == null) { 175 junit.textui.TestRunner.run(suite()); 176 } else { 177 junit.textui.TestRunner.run(new F_JonasAdminNavigation(testtorun)); 178 } 179 } 180 181 185 public static TestSuite suite() { 186 return new TestSuite(F_JonasAdminNavigation.class); 187 } 188 189 194 public static TestSuite suite(WebConversation wc) { 195 TestSuite suite = new TestSuite(); 196 suite.addTest(new F_JonasAdminNavigation(wc, "testAll")); 197 return suite; 198 } 199 200 205 protected void setUp() throws Exception { 206 super.setUp(); 207 208 beginTime = getTime(); 210 211 if (wc.getCurrentPage().getURL() == null) { 212 useWar("jonasAdmin"); 213 try { 215 JonasAdminAuth.doValidAuth(wc, url); 216 } catch (Exception e) { 217 fail("authentification failed : " + e); 218 } 219 } else { 220 try { 222 wc.getFrameContents(FRAME_TREE); 223 } catch (Exception e) { 224 wc.getResponse(urlLogOut); 225 try { 227 JonasAdminAuth.doValidAuth(wc, url); 228 } catch (Exception auth) { 229 fail("authentification failed : " + auth); 230 } 231 } 232 } 233 undeployAllEar(); 234 undeployAllJar(); 235 236 useEar("autoload/mejb"); 237 } 238 239 244 public void testAll() throws Exception { 245 246 Vector viewedURLs = new Vector (); 247 WebResponse wr; 248 249 viewedURLs.add(URL_JONASADMIN); 250 251 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 253 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 255 256 if (jProp.isEar()) { 259 useEar("alarm"); 260 if (jProp.isResource()) { 261 if (configFile != null) { 262 if (configFile.get(NAVIGATION_RAR_IN_EAR).equals("on")) { 263 useEar("earsample"); 264 } 265 } else { 266 useEar("earsample"); 267 } 268 } 269 wc.getResponse(getAbsoluteUrl(URL_JONASADMIN)); 271 } 272 273 WebResponse treeFrame = wc.getFrameContents(FRAME_TREE); 275 276 try { 278 treeFrame = JonasAdminTree.openTree(treeFrame, wc); 279 } catch (IOException e) { 280 fail("failed to open tree. " + e); 281 } 282 283 if (jProp.isEjb()) { 285 testParticularCase("name=AlarmRecord", "synchronize", URL_JONASADMIN_SYNCHRONIZE, viewedURLs); 288 289 testParticularCase("name=AlarmRecord", "reduceCache", URL_JONASADMIN_REDUCE, viewedURLs); 291 292 testParticularCase("EditEjbSbl.do?select=jonas:j2eeType=StatelessSessionBean,name=MEJB,EJBModule=mejb,J2EEApplication=mejb,J2EEServer=jonas", "reducePool", URL_JONASADMIN_REDUCE_POOL, viewedURLs); 294 } 295 296 testParticularCase("memrlm_1", "Groups.do", "action=create", URL_JONASADMIN_NEW_GROUP, viewedURLs); 298 299 testParticularCase("memrlm_1", "Users.do", "action=create", URL_JONASADMIN_NEW_USER, viewedURLs); 301 302 try { 304 verifyLinks(treeFrame, viewedURLs); 305 } catch (IOException e) { 306 throw new IllegalStateException ("Problem to verify all links. " + e); 307 } catch (Exception e) { 308 throw new IllegalStateException ("Problem to verify all links. " + e); 309 } 310 311 if (configFile.get(NAVIGATION_MBEAN).equals("on")) { 313 testMBean(viewedURLs); 314 } 315 } 316 317 324 public void verifyLinks(WebResponse frame, Vector viewedURLs) throws Exception , IOException { 325 326 WebLink[] links = null; 327 328 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 330 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 332 333 links = frame.getLinks(); 335 WebResponse wr; 336 337 for (int i = 0; i < links.length; i++) { 338 if (links[i].getURLString().indexOf("viewTree.do") == -1 && links[i].getURLString().indexOf("ListMBeanDetails.do") == -1 && links[i].getURLString().indexOf("://") == -1) { 340 if (!viewedURLs.contains(links[i].getURLString())) { 341 executeTests(frame, links[i], viewedURLs); 342 343 WebResponse contentFrame = wc.getFrameContents(FRAME_CONTENT); 345 verifyLinks(contentFrame, viewedURLs); 346 } 347 } 348 } 349 } 350 351 359 private void testParticularCase(String treeLink, String contentLink, String url, Vector viewedURLs) throws Exception { 360 WebLink link; 361 WebResponse wr; 362 WebResponse frame; 363 364 frame = wc.getFrameContents(FRAME_TREE); 365 link = frame.getFirstMatchingLink( WebLink.MATCH_URL_STRING, treeLink); 366 if (link == null) { 367 throw new IllegalStateException ("No link found for treelink : '" + treeLink + "'."); 368 } 369 wr = link.click(); 370 371 frame = wc.getFrameContents(FRAME_CONTENT); 372 link = frame.getFirstMatchingLink( WebLink.MATCH_URL_STRING, contentLink); 373 374 if (link == null) { 375 throw new IllegalStateException ("No link found for treelink : '" + treeLink + "'."); 376 } 377 executeTests(frame, link, viewedURLs); 378 } 379 380 389 private void testParticularCase(String treeLink, String contentLink, String contentLink2, String url, Vector viewedURLs) throws Exception { 390 391 WebLink link; 392 WebResponse wr; 393 WebResponse frame; 394 395 frame = wc.getFrameContents(FRAME_TREE); 396 link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING, treeLink); 397 if (link == null) { 398 throw new IllegalStateException ("No link found for treelink : '" + treeLink + "'."); 399 } 400 wr = link.click(); 401 402 frame = wc.getFrameContents(FRAME_CONTENT); 403 link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING, contentLink); 404 if (link == null) { 405 throw new IllegalStateException ("No link found for contentLink : '" + contentLink + "'."); 406 } 407 wr = link.click(); 408 409 frame = wc.getFrameContents(FRAME_CONTENT); 410 link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING, contentLink2); 411 if (link == null) { 412 throw new IllegalStateException ("No link found for contentLink2 : '" + contentLink2 + "'."); 413 } 414 415 executeTests(frame, link, viewedURLs); 416 } 417 418 425 private void executeTests(WebResponse frame, WebLink link, Vector viewedURLs) throws SAXException { 426 427 WebResponse wr; 428 try { 429 wr = link.click(); 430 if (configFile.get(NAVIGATION_LINK).equals("on")) { 432 testLinks(wr); 433 } 434 } catch (HttpNotFoundException e) { 435 if (configFile.get(NAVIGATION_LINK).equals("on")) { 436 fail("failed to click : link = " + link.getText() + ", URL = " + link.getURLString() + ", page = " + viewedURLs.lastElement() + ". " + e); 437 } 438 } catch (HttpException e) { 439 if (configFile.get(NAVIGATION_LINK).equals("on")) { 440 fail("failed to click : link = " + link.getText() + ", URL = " + link.getURLString() + ", page = " + viewedURLs.lastElement() + ". " + e); 441 } 442 } catch (IOException e) { 443 if (configFile.get(NAVIGATION_LINK).equals("on")) { 444 fail("failed to click : link = " + link.getText() + ", URL = " + link.getURLString() + ", page = " + viewedURLs.lastElement() + ". " + e); 445 } 446 } 447 448 if (configFile.get(NAVIGATION_CONTENT_TITLE).equals("on")) { 450 testContentTitle(link.getURLString()); 451 } 452 453 if (frame.getFrameName().equalsIgnoreCase(FRAME_TREE)) { 455 if (configFile.get(NAVIGATION_SELECTED_ITEM).equals("on")) { 456 testTreeSelected(link.getURLString()); 457 } 458 } 459 460 if (configFile.get(NAVIGATION_TITLE_TOM_THUMB).equals("on")) { 462 testTitleTomThumb(link.getURLString()); 463 } 464 465 viewedURLs.add(link.getURLString()); 467 } 468 469 473 private void testLinks(WebResponse wr) { 474 assertEquals("a code of 200 (success) should be returned. ", HTTP_SUCCESS_CODE, wr.getResponseCode()); 475 } 476 477 482 private void testContentTitle(String url) throws SAXException { 483 484 WebResponse tree = null; 485 WebResponse content = null; 486 String treeTitle = null; 487 String contentTitle = null; 488 489 content = wc.getFrameContents(FRAME_CONTENT); 491 tree = wc.getFrameContents(FRAME_TREE); 492 493 if (tree.getElementsWithAttribute("class", CLASS_TREE_CONTROL_SELECTED).length == 1) { 495 treeTitle = new String (tree.getElementsWithAttribute("class", CLASS_TREE_CONTROL_SELECTED)[0].getText()); 496 } 497 498 if (content.getElementsWithAttribute("class", "contentTitle").length == 1) { 500 contentTitle = new String (content.getElementsWithAttribute("class", "contentTitle")[0].getText()); 501 } 502 if (treeTitle != null && contentTitle != null) { 503 assertEquals("The content title (" + contentTitle + ") is different of the link name (" + treeTitle + "). Clicked link was " + url, treeTitle, contentTitle); 504 } else { 505 if (!url.equals(URL_JONASADMIN)) { 506 if (treeTitle != null) { 507 try { 508 fail("Content title is null. Name of the selected link was " + treeTitle + ". Link URL: " + url + " Content frame: " + content.getText()); 509 } catch (IOException e) { 510 fail("Content title is null. Name of the selected link was " + treeTitle + ". Link URL: " + url + " Error to get content frame text"); 511 } 512 } else { 513 if (contentTitle != null) { 514 fail("No link is selected. Content title was " + contentTitle); 515 } else { 516 try { 517 fail("No link and no content title are found. Tree frame: " + tree.getText() + ". Content frame: " + content.getText()); 518 } catch (IOException e) { 519 fail("No link and no content title are found because there is a problem in tree frame or content frame. "); 520 } 521 } 522 } 523 } 524 } 525 526 content = null; 528 tree = null; 529 } 530 531 535 private void testTreeSelected(String selectedLink) { 536 537 WebResponse tree = null; 538 539 tree = wc.getFrameContents(FRAME_TREE); 541 542 try { 543 if (!JonasAdminTree.treeControlSelected(tree, selectedLink)) { 544 fail("The name of the link " + selectedLink + " is not selected in the tree."); 545 } 546 } catch (SAXException sax) { 547 fail("" + sax); 548 } 549 550 tree = null; 551 } 552 553 557 private void testTitleTomThumb(String url) { 558 WebResponse contentFrame = wc.getFrameContents(FRAME_CONTENT); 559 WebResponse treeFrame = wc.getFrameContents(FRAME_TREE); 560 WebTable thumbTable = null; 561 WebTable treeTable = null; 562 TableCell thumbCell = null; 563 TableCell treeCell = null; 564 String text = null; 565 String [] thumbs = null; 566 String [] treeThumbs = null; 567 JonasAdminUtils utils = new JonasAdminUtils(); 568 int row; 569 int column; 570 571 try { 572 thumbTable = contentFrame.getTables()[0]; 573 } catch (SAXException e) { 574 fail("There is no table in content frame: " + e); 575 } 576 577 thumbCell = thumbTable.getTableCell(0, 0); 578 text = thumbCell.getText(); 579 thumbs = text.split(" > "); 580 581 582 try { 583 treeTable = treeFrame.getTables()[0]; 584 } catch (SAXException e) { 585 fail("There is no table in tree frame: " + e); 586 } 587 JonasAdminUtils.CoordCell coord = utils.getSelectedItemRow(treeTable); 588 589 if (!url.equals(URL_JONASADMIN)) { 590 row = coord.getRow().intValue(); 591 column = coord.getColumn().intValue(); 592 treeThumbs = new String [thumbs.length]; 594 int i = thumbs.length; 595 while (row > 0 && column > 3 && i > 0) { 596 boolean found = false; 597 column--; 598 i--; 599 int nextRow = row; 601 while (nextRow > 0 && !found) { 602 nextRow--; 603 treeCell = treeTable.getTableCell(nextRow, column-2); 604 if (treeCell.getElementsWithAttribute("src", "images/tree/node_open_middle.gif").length == 1) { 605 treeCell = treeTable.getTableCell(nextRow, column); 606 treeThumbs[i] = treeCell.getText(); 607 found = true; 608 assertEquals("For the link " + url, treeThumbs[i], thumbs[i]); 609 } else if (treeCell.getElementsWithAttribute("src", "images/tree/node_open_last.gif").length == 1) { 610 treeCell = treeTable.getTableCell(nextRow, column); 611 treeThumbs[i] = treeCell.getText(); 612 found = true; 613 assertEquals("For the link " + url, treeThumbs[i], thumbs[i]); 614 } else if (treeCell.getElementsWithAttribute("src", "images/tree/node_open_first.gif").length == 1) { 615 treeCell = treeTable.getTableCell(nextRow, column); 616 treeThumbs[i] = treeCell.getText(); 617 found = true; 618 assertEquals("For the link " + url, treeThumbs[i], thumbs[i]); 619 } else if (treeCell.getElementsWithAttribute("src", "images/tree/node_open.gif").length == 1) { 620 treeCell = treeTable.getTableCell(nextRow, column); 621 treeThumbs[i] = treeCell.getText(); 622 found = true; 623 assertEquals("For the link " + url, treeThumbs[i], thumbs[i]); 624 } 625 } 626 row = nextRow; 627 } 628 } 629 } 630 631 635 private void testMBean(Vector viewedURLs) throws Exception { 636 WebResponse wr = wc.getFrameContents(FRAME_TREE); 637 WebLink link; 638 639 if (wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*j2ee") == null) { 641 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans"); 642 if (link == null) { 643 throw new IllegalStateException ("The link viewTree.do?domain*mbeans is not found in tree. "); 644 } 645 wr = link.click(); 646 } 647 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*j2ee"); 649 if (link == null) { 650 throw new IllegalStateException ("The link viewTree.do?domain*mbeans*j2ee is not found in tree. "); 651 } 652 wr = link.click(); 653 654 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*j2ee*"); 655 if (link == null) { 656 throw new IllegalStateException ("The link viewTree.do?domain*mbeans*j2ee* is not found in tree. "); 657 } 658 wr = link.click(); 659 660 link = wr.getMatchingLinks(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*j2ee*")[1]; 661 if (link == null) { 662 throw new IllegalStateException ("The 2nd link viewTree.do?domain*mbeans*j2ee* is not found in tree. "); 663 } 664 wr = link.click(); 665 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*owner"); 667 if (link == null) { 668 throw new IllegalStateException ("The link viewTree.do?domain*mbeans*owner is not found in tree. "); 669 } 670 wr = link.click(); 671 672 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*owner*"); 673 if (link == null) { 674 throw new IllegalStateException ("The link viewTree.do?domain*mbeans*owner* is not found in tree. "); 675 } 676 wr = link.click(); 677 678 link = wr.getMatchingLinks(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*owner*")[1]; 679 if (link == null) { 680 throw new IllegalStateException ("The 2nd link viewTree.do?domain*mbeans*owner* is not found in tree. "); 681 } 682 wr = link.click(); 683 684 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*unknown"); 686 if (link == null) { 687 throw new IllegalStateException ("The link viewTree.do?domain*mbeans*unknow is not found in tree. "); 688 } 689 wr = link.click(); 690 691 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*unknown*"); 692 if (link == null) { 693 throw new IllegalStateException ("The link viewTree.do?domain*mbeans*unknow* is not found in tree. "); 694 } 695 wr = link.click(); 696 697 link = wr.getMatchingLinks(WebLink.MATCH_URL_STRING, "viewTree.do?tree=domain*mbeans*unknown*")[1]; 698 if (link == null) { 699 throw new IllegalStateException ("The 2nd link viewTree.do?domain*mbeans*unknow* is not found in tree. "); 700 } 701 wr = link.click(); 702 703 wr = wc.getFrameContents(FRAME_TREE); 705 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListMBeans.do"); 706 if (link == null) { 707 throw new IllegalStateException ("ListMBeans.do was not found in tree. "); 708 } 709 executeTests(wr, link, viewedURLs); 710 711 wr = wc.getFrameContents(FRAME_TREE); 713 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListJ2eeMBeans.do"); 714 if (link == null) { 715 throw new IllegalStateException ("ListJ2eeMBeans.do was not found in tree. "); 716 } 717 executeTests(wr, link, viewedURLs); 718 719 wr = wc.getFrameContents(FRAME_TREE); 721 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListOwnerMBeans.do"); 722 if (link == null) { 723 throw new IllegalStateException ("ListOwnerMBeans.do was not found in tree. "); 724 } 725 executeTests(wr, link, viewedURLs); 726 727 wr = wc.getFrameContents(FRAME_TREE); 729 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListUnknownMBeans.do"); 730 if (link == null) { 731 throw new IllegalStateException ("ListUnknownMBeans.do was not found in tree. "); 732 } 733 executeTests(wr, link, viewedURLs); 734 735 wr = wc.getFrameContents(FRAME_TREE); 737 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListMBeanDetails.do"); 738 if (link == null) { 739 throw new IllegalStateException ("ListMBeanDetails.do was not found in tree. "); 740 } 741 executeTests(wr, link, viewedURLs); 742 743 wr = wc.getFrameContents(FRAME_CONTENT); 745 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListMBeanAttributes.do"); 746 if (link == null) { 747 throw new IllegalStateException ("ListMBeansAttributes.do was not found in tree. "); 748 } 749 executeTests(wr, link, viewedURLs); 750 751 wr = wc.getFrameContents(FRAME_CONTENT); 753 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListMBeanOperations.do"); 754 if (link == null) { 755 throw new IllegalStateException ("ListMBeansOperations.do was not found in tree. "); 756 } 757 executeTests(wr, link, viewedURLs); 758 759 wr = wc.getFrameContents(FRAME_CONTENT); 761 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "ListMBeanProperties.do"); 762 if (link == null) { 763 throw new IllegalStateException ("ListMBeansProperties.do was not found in tree. "); 764 } 765 executeTests(wr, link, viewedURLs); 766 } 767 768 771 public void tearDown() { 772 endTime = getTime(); 774 775 JonasAdminFiles.recoverServerConf(beginTime, endTime); 777 } 778 } 779 | Popular Tags |