Exemplo n.º 1
0
  public void testOnRemoveCallsDispose() throws Exception {
    MuleDescriptor descriptor = getTestDescriptor("test", "java.lang.Object");
    UMOModel model = new SedaModel();
    CommonsPoolProxyFactory factory = new CommonsPoolProxyFactory(descriptor, model);
    CommonsPoolProxyPool pool =
        new CommonsPoolProxyPool(descriptor, model, factory, new PoolingProfile());
    factory.setPool(pool);

    Object obj = factory.makeObject();
    factory.destroyObject(obj);

    // if calling dispose throws an IllegalStateException it means
    // the component has already been disposed by the pool.
    boolean exceptionWasThrown = false;
    try {
      ((MuleProxy) obj).dispose();
    } catch (IllegalStateException isex) {
      assertEquals("Component has already been disposed of", isex.getMessage());
      exceptionWasThrown = true;
    }

    if (!exceptionWasThrown) {
      fail("Expected exception has never been thrown. Was the component disposed before?");
    }
  }
Exemplo n.º 2
0
  public void testLifeCycleMethods() throws Exception {
    getManager(true);
    Mock mockPool = new Mock(ObjectPool.class);
    mockPool.expect("onAdd", C.IS_NOT_NULL);
    mockPool.expect("onRemove", C.IS_NOT_NULL);
    MuleDescriptor descriptor = getTestDescriptor("apple", Apple.class.getName());
    CommonsPoolProxyFactory factory =
        (CommonsPoolProxyFactory) getProxyFactory(descriptor, (ObjectPool) mockPool.proxy());

    assertNotNull(factory);

    Object obj = factory.makeObject();
    assertNotNull(obj);
    assertTrue(factory.validateObject(obj));
    factory.activateObject(obj);
    factory.passivateObject(obj);
    factory.destroyObject(obj);
  }
Exemplo n.º 3
0
 public ObjectFactory getProxyFactory(MuleDescriptor descriptor, ObjectPool pool) {
   CommonsPoolProxyFactory factory = new CommonsPoolProxyFactory(descriptor);
   factory.setPool(pool);
   return factory;
 }