1   /*
2    * $Id: ComponentStatsTestCase.java 9082 2007-10-12 11:37:14Z romikk $
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.ComponentStatistics;
15  import org.mule.management.stats.RouterStatistics;
16  
17  import java.util.Set;
18  
19  import javax.management.ObjectName;
20  
21  public class ComponentStatsTestCase extends AbstractMuleJmxTestCase
22  {
23      public void testUndeploy() throws Exception
24      {
25          final String domainOriginal = "TEST_DOMAIN_1";
26  
27          // inbound/outbound router statistics are required
28  
29          final ComponentStatistics statistics = new ComponentStatistics("TEST_IN", 0);
30          statistics.setInboundRouterStat(new RouterStatistics(RouterStatistics.TYPE_INBOUND));
31          statistics.setOutboundRouterStat(new RouterStatistics(RouterStatistics.TYPE_OUTBOUND));
32          ComponentStats stats = new ComponentStats(statistics);
33  
34          final ObjectName name = ObjectName.getInstance(domainOriginal + ":type=TEST_NAME");
35          mBeanServer.registerMBean(stats, name);
36  
37          Set mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
38  
39          // Expecting following mbeans to be registered:
40          // 1) org.mule.management.mbeans.ComponentStats@TEST_DOMAIN_1:type=TEST_NAME
41          // 2) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,component=TEST_IN,router=inbound
42          // 3) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,component=TEST_IN,router=outbound
43          assertEquals("Unexpected components registered in the domain.", 3, mbeans.size());
44  
45          mBeanServer.unregisterMBean(name);
46  
47          mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
48  
49          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
50      }
51  }