KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > applications > clients > apps > mejb > F_MonitoringEndpoint


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  * Initial developer: Matt Wringe
22  * --------------------------------------------------------------------------
23  * $Id:
24  * --------------------------------------------------------------------------
25  */

26 package org.objectweb.jonas.applications.clients.apps.mejb;
27
28 import java.net.URL JavaDoc;
29 import javax.xml.namespace.QName JavaDoc;
30 import junit.framework.TestSuite;
31 import junit.textui.TestRunner;
32 import org.apache.axis.client.Call;
33 import org.apache.axis.client.Service;
34 import org.objectweb.jonas.applications.util.JApplicationsTestCase;
35
36 /**
37  * Class used to test that the monitoring endpoint (contained in
38  * mejb.ear) is working properly.
39  * @author Matt Wringe
40  */

41 public class F_MonitoringEndpoint extends JApplicationsTestCase{
42
43
44     /**
45      * URL of the monitoring endpoint
46      */

47     private static final String JavaDoc URL_ENDPOINT = "/mejb/ManagementEndpoint/ManagementEndpoint";
48
49     /**
50      * The namespace of the monitoring endpoint.
51      */

52     private static final String JavaDoc NAMESPACE = "http://mejb.jonas.objectweb.org";
53
54     /**
55      * Call object used to invoke methods in the monitoring endpoint
56      */

57     private static Call call;
58
59     /**
60      * Main method
61      * @param args the arguments
62      */

63     public static void main(String JavaDoc[] args) {
64         String JavaDoc testtorun = null;
65         for (int argn = 0; argn < args.length; argn++) {
66             String JavaDoc sArg = args[argn];
67             if (sArg.equals("-n")) {
68                 testtorun = args[++argn];
69             }
70         }
71         if (testtorun == null) {
72             TestRunner.run(suite());
73         } else {
74             TestRunner.run(new F_MonitoringEndpoint(testtorun));
75         }
76     }
77
78     /**
79      * Constructor with a specified name
80      * @param s name
81      */

82     public F_MonitoringEndpoint(String JavaDoc s) {
83         super (s, URL_ENDPOINT);
84     }
85
86     /**
87      * Get a new TestSuite for this class
88      * @return a new TestSuite for this class
89      */

90     public static TestSuite suite() {
91         return new TestSuite(F_MonitoringEndpoint.class);
92     }
93
94     /**
95      * Initial setup for the test
96      * @throws Exception If any exception occurs.
97      */

98     protected void setUp() throws Exception JavaDoc {
99         super.setUp();
100         useEar("mejb");
101         Service service = new Service();
102         call = (Call) service.createCall();
103         call.setTargetEndpointAddress (new URL JavaDoc(getAbsoluteUrl(URL_ENDPOINT)));
104     }
105
106     /**
107      * Tests that the endpoint can get the mbean count for the current server
108      * @throws Exception If any exception occurs
109      */

110     public void testGetMBeanCount() throws Exception JavaDoc {
111         call.setOperationName (new QName JavaDoc(NAMESPACE, "getMBeanCount"));
112         Integer JavaDoc res = (Integer JavaDoc) call.invoke (new Object JavaDoc[]{});
113         if (res.intValue() <= 0) {
114             fail ("Could not get any mbeans");
115         }
116     }
117
118     /**
119      * Tests if the endpoint can get the list of servers.
120      * @throws Exception If any exception occurs.
121      */

122     public void testGetServers() throws Exception JavaDoc {
123         call.setOperationName (new QName JavaDoc(NAMESPACE, "getServers"));
124         String JavaDoc[] res = (String JavaDoc[]) call.invoke (new Object JavaDoc[]{});
125         if (res.length < 1) {
126             fail ("No servers found in the domain");
127         }
128     }
129
130     /**
131      * Test if the endopoint can get current domain.
132      * Assumes the sever is started in domain 'jonas'
133      * @throws Exception If any exception occurs.
134      */

135     public void testDefaultDomain() throws Exception JavaDoc {
136         //Assumes server is started in domain jonas
137
call.setOperationName (new QName JavaDoc(NAMESPACE, "getDefaultDomain"));
138         String JavaDoc res = (String JavaDoc) call.invoke (new Object JavaDoc[]{});
139         if (!res.equals("jonas")) {
140             fail ("The domain name gotten through the endpoint does not match the actual domain name. Expected :jonas, received :" + res);
141         }
142     }
143
144     /**
145      * Test if the endpoint can get the server name from the J2EEServer mbean.
146      * Assumes that the server's name is 'jonas' and started in domain 'jonas'
147      * @throws Exception If any exception occurs.
148      */

149     public void testGetAttribute() throws Exception JavaDoc {
150         //Assumes that the server started is named jonas and is started in domain jonas
151
String JavaDoc serverName = "jonas";
152         String JavaDoc domainName = "jonas";
153         String JavaDoc objectName = domainName + ":j2eeType=J2EEServer,name=" + serverName;
154
155         call.setOperationName (new QName JavaDoc(NAMESPACE, "getAttribute"));
156         String JavaDoc[] res = (String JavaDoc[]) call.invoke (new Object JavaDoc[]{serverName, objectName, "serverName"});
157         if (!res[0].equals(serverName)) {
158             fail ("The attribute value received does not match its acual value. Expected :"
159                    + serverName + ", received:" + res[0]);
160         }
161     }
162 }
163
Popular Tags