01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.jmx.test;
23:
24: import java.net.URL;
25: import java.net.HttpURLConnection;
26:
27: import org.apache.commons.httpclient.methods.PostMethod;
28: import org.apache.commons.httpclient.HttpClient;
29:
30: import org.jboss.test.JBossTestCase;
31: import org.jboss.test.util.web.HttpUtils;
32:
33: /** Basic access tests of the http jmx-console interface
34: *
35: * @author Scott.Stark@jboss.org
36: * @version $Revision: 57211 $
37: */
38: public class JMXConsoleUnitTestCase extends JBossTestCase {
39: private String baseURLNoAuth = HttpUtils.getBaseURLNoAuth();
40:
41: public JMXConsoleUnitTestCase(String name) {
42: super (name);
43: }
44:
45: /** Test access of the jmx-console/index.jsp page
46: * @throws Exception
47: */
48: public void testIndexPage() throws Exception {
49: URL url = new URL(baseURLNoAuth + "jmx-console/index.jsp");
50: HttpUtils.accessURL(url);
51: }
52:
53: /** Test an mbean inspection via a get to the HtmlAdaptor
54: * @throws Exception
55: */
56: public void testMBeanInspection() throws Exception {
57: // The jboss:service=Naming mbean view
58: URL url = new URL(
59: baseURLNoAuth
60: + "jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss%3Aservice%3DNaming");
61: HttpUtils.accessURL(url);
62: }
63:
64: /** Test an mbean invocation via a post to the HtmlAdaptor
65: * @throws Exception
66: */
67: public void testMBeanOperation() throws Exception {
68: // The jboss.system:type=Server mbean view
69: URL url = new URL(
70: baseURLNoAuth
71: + "jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.system%3Atype%3DServer");
72: HttpUtils.accessURL(url);
73: // Submit the op invocation form for op=runGarbageCollector
74: PostMethod formPost = new PostMethod(baseURLNoAuth
75: + "jmx-console/HtmlAdaptor");
76: formPost.addRequestHeader("Referer", baseURLNoAuth
77: + "jmx-console/HtmlAdaptor");
78: formPost.addParameter("action", "invokeOpByName");
79: formPost.addParameter("name", "jboss.system:type=Server");
80: formPost.addParameter("methodName", "runGarbageCollector");
81: HttpClient httpConn = new HttpClient();
82: int responseCode = httpConn.executeMethod(formPost
83: .getHostConfiguration(), formPost);
84: assertTrue("HTTP_OK", responseCode == HttpURLConnection.HTTP_OK);
85: }
86: }
|