View Javadoc

1   /*
2    * $Id: ConnectorServiceTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.api.transport.Connector;
14  import org.mule.management.AbstractMuleJmxTestCase;
15  import org.mule.module.management.agent.JmxAgent;
16  import org.mule.tck.testmodels.mule.TestConnector;
17  
18  import java.util.Set;
19  
20  import javax.management.ObjectName;
21  
22  public class ConnectorServiceTestCase extends AbstractMuleJmxTestCase
23  {
24  
25      protected String domainName;
26      protected JmxAgent jmxAgent;
27  
28      @Override
29      protected void doSetUp() throws Exception
30      {
31          super.doSetUp();
32          jmxAgent = (JmxAgent) muleContext.getRegistry().lookupObject(JmxAgent.class);
33  
34      }
35  
36      public void testUndeploy() throws Exception
37      {
38          final Connector connector = new TestConnector(muleContext);
39          connector.setName("TEST_CONNECTOR");
40          muleContext.getRegistry().registerConnector(connector);
41          muleContext.start();
42  
43          domainName = jmxSupport.getDomainName(muleContext);
44          final String query = domainName + ":*";
45          final ObjectName objectName = jmxSupport.getObjectName(query);
46          Set mbeans = mBeanServer.queryMBeans(objectName, null);
47  
48          // Expecting following mbeans to be registered:
49          // 1) org.mule.management.mbeans.StatisticsService@Mule.ConnectorServiceTest:type=org.mule.Statistics,name=AllStatistics
50          // 2) org.mule.management.mbeans.MuleConfigurationService@Mule.ConnectorServiceTest:type=org.mule.Configuration,name=GlobalConfiguration
51          // 3) org.mule.management.mbeans.ModelService@Mule.ConnectorServiceTest:type=org.mule.Model,name="_muleSystemModel(seda)"
52          // 4) org.mule.management.mbeans.MuleService@Mule.ConnectorServiceTest:type=org.mule.MuleContext,name=MuleServerInfo
53          // 5) org.mule.management.mbeans.ConnectorService@Mule.ConnectorServiceTest:type=org.mule.Connector,name="TEST.CONNECTOR"
54          assertEquals("Unexpected number of components registered in the domain.", 5, mbeans.size());
55          muleContext.dispose();
56  
57          mbeans = mBeanServer.queryMBeans(objectName, null);
58          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
59      }
60  
61      @Override
62      protected void doTearDown() throws Exception
63      {
64          unregisterMBeansByMask(domainName + ":*");
65      }
66  }