1 17 package org.apache.servicemix.web.jmx; 18 19 import javax.management.MBeanServer ; 20 import javax.management.ObjectName ; 21 22 import java.io.OutputStreamWriter ; 23 import java.io.PrintWriter ; 24 import java.util.Set ; 25 26 import junit.framework.TestCase; 27 28 32 public class JMXWriterTest extends TestCase { 33 34 protected PrintWriter writer; 35 private JMXWriter jmxWriter; 36 private ManagementContext managementContext = new ManagementContext(); 37 38 public void testDetail() throws Exception { 39 Set names = managementContext.getMBeanServer().queryNames(null, null); 40 jmxWriter.outputDetail(names); 41 } 42 43 public void testQuery() throws Exception { 44 MBeanServer beanServer = managementContext.getMBeanServer(); 45 46 beanServer.registerMBean(new Foo("James"), new ObjectName ("Bar:type=Foo,name=James")); 47 beanServer.registerMBean(new Foo("Rob"), new ObjectName ("Bar:type=Foo,name=Rob")); 48 beanServer.registerMBean(new Foo("Hiram"), new ObjectName ("Bar:type=Foo,name=Hiram")); 49 50 51 53 Set result = beanServer.queryMBeans(null, new ObjectName ("*:type=Foo,*")); 54 assertEquals("Size of results: " + result, 3, result.size()); 55 } 56 57 protected void setUp() throws Exception { 58 writer = new PrintWriter (new OutputStreamWriter (System.out)); 59 jmxWriter = new JMXWriter(writer, managementContext); 60 } 61 62 protected void tearDown() throws Exception { 63 if (writer != null) { 64 writer.close(); 65 } 66 } 67 68 69 70 } 71 | Popular Tags |