KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > management > jmx > JMXManagedComponentManagerTest


1 package org.objectweb.celtix.bus.management.jmx;
2
3 import javax.management.ObjectName JavaDoc;
4
5
6 import junit.framework.TestCase;
7
8 import org.easymock.classextension.EasyMock;
9 import org.objectweb.celtix.Bus;
10 import org.objectweb.celtix.BusException;
11 import org.objectweb.celtix.bus.instrumentation.JMXConnectorPolicyType;
12 import org.objectweb.celtix.bus.instrumentation.MBServerPolicyType;
13 import org.objectweb.celtix.bus.management.InstrumentationCreatedEvent;
14 import org.objectweb.celtix.bus.management.InstrumentationRemovedEvent;
15 import org.objectweb.celtix.bus.management.jmx.export.AnnotationTestInstrumentation;
16
17
18 public class JMXManagedComponentManagerTest extends TestCase {
19     private static final String JavaDoc NAME_ATTRIBUTE = "Name";
20     private static final String JavaDoc BUS_ID = "celtix";
21     private Bus bus;
22     private JMXManagedComponentManager manager;
23     
24     public void setUp() throws BusException {
25         bus = EasyMock.createMock(Bus.class);
26         EasyMock.reset(bus);
27         bus.getBusID();
28         EasyMock.expectLastCall().andReturn(BUS_ID);
29         EasyMock.replay(bus);
30         manager = new JMXManagedComponentManager(bus);
31     }
32     
33     public void tearDown() throws Exception JavaDoc {
34         //?
35
}
36     
37         
38     public void testJMXManagerInit() {
39         MBServerPolicyType policy = new MBServerPolicyType();
40         JMXConnectorPolicyType connector = new JMXConnectorPolicyType();
41         policy.setJMXConnector(connector);
42         connector.setDaemon(false);
43         connector.setThreaded(true);
44         connector.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
45         try {
46             manager.init(policy);
47             Thread.sleep(300);
48             manager.shutdown();
49         } catch (Exception JavaDoc ex) {
50             assertTrue("JMX Manager init with NewMBeanServer error", false);
51             ex.printStackTrace();
52         }
53     }
54     
55     public void testJMXManagerProcessEvent() throws BusException {
56         MBServerPolicyType policy = new MBServerPolicyType();
57         JMXConnectorPolicyType connector = new JMXConnectorPolicyType();
58         policy.setJMXConnector(connector);
59         connector.setDaemon(false);
60         connector.setThreaded(false);
61         connector.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
62         manager.init(policy);
63         // setup the fack instrumentation
64
AnnotationTestInstrumentation im = new AnnotationTestInstrumentation();
65         ObjectName JavaDoc name = JMXUtils.getObjectName(im.getInstrumentationName(),
66                                                  im.getUniqueInstrumentationName(),
67                                                  BUS_ID);
68        
69         im.setName("John Smith");
70         manager.processEvent(new InstrumentationCreatedEvent(im));
71         
72         try {
73             Object JavaDoc val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
74             assertEquals("Incorrect result", "John Smith", val);
75             Thread.sleep(300);
76         } catch (Exception JavaDoc ex) {
77             ex.printStackTrace();
78             assertTrue("get instrumentation attribute error", false);
79         }
80         manager.processEvent(new InstrumentationRemovedEvent(im));
81         manager.shutdown();
82     }
83
84 }
85
Popular Tags