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.api.transport.Connector;
10  import org.mule.management.AbstractMuleJmxTestCase;
11  import org.mule.module.management.agent.JmxAgent;
12  import org.mule.tck.testmodels.mule.TestConnector;
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 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      @Test
37      public void testUndeploy() throws Exception
38      {
39          final Connector connector = new TestConnector(muleContext);
40          connector.setName("TEST_CONNECTOR");
41          muleContext.getRegistry().registerConnector(connector);
42          muleContext.start();
43  
44          domainName = jmxSupport.getDomainName(muleContext);
45          final String query = domainName + ":*";
46          final ObjectName objectName = jmxSupport.getObjectName(query);
47          Set mbeans = mBeanServer.queryMBeans(objectName, null);
48  
49          // Expecting following mbeans to be registered:
50          // 1) org.mule.management.mbeans.StatisticsService@Mule.ConnectorServiceTest:type=org.mule.Statistics,name=AllStatistics
51          // 2) org.mule.management.mbeans.MuleConfigurationService@Mule.ConnectorServiceTest:type=org.mule.Configuration,name=GlobalConfiguration
52          // 3) org.mule.management.mbeans.ModelService@Mule.ConnectorServiceTest:type=org.mule.Model,name="_muleSystemModel(seda)"
53          // 4) org.mule.management.mbeans.MuleService@Mule.ConnectorServiceTest:type=org.mule.MuleContext,name=MuleServerInfo
54          // 5) org.mule.management.mbeans.ConnectorService@Mule.ConnectorServiceTest:type=org.mule.Connector,name="TEST.CONNECTOR"
55          // 6) org.mule.module.management.mbean.ApplicationService:type=Application,name="totals for all flows and services"]
56          // 7) org.mule.module.management.mbean.FlowConstructStats:type=org.mule.Statistics,Application=totals for all flows and services]
57          assertEquals("Unexpected number of components registered in the domain.", 7, mbeans.size());
58          muleContext.dispose();
59  
60          mbeans = mBeanServer.queryMBeans(objectName, null);
61          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
62      }
63  
64      @Override
65      protected void doTearDown() throws Exception
66      {
67          unregisterMBeansByMask(domainName + ":*");
68      }
69  }