001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JonasAdminTree.java 7041 2005-07-12 08:16:52Z kemlerp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jonasadmin.test.util;
025:
026: import org.xml.sax.SAXException;
027:
028: import com.meterware.httpunit.WebConversation;
029: import com.meterware.httpunit.WebImage;
030: import com.meterware.httpunit.WebLink;
031: import com.meterware.httpunit.WebResponse;
032:
033: /**
034: * Define a class to manipulate the tree frame of JonasAdmin
035: * @author kemlerp
036: *
037: */
038: public class JonasAdminTree {
039:
040: /**
041: * NAME of FRAME tree
042: */
043: private static final String FRAME_TREE = "tree";
044:
045: /**
046: * Verify if it is the good link of the tree which is selected
047: * @param wr The WebResponse of the 'tree' frame
048: * @param name A string with the name of the link
049: * @return a boolean. True if the name is found in the link, else false.
050: */
051: public static boolean treeControlSelected(WebResponse wr,
052: String selectedLink) throws SAXException {
053: boolean isSelected = false; // the result
054: int nbSelectedLink = 0; // number of selected link
055: String attribut; // value of class attribut
056: String linkUrl = null; // url of selected attribut
057:
058: // Get all links
059: WebLink[] links;
060: try {
061: links = wr.getLinks();
062:
063: // Search links with the 'tree-control-selected' class attribut
064: // and increase nbSelectedLink
065: for (int i = 0; i < links.length; i++) {
066: attribut = links[i].getAttribute("class");
067: if (attribut.indexOf("tree-control-selected") != -1) {
068: linkUrl = links[i].getURLString();
069: nbSelectedLink++;
070: }
071: }
072:
073: if (nbSelectedLink == 1) {
074: if (selectedLink.equals(linkUrl)) {
075: isSelected = true;
076: }
077: }
078: } catch (SAXException e) {
079: throw new SAXException("No link was found : " + e);
080: }
081:
082: return isSelected;
083: }
084:
085: /**
086: * Open tree
087: * @param wr Tree Frame Web Response
088: * @return Tree Frame Web Response with opened tree
089: * @throws Exception if an error occurs
090: */
091: public static WebResponse openTree(WebResponse wr,
092: WebConversation wc) throws Exception {
093: WebImage[] frameTreeImages = wr.getImages();
094: for (int i = 0; i < frameTreeImages.length; i++) {
095: if (frameTreeImages[i].getSource().indexOf("node_close") != -1) {
096: if (!frameTreeImages[i].getLink().getURLString()
097: .endsWith("*mbeans")) {
098: frameTreeImages[i].getLink().click();
099: // get frame tree response
100: wr = wc.getFrameContents(FRAME_TREE);
101: // update frameTreeImages
102: frameTreeImages = wr.getImages();
103: }
104: }
105: }
106: return wr;
107: }
108:
109: }
|