Package com.p6spy.engine.test

Examples of com.p6spy.engine.test.TestConnectionImpl


public class P6WrapperUnwrapDelegateTest extends BaseTestCase {

  @Test
  public void testCastableFromProxy() throws SQLException {
    Connection con = new TestConnectionImpl();
    Connection proxy = ProxyFactory.createProxy(con, new GenericInvocationHandler<Connection>(con));

    // if the proxy implements the interface then the proxy should be returned
    {
      Connection unwrapped = proxy.unwrap(Connection.class);
      assertTrue(ProxyFactory.isProxy(unwrapped));
    }

    {
      TestConnection unwrapped = proxy.unwrap(TestConnection.class);
      assertTrue(ProxyFactory.isProxy(unwrapped));
    }

    {
      Wrapper unwrapped = proxy.unwrap(Wrapper.class);
      assertTrue(ProxyFactory.isProxy(unwrapped));
    }

    {
      AutoCloseable unwrapped = proxy.unwrap(AutoCloseable.class);
      assertTrue(ProxyFactory.isProxy(unwrapped));
    }

    // TestConnectionImpl is not implemented by the proxy - proxy will not be returned
    {
      TestConnectionImpl unwrapped = proxy.unwrap(TestConnectionImpl.class);
      assertFalse(ProxyFactory.isProxy(unwrapped));
    }

  }
View Full Code Here


  }

  @Test
  public void testCastableFromUnderlying() throws SQLException {
    Connection con = new TestConnectionImpl();
    Connection proxy = ProxyFactory.createProxy(con, new GenericInvocationHandler<Connection>(con));

    // if the underlying object extends the class (or matches the class) then the underlying object should be returned.
    {
      AbstractTestConnection unwrapped = proxy.unwrap(AbstractTestConnection.class);
      assertFalse(ProxyFactory.isProxy(unwrapped));
    }

    {
      TestConnectionImpl unwrapped = proxy.unwrap(TestConnectionImpl.class);
      assertFalse(ProxyFactory.isProxy(unwrapped));
    }

  }
View Full Code Here

  }

  @Test
  public void testProxyOfWrappedConnection() throws SQLException {
    // this will be the actual connection
    Connection con = new TestConnectionImpl();

    // use a wrapper from DBCP to create a proxy of a proxy
    // Note: DBCP implements with JDBC 4.0 API so the Wrapper interface
    // is implemented here.
    DelegatingConnection underlying = new DelegatingConnection(con);
View Full Code Here

public class P6WrapperIsWrapperDelegateTest extends BaseTestCase {

  @Test
  public void testCastableFromProxy() throws SQLException {
    Connection con = new TestConnectionImpl();
    Connection proxy = ProxyFactory.createProxy(con, new GenericInvocationHandler<Connection>(con));

    // if the proxy implements the interface then true should be returned.
    assertTrue(proxy.isWrapperFor(Connection.class));
    assertTrue(proxy.isWrapperFor(TestConnection.class));
View Full Code Here

    assertTrue(proxy.isWrapperFor(Wrapper.class));
  }

  @Test
  public void testCastableFromUnderlying() throws SQLException {
    Connection con = new TestConnectionImpl();
    Connection proxy = ProxyFactory.createProxy(con, new GenericInvocationHandler<Connection>(con));

    // if the underlying object extends the class (or matches the class) then true should be returned.
    assertTrue(proxy.isWrapperFor(TestConnectionImpl.class));
    assertTrue(proxy.isWrapperFor(AbstractTestConnection.class));
View Full Code Here

  }

  @Test
  public void testProxyOfWrappedConnection() throws SQLException {
    // this will be the actual connection
    Connection con = new TestConnectionImpl();

    // use a wrapper from DBCP to create a proxy of a proxy
    // Note: DBCP implements with JDBC 4.0 API so the Wrapper interface
    // is implemented here.
    DelegatingConnection underlying = new DelegatingConnection(con);
View Full Code Here

TOP

Related Classes of com.p6spy.engine.test.TestConnectionImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.