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