KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > util > JonasAdminTree


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: JonasAdminTree.java,v 1.3 2005/07/12 08:16:52 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.util;
27
28 import org.xml.sax.SAXException JavaDoc;
29
30 import com.meterware.httpunit.WebConversation;
31 import com.meterware.httpunit.WebImage;
32 import com.meterware.httpunit.WebLink;
33 import com.meterware.httpunit.WebResponse;
34
35 /**
36  * Define a class to manipulate the tree frame of JonasAdmin
37  * @author kemlerp
38  *
39  */

40 public class JonasAdminTree {
41
42     /**
43      * NAME of FRAME tree
44      */

45     private static final String JavaDoc FRAME_TREE = "tree";
46
47     /**
48      * Verify if it is the good link of the tree which is selected
49      * @param wr The WebResponse of the 'tree' frame
50      * @param name A string with the name of the link
51      * @return a boolean. True if the name is found in the link, else false.
52      */

53     public static boolean treeControlSelected (WebResponse wr, String JavaDoc selectedLink) throws SAXException JavaDoc {
54         boolean isSelected = false; // the result
55
int nbSelectedLink = 0; // number of selected link
56
String JavaDoc attribut; // value of class attribut
57
String JavaDoc linkUrl = null; // url of selected attribut
58

59         // Get all links
60
WebLink[] links;
61         try {
62             links = wr.getLinks();
63
64             // Search links with the 'tree-control-selected' class attribut
65
// and increase nbSelectedLink
66
for (int i = 0; i < links.length; i++) {
67                 attribut = links[i].getAttribute("class");
68                 if (attribut.indexOf("tree-control-selected") != -1) {
69                     linkUrl = links[i].getURLString();
70                     nbSelectedLink++;
71                 }
72             }
73
74             if (nbSelectedLink == 1) {
75                 if (selectedLink.equals(linkUrl)) {
76                     isSelected = true;
77                 }
78             }
79         } catch (SAXException JavaDoc e) {
80             throw new SAXException JavaDoc("No link was found : " + e);
81         }
82
83         return isSelected;
84     }
85
86     /**
87      * Open tree
88      * @param wr Tree Frame Web Response
89      * @return Tree Frame Web Response with opened tree
90      * @throws Exception if an error occurs
91      */

92     public static WebResponse openTree(WebResponse wr, WebConversation wc) throws Exception JavaDoc {
93             WebImage[] frameTreeImages = wr.getImages();
94         for (int i = 0; i < frameTreeImages.length; i++) {
95             if (frameTreeImages[i].getSource().indexOf("node_close") != -1) {
96                 if (!frameTreeImages[i].getLink().getURLString().endsWith("*mbeans")) {
97                     frameTreeImages[i].getLink().click();
98                     // get frame tree response
99
wr = wc.getFrameContents(FRAME_TREE);
100                     // update frameTreeImages
101
frameTreeImages = wr.getImages();
102                 }
103             }
104         }
105         return wr;
106     }
107
108 }
109
Popular Tags