View Javadoc

1   /*
2    * $Id: ServiceStatsTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  
26  public class ServiceStatsTestCase extends AbstractMuleJmxTestCase
27  {
28      @Test
29      public void testUndeploy() throws Exception
30      {
31          final String domainOriginal = "TEST_DOMAIN_1";
32  
33          // inbound/outbound router statistics are required
34  
35          final SedaServiceStatistics statistics = new SedaServiceStatistics("TEST_IN", 0, 0);
36          statistics.setInboundRouterStat(new RouterStatistics(RouterStatistics.TYPE_INBOUND));
37          statistics.setOutboundRouterStat(new RouterStatistics(RouterStatistics.TYPE_OUTBOUND));
38          ServiceStats stats = new ServiceStats(statistics);
39  
40          final ObjectName name = ObjectName.getInstance(domainOriginal + ":type=TEST_NAME");
41          mBeanServer.registerMBean(stats, name);
42  
43          Set mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
44  
45          // Expecting following mbeans to be registered:
46          // 1) org.mule.management.mbeans.ServiceStats@TEST_DOMAIN_1:type=TEST_NAME
47          // 2) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,service=TEST_IN,router=inbound
48          // 3) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,service=TEST_IN,router=outbound
49          assertEquals("Unexpected components registered in the domain.", 3, mbeans.size());
50  
51          mBeanServer.unregisterMBean(name);
52  
53          mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
54  
55          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
56      }
57  }