KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > web > jmx > JMXWriterTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.web.jmx;
18
19 import javax.management.MBeanServer JavaDoc;
20 import javax.management.ObjectName JavaDoc;
21
22 import java.io.OutputStreamWriter JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import junit.framework.TestCase;
27
28 /**
29  *
30  * @version $Revision: 356269 $
31  */

32 public class JMXWriterTest extends TestCase {
33
34     protected PrintWriter JavaDoc writer;
35     private JMXWriter jmxWriter;
36     private ManagementContext managementContext = new ManagementContext();
37
38     public void testDetail() throws Exception JavaDoc {
39         Set JavaDoc names = managementContext.getMBeanServer().queryNames(null, null);
40         jmxWriter.outputDetail(names);
41     }
42
43     public void testQuery() throws Exception JavaDoc {
44         MBeanServer JavaDoc beanServer = managementContext.getMBeanServer();
45
46         beanServer.registerMBean(new Foo("James"), new ObjectName JavaDoc("Bar:type=Foo,name=James"));
47         beanServer.registerMBean(new Foo("Rob"), new ObjectName JavaDoc("Bar:type=Foo,name=Rob"));
48         beanServer.registerMBean(new Foo("Hiram"), new ObjectName JavaDoc("Bar:type=Foo,name=Hiram"));
49
50
51         // now lets try find some MBeans using a query
52

53         Set JavaDoc result = beanServer.queryMBeans(null, new ObjectName JavaDoc("*:type=Foo,*"));
54         assertEquals("Size of results: " + result, 3, result.size());
55     }
56
57     protected void setUp() throws Exception JavaDoc {
58         writer = new PrintWriter JavaDoc(new OutputStreamWriter JavaDoc(System.out));
59         jmxWriter = new JMXWriter(writer, managementContext);
60     }
61
62     protected void tearDown() throws Exception JavaDoc {
63         if (writer != null) {
64             writer.close();
65         }
66     }
67
68
69
70 }
71
Popular Tags