1   /*
2    * $Id: ComponentServiceTestCase.java 9082 2007-10-12 11:37:14Z romikk $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.impl.MuleDescriptor;
14  import org.mule.management.AbstractMuleJmxTestCase;
15  import org.mule.umo.manager.UMOManager;
16  
17  import java.util.Set;
18  
19  import javax.management.ObjectName;
20  
21  public class ComponentServiceTestCase extends AbstractMuleJmxTestCase
22  {
23      public void testUndeploy() throws Exception
24      {
25          final String domainOriginal = "TEST_DOMAIN_1";
26  
27          UMOManager manager = getManager(true);
28          final MuleDescriptor descriptor = new MuleDescriptor("TEST_SERVICE");
29          descriptor.setImplementation(new Object());
30          getDefaultModel().registerComponent(descriptor);
31  
32          manager.start();
33          final ComponentService service = new ComponentService("TEST_SERVICE");
34          final ObjectName name = ObjectName.getInstance(domainOriginal + ":type=TEST_SERVICE");
35          mBeanServer.registerMBean(service, name);
36          Set mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
37  
38          // Expecting following mbeans to be registered:
39          // 1) org.mule.management.mbeans.ComponentService@TEST_DOMAIN_1:type=TEST_SERVICE
40          // 2) org.mule.management.mbeans.ComponentStats@TEST_DOMAIN_1:type=org.mule.Statistics,component=TEST_SERVICE
41          // 3) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,component=TEST_SERVICE,router=inbound
42          // 4) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,component=TEST_SERVICE,router=outbound
43          assertEquals("Unexpected number of components registered in the domain.", 4, mbeans.size());
44  
45          mBeanServer.unregisterMBean(name);
46  
47          mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
48  
49          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
50      }
51  }