View Javadoc

1   /*
2    * $Id: MuleContextRestartTestCase.java 22525 2011-07-22 09:39:16Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  import java.util.Set;
18  
19  import javax.management.MBeanServer;
20  import javax.management.MalformedObjectNameException;
21  import javax.management.ObjectName;
22  
23  import org.junit.Test;
24  import org.junit.runners.Parameterized.Parameters;
25  import org.mule.module.management.mbean.MBeanServerFactory;
26  import org.mule.tck.AbstractServiceAndFlowTestCase;
27  
28  public class MuleContextRestartTestCase extends AbstractServiceAndFlowTestCase
29  {
30  
31      public MuleContextRestartTestCase(ConfigVariant variant, String configResources)
32      {
33          super(variant, configResources);
34      }
35  
36      @Parameters
37      public static Collection<Object[]> parameters()
38      {
39          return Arrays.asList(new Object[][]{
40              {ConfigVariant.SERVICE, "mule-context-restart-config-service.xml"},
41              {ConfigVariant.FLOW, "mule-context-restart-config-flow.xml"}});
42      }
43  
44      @Test
45      public void testContextRestart() throws Exception
46      {
47          muleContext.stop();
48          checkCleanShutdown();
49  
50          // do it again ;)
51          muleContext.start();
52          muleContext.stop();
53          checkCleanShutdown();
54      }
55  
56      protected void checkCleanShutdown() throws MalformedObjectNameException
57      {
58          // check there are no leftover mbeans in mule domain
59          final String contextId = muleContext.getConfiguration().getId();
60          MBeanServer server = MBeanServerFactory.getOrCreateMBeanServer();
61          ObjectName oname = ObjectName.getInstance("Mule." + contextId + ":*");
62          Set mbeans = server.queryMBeans(oname, null);
63  
64          assertEquals("Not all MBeans unregistered on context stop.", 0, mbeans.size());
65      }
66  
67  }