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.context;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.MuleException;
11  import org.mule.tck.junit4.AbstractMuleContextTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertFalse;
16  import static org.junit.Assert.assertTrue;
17  
18  public class DefaultMuleContextTestCase extends AbstractMuleContextTestCase
19  {
20  
21      @Test
22      public void testDisposal() throws MuleException, InterruptedException
23      {
24          int threadsBeforeStart = Thread.activeCount();
25          MuleContext ctx = new DefaultMuleContextFactory().createMuleContext();
26          ctx.start();
27          assertTrue(Thread.activeCount() > threadsBeforeStart);
28          ctx.stop();
29          ctx.dispose();
30          // Check that workManager ("MuleServer") thread no longer exists.
31          assertTrue(Thread.activeCount() == threadsBeforeStart);
32          assertTrue(ctx.isDisposed());
33          assertFalse(ctx.isInitialised());
34          assertFalse(ctx.isStarted());
35      }
36  
37      @Override
38      protected MuleContext createMuleContext() throws Exception
39      {
40          return null;
41      }
42  }