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.agents;
8   
9   import org.mule.module.management.mbean.MBeanServerFactory;
10  import org.mule.tck.junit4.FunctionalTestCase;
11  
12  import java.util.Set;
13  
14  import javax.management.MBeanServer;
15  import javax.management.MalformedObjectNameException;
16  import javax.management.ObjectName;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
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      @Test
32      public void testContextRestart() throws Exception
33      {
34          muleContext.stop();
35          checkCleanShutdown();
36  
37          // do it again ;)
38          muleContext.start();
39          muleContext.stop();
40          checkCleanShutdown();
41      }
42  
43      protected void checkCleanShutdown() throws MalformedObjectNameException
44      {
45          // check there are no leftover mbeans in mule domain
46          final String contextId = muleContext.getConfiguration().getId();
47          MBeanServer server = MBeanServerFactory.getOrCreateMBeanServer();
48          ObjectName oname = ObjectName.getInstance("Mule." + contextId + ":*");
49          Set mbeans = server.queryMBeans(oname, null);
50  
51          assertEquals("Not all MBeans unregistered on context stop.", 0, mbeans.size());
52      }
53  
54  }