1   /*
2    * $Id: CommonsPoolProxyFactoryTestCase.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.mule.commonspool;
12  
13  import org.mule.config.pool.CommonsPoolProxyFactory;
14  import org.mule.impl.MuleDescriptor;
15  import org.mule.impl.model.seda.SedaModel;
16  import org.mule.tck.model.AbstractProxyPoolFactoryTestCase;
17  import org.mule.tck.testmodels.fruit.Apple;
18  import org.mule.util.ObjectFactory;
19  import org.mule.util.ObjectPool;
20  
21  import com.mockobjects.dynamic.C;
22  import com.mockobjects.dynamic.Mock;
23  
24  /**
25   * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26   * @version $Revision: 7976 $
27   */
28  
29  public class CommonsPoolProxyFactoryTestCase extends AbstractProxyPoolFactoryTestCase
30  {
31      public ObjectFactory getProxyFactory(MuleDescriptor descriptor, ObjectPool pool)
32      {
33          CommonsPoolProxyFactory factory = new CommonsPoolProxyFactory(descriptor, new SedaModel());
34          factory.setPool(pool);
35          return factory;
36      }
37  
38      public void testLifeCycleMethods() throws Exception
39      {
40          getManager(true);
41          Mock mockPool = new Mock(ObjectPool.class);
42          mockPool.expect("onAdd", C.IS_NOT_NULL);
43          mockPool.expect("onRemove", C.IS_NOT_NULL);
44          MuleDescriptor descriptor = getTestDescriptor("apple", Apple.class.getName());
45          CommonsPoolProxyFactory factory = (CommonsPoolProxyFactory)getProxyFactory(descriptor,
46              (ObjectPool)mockPool.proxy());
47  
48          assertNotNull(factory);
49  
50          Object obj = factory.makeObject();
51          assertNotNull(obj);
52          assertTrue(factory.validateObject(obj));
53          factory.activateObject(obj);
54          factory.passivateObject(obj);
55          factory.destroyObject(obj);
56      }
57  }