1   /*
2    * $Id: CommonsPoolProxyPoolTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.test.config;
12  
13  import org.mule.config.PoolingProfile;
14  import org.mule.config.pool.CommonsPoolProxyFactory;
15  import org.mule.config.pool.CommonsPoolProxyPool;
16  import org.mule.impl.MuleDescriptor;
17  import org.mule.impl.model.MuleProxy;
18  import org.mule.impl.model.seda.SedaModel;
19  import org.mule.tck.AbstractMuleTestCase;
20  import org.mule.umo.model.UMOModel;
21  
22  public class CommonsPoolProxyPoolTestCase extends AbstractMuleTestCase
23  {
24  
25      public void testOnRemoveCallsDispose() throws Exception
26      {
27          MuleDescriptor descriptor = getTestDescriptor("test", "java.lang.Object");
28          UMOModel model = new SedaModel();
29          CommonsPoolProxyFactory factory = new CommonsPoolProxyFactory(descriptor, model);
30          CommonsPoolProxyPool pool = new CommonsPoolProxyPool(descriptor, model, factory, new PoolingProfile());
31          factory.setPool(pool);
32  
33          Object obj = factory.makeObject();
34          factory.destroyObject(obj);
35  
36          // if calling dispose throws an IllegalStateException it means
37          // the component has already been disposed by the pool.
38          boolean exceptionWasThrown = false;
39          try
40          {
41              ((MuleProxy)obj).dispose();
42          }
43          catch (IllegalStateException isex)
44          {
45              assertEquals("Component has already been disposed of", isex.getMessage());
46              exceptionWasThrown = true;
47          }
48  
49          if (!exceptionWasThrown)
50          {
51              fail("Expected exception has never been thrown. Was the component disposed before?");
52          }
53      }
54  }