@Test
  public void testWrapper() throws Exception {
    Connection conn = getConnection();

    assertTrue(conn.isWrapperFor(JcrConnection.class));

    try {
      conn.isWrapperFor(null);
      fail();
    } catch (IllegalArgumentException ignore) {
    }

    assertFalse(conn.isWrapperFor(Session.class));

    JcrConnection jcrConn = conn.unwrap(JcrConnection.class);
    Session jcrSession = jcrConn.getSession();
    assertNotNull(jcrSession);
    assertTrue(jcrSession.isLive());

    try {
      conn.unwrap(null);
      fail();
    } catch (IllegalArgumentException ignore) {
    }

    try {
      conn.unwrap(Session.class);
      fail();
    } catch (SQLException ignore) {
    }

    conn.close();
  }
  @Test
  public void testCastableFromUnderlying() throws SQLException {
    Connection con = new TestConnectionImpl();
    Connection proxy =
        ConnectionWrapper.wrap(
            con, noOpEventListener, ConnectionInformation.fromTestConnection(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));
  }
  @Test
  public void testCastableFromProxy() throws SQLException {
    Connection con = new TestConnectionImpl();
    Connection proxy =
        ConnectionWrapper.wrap(
            con, noOpEventListener, ConnectionInformation.fromTestConnection(con));

    // if the proxy implements the interface then true should be returned.
    assertTrue(proxy.isWrapperFor(Connection.class));
    assertTrue(proxy.isWrapperFor(TestConnection.class));
    assertTrue(proxy.isWrapperFor(Wrapper.class));
  }
Example #4
0
  /**
   * Case 1
   *
   * @exception Throwable Thrown if case of an error
   */
  @Test
  public void testIsWraperForSelf() throws Throwable {
    assertNotNull(ds);
    Connection c = ds.getConnection();
    assertNotNull(c);

    assertTrue(c.isWrapperFor(Connection.class));

    c.close();
  }
Example #5
0
  /**
   * Case 2
   *
   * @exception Throwable Thrown if case of an error
   */
  @Test
  public void testIsWrapperForDirect() throws Throwable {
    assertNotNull(ds);
    Connection c = ds.getConnection();
    assertNotNull(c);

    assertTrue(c.isWrapperFor(org.h2.jdbc.JdbcConnection.class));

    c.close();
  }
  @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);

    Connection proxy =
        ConnectionWrapper.wrap(
            underlying, noOpEventListener, ConnectionInformation.fromTestConnection(con));

    // TestConnection is an interface of the wrapped underlying object.
    assertTrue(proxy.isWrapperFor(TestConnection.class));

    // ResultSet is not implemented at all - false should be returned
    assertFalse(proxy.isWrapperFor(ResultSet.class));
  }
Example #7
0
  @Override
  public boolean isWrapperFor(Class<?> iface) throws SQLException {
    if (iface == null) {
      return false;
    }

    if (iface.isInstance(this)) {
      return true;
    }

    return conn.isWrapperFor(iface);
  }
 public boolean isWrapperFor(Class<?> iface) throws SQLException {
   String methodCall = "isWrapperFor(" + (iface == null ? "null" : iface.getName()) + ")";
   try {
     return reportReturn(
         methodCall,
         (iface != null && (iface == Connection.class || iface == Spy.class))
             || realConnection.isWrapperFor(iface));
   } catch (SQLException s) {
     reportException(methodCall, s);
     throw s;
   }
 }
 public boolean isWrapperFor(Class<?> iface) throws SQLException {
   return connection.isWrapperFor(iface);
 }
Example #10
0
 public boolean isWrapperFor(Class<?> aClass) throws SQLException {
   return conn.isWrapperFor(aClass);
 }
 @Override
 public boolean isWrapperFor(Class<?> iface) throws SQLException {
   return _wrapped.isWrapperFor(iface);
 }