View Javadoc

1   /*
2    * $Id: ConnectorServiceTestCase.java 22391 2011-07-12 12:00:48Z 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.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.ObjectInstance;
21  import javax.management.ObjectName;
22  
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  
27  public class ConnectorServiceTestCase extends AbstractMuleJmxTestCase
28  {
29  
30      protected String domainName;
31      protected JmxAgent jmxAgent;
32  
33      @Override
34      protected void doSetUp() throws Exception
35      {
36          super.doSetUp();
37          jmxAgent = muleContext.getRegistry().lookupObject(JmxAgent.class);
38  
39      }
40  
41      @Test
42      public void testUndeploy() throws Exception
43      {
44          final Connector connector = new TestConnector(muleContext);
45          connector.setName("TEST_CONNECTOR");
46          muleContext.getRegistry().registerConnector(connector);
47          muleContext.start();
48  
49          domainName = jmxSupport.getDomainName(muleContext);
50          final String query = domainName + ":*";
51          final ObjectName objectName = jmxSupport.getObjectName(query);
52          Set<ObjectInstance> mbeans = mBeanServer.queryMBeans(objectName, null);
53  
54          // Expecting following mbeans to be registered:
55          // 1) org.mule.management.mbeans.StatisticsService@Mule.ConnectorServiceTest:type=org.mule.Statistics,name=AllStatistics
56          // 2) org.mule.management.mbeans.MuleConfigurationService@Mule.ConnectorServiceTest:type=org.mule.Configuration,name=GlobalConfiguration
57          // 3) org.mule.management.mbeans.ModelService@Mule.ConnectorServiceTest:type=org.mule.Model,name="_muleSystemModel(seda)"
58          // 4) org.mule.management.mbeans.MuleService@Mule.ConnectorServiceTest:type=org.mule.MuleContext,name=MuleServerInfo
59          // 5) org.mule.management.mbeans.ConnectorService@Mule.ConnectorServiceTest:type=org.mule.Connector,name="TEST.CONNECTOR"
60          // 6) org.mule.module.management.mbean.ApplicationService:type=Application,name="totals for all flows and services"]
61          // 7) org.mule.module.management.mbean.FlowConstructStats:type=org.mule.Statistics,Application=totals for all flows and services]
62          assertEquals("Unexpected number of components registered in the domain.", 7, mbeans.size());
63          muleContext.dispose();
64  
65          mbeans = mBeanServer.queryMBeans(objectName, null);
66          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
67      }
68  
69      @Override
70      protected void doTearDown() throws Exception
71      {
72          unregisterMBeansByMask(domainName + ":*");
73      }
74  }