1   /*
2    * $Id: ServiceStatsTestCase.java 11234 2008-03-06 23:44:34Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.management.mbeans;
12  
13  import org.mule.management.AbstractMuleJmxTestCase;
14  import org.mule.management.stats.RouterStatistics;
15  import org.mule.management.stats.SedaServiceStatistics;
16  import org.mule.module.management.mbean.ServiceStats;
17  
18  import java.util.Set;
19  
20  import javax.management.ObjectName;
21  
22  public class ServiceStatsTestCase extends AbstractMuleJmxTestCase
23  {
24      public void testUndeploy() throws Exception
25      {
26          final String domainOriginal = "TEST_DOMAIN_1";
27  
28          // inbound/outbound router statistics are required
29  
30          final SedaServiceStatistics statistics = new SedaServiceStatistics("TEST_IN", 0, 0);
31          statistics.setInboundRouterStat(new RouterStatistics(RouterStatistics.TYPE_INBOUND));
32          statistics.setOutboundRouterStat(new RouterStatistics(RouterStatistics.TYPE_OUTBOUND));
33          ServiceStats stats = new ServiceStats(statistics);
34  
35          final ObjectName name = ObjectName.getInstance(domainOriginal + ":type=TEST_NAME");
36          mBeanServer.registerMBean(stats, name);
37  
38          Set mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
39  
40          // Expecting following mbeans to be registered:
41          // 1) org.mule.management.mbeans.ServiceStats@TEST_DOMAIN_1:type=TEST_NAME
42          // 2) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,service=TEST_IN,router=inbound
43          // 3) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,service=TEST_IN,router=outbound
44          assertEquals("Unexpected components registered in the domain.", 3, mbeans.size());
45  
46          mBeanServer.unregisterMBean(name);
47  
48          mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
49  
50          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
51      }
52  }