KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > JMXConsoleUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import java.net.HttpURLConnection JavaDoc;
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: 37406 $
37  */

38 public class JMXConsoleUnitTestCase
39    extends JBossTestCase
40 {
41    private String JavaDoc baseURLNoAuth = HttpUtils.getBaseURLNoAuth();
42
43    public JMXConsoleUnitTestCase(String JavaDoc name)
44    {
45       super(name);
46    }
47
48    /** Test access of the jmx-console/index.jsp page
49     * @throws Exception
50     */

51    public void testIndexPage()
52       throws Exception JavaDoc
53    {
54       URL JavaDoc url = new URL JavaDoc(baseURLNoAuth+"jmx-console/index.jsp");
55       HttpUtils.accessURL(url);
56    }
57
58    /** Test an mbean inspection via a get to the HtmlAdaptor
59     * @throws Exception
60     */

61    public void testMBeanInspection()
62       throws Exception JavaDoc
63    {
64       // The jboss:service=Naming mbean view
65
URL JavaDoc url = new URL JavaDoc(baseURLNoAuth+"jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss%3Aservice%3DNaming");
66       HttpUtils.accessURL(url);
67    }
68
69    /** Test an mbean invocation via a post to the HtmlAdaptor
70     * @throws Exception
71     */

72    public void testMBeanOperation()
73       throws Exception JavaDoc
74    {
75       // The jboss.system:type=Server mbean view
76
URL JavaDoc url = new URL JavaDoc(baseURLNoAuth+"jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.system%3Atype%3DServer");
77       HttpUtils.accessURL(url);
78       // Submit the op invocation form for op=runGarbageCollector
79
PostMethod formPost = new PostMethod(baseURLNoAuth+"jmx-console/HtmlAdaptor");
80       formPost.addRequestHeader("Referer", baseURLNoAuth+"jmx-console/HtmlAdaptor");
81       formPost.addParameter("action", "invokeOpByName");
82       formPost.addParameter("name", "jboss.system:type=Server");
83       formPost.addParameter("methodName", "runGarbageCollector");
84       HttpClient httpConn = new HttpClient();
85       int responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
86          formPost);
87       assertTrue("HTTP_OK", responseCode==HttpURLConnection.HTTP_OK);
88    }
89 }
90
Popular Tags