1   /*
2    * $Id: CommonsPoolProxyFactoryTestCase.java 7963 2007-08-21 08:53:15Z 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  public class CommonsPoolProxyFactoryTestCase extends AbstractProxyPoolFactoryTestCase
25  {
26      public ObjectFactory getProxyFactory(MuleDescriptor descriptor, ObjectPool pool)
27      {
28          CommonsPoolProxyFactory factory = new CommonsPoolProxyFactory(descriptor, new SedaModel());
29          factory.setPool(pool);
30          return factory;
31      }
32  
33      public void testLifeCycleMethods() throws Exception
34      {
35          getManager(true);
36          Mock mockPool = new Mock(ObjectPool.class);
37          mockPool.expect("onAdd", C.IS_NOT_NULL);
38          mockPool.expect("onRemove", C.IS_NOT_NULL);
39          MuleDescriptor descriptor = getTestDescriptor("apple", Apple.class.getName());
40          CommonsPoolProxyFactory factory = (CommonsPoolProxyFactory)getProxyFactory(descriptor,
41              (ObjectPool)mockPool.proxy());
42  
43          assertNotNull(factory);
44  
45          Object obj = factory.makeObject();
46          assertNotNull(obj);
47          assertTrue(factory.validateObject(obj));
48          factory.activateObject(obj);
49          factory.passivateObject(obj);
50          factory.destroyObject(obj);
51      }
52  }