1   /*
2    * $Id: ComponentStatsTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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          assertEquals("Unexpected components registered in the domain.", 3, mbeans.size());
40  
41          mBeanServer.unregisterMBean(name);
42  
43          mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
44  
45          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
46      }
47  }