View Javadoc

1   /*
2    * $Id: MuleContextRestartTestCase.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.agents;
12  
13  import org.mule.module.management.mbean.MBeanServerFactory;
14  import org.mule.tck.FunctionalTestCase;
15  
16  import java.util.Set;
17  
18  import javax.management.MBeanServer;
19  import javax.management.MalformedObjectNameException;
20  import javax.management.ObjectName;
21  
22  public class MuleContextRestartTestCase extends FunctionalTestCase
23  {
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "mule-context-restart-config.xml";
29      }
30  
31      public void testContextRestart() throws Exception
32      {
33          muleContext.stop();
34          checkCleanShutdown();
35  
36          // do it again ;)
37          muleContext.start();
38          muleContext.stop();
39          checkCleanShutdown();
40      }
41  
42      protected void checkCleanShutdown() throws MalformedObjectNameException
43      {
44          // check there are no leftover mbeans in mule domain
45          final String contextId = muleContext.getConfiguration().getId();
46          MBeanServer server = MBeanServerFactory.getOrCreateMBeanServer();
47          ObjectName oname = ObjectName.getInstance("Mule." + contextId + ":*");
48          Set mbeans = server.queryMBeans(oname, null);
49  
50          assertEquals("Not all MBeans unregistered on context stop.", 0, mbeans.size());
51      }
52  
53  }