01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.management;
19:
20: import java.util.Iterator;
21: import java.util.Set;
22:
23: import javax.management.MBeanServer;
24: import javax.management.ObjectName;
25:
26: import org.apache.cxf.Bus;
27: import org.apache.cxf.bus.spring.SpringBusFactory;
28: import org.apache.cxf.workqueue.WorkQueueManagerImpl;
29: import org.junit.After;
30: import org.junit.Assert;
31: import org.junit.Before;
32: import org.junit.Test;
33:
34: public class InstrumentationManagerTest extends Assert {
35: InstrumentationManager im;
36: Bus bus;
37:
38: @Before
39: public void setUp() throws Exception {
40:
41: }
42:
43: @After
44: public void tearDown() throws Exception {
45: //test case had done the bus.shutdown
46: bus.shutdown(true);
47: }
48:
49: @Test
50: public void testInstrumentationNotEnabled() {
51: SpringBusFactory factory = new SpringBusFactory();
52: bus = factory.createBus();
53: im = bus.getExtension(InstrumentationManager.class);
54: assertTrue("Instrumentation Manager should not be null",
55: im != null);
56: MBeanServer mbs = im.getMBeanServer();
57: assertNull("MBeanServer should not be available.", mbs);
58: }
59:
60: @Test
61: // try to get WorkQueue information
62: public void testWorkQueueInstrumentation() throws Exception {
63: SpringBusFactory factory = new SpringBusFactory();
64: bus = factory.createBus("managed-spring.xml", true);
65: im = bus.getExtension(InstrumentationManager.class);
66: assertTrue("Instrumentation Manager should not be null",
67: im != null);
68: WorkQueueManagerImpl wqm = new WorkQueueManagerImpl();
69: wqm.setBus(bus);
70: wqm.getAutomaticWorkQueue();
71:
72: MBeanServer mbs = im.getMBeanServer();
73: assertNotNull("MBeanServer should be available.", mbs);
74: ObjectName name = new ObjectName(
75: ManagementConstants.DEFAULT_DOMAIN_NAME
76: + ":type=WorkQueueMBean,*");
77: Set s = mbs.queryNames(name, null);
78: assertTrue(s.size() == 1);
79: Iterator it = s.iterator();
80: while (it.hasNext()) {
81: ObjectName n = (ObjectName) it.next();
82: Long result = (Long) mbs.invoke(n, "getWorkQueueMaxSize",
83: new Object[0], new String[0]);
84: assertEquals(result, Long.valueOf(250));
85: }
86:
87: bus.shutdown(true);
88: }
89:
90: }
|