1   /*
2    * $Id: ServiceServiceTestCase.java 11376 2008-03-16 17:44:10Z dfeist $
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.api.config.ThreadingProfile;
14  import org.mule.component.DefaultJavaComponent;
15  import org.mule.management.AbstractMuleJmxTestCase;
16  import org.mule.model.seda.SedaModel;
17  import org.mule.model.seda.SedaService;
18  import org.mule.module.management.mbean.ServiceService;
19  import org.mule.object.SingletonObjectFactory;
20  
21  import java.util.Set;
22  
23  import javax.management.ObjectName;
24  
25  public class ServiceServiceTestCase extends AbstractMuleJmxTestCase
26  {
27      public void testUndeploy() throws Exception
28      {
29          final String domainOriginal = "TEST_DOMAIN_1";
30  
31          final SedaService component = new SedaService();
32          component.setName("TEST_SERVICE");
33          component.setComponent(new DefaultJavaComponent(new SingletonObjectFactory(Object.class)));
34  
35          component.setThreadingProfile(ThreadingProfile.DEFAULT_THREADING_PROFILE);
36          SedaModel model = new SedaModel();
37          component.setModel(model);
38          muleContext.getRegistry().registerModel(model);
39          muleContext.getRegistry().registerService(component);
40          muleContext.start();
41  
42          final ServiceService service = new ServiceService("TEST_SERVICE");
43          final ObjectName name = ObjectName.getInstance(domainOriginal + ":type=TEST_SERVICE");
44          mBeanServer.registerMBean(service, name);
45          Set mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
46  
47          // Expecting following mbeans to be registered:
48          // 1) org.mule.management.mbeans.ServiceService@TEST_DOMAIN_1:type=TEST_SERVICE
49          // 2) org.mule.management.mbeans.ServiceStats@TEST_DOMAIN_1:type=org.mule.Statistics,service=TEST_SERVICE
50          // 3) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,service=TEST_SERVICE,router=inbound
51          // 4) org.mule.management.mbeans.RouterStats@TEST_DOMAIN_1:type=org.mule.Statistics,service=TEST_SERVICE,router=outbound
52          assertEquals("Unexpected number of components registered in the domain.", 4, mbeans.size());
53  
54          mBeanServer.unregisterMBean(name);
55  
56          mbeans = mBeanServer.queryMBeans(ObjectName.getInstance(domainOriginal + ":*"), null);
57  
58          assertEquals("There should be no MBeans left in the domain", 0, mbeans.size());
59      }
60  }