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