Exemplo n.º 1
0
  /**
   * Tests various getter/setters.
   *
   * @throws IllegalArgumentException
   * @throws IllegalAccessException
   * @throws SecurityException
   * @throws NoSuchFieldException
   */
  @SuppressWarnings("deprecation")
  @Test
  public void testSettersGetters()
      throws IllegalArgumentException, IllegalAccessException, SecurityException,
          NoSuchFieldException {
    ConnectionPartition mockPartition = createNiceMock(ConnectionPartition.class);
    testClass.setOriginatingPartition(mockPartition);
    assertEquals(mockPartition, testClass.getOriginatingPartition());

    testClass.setConnectionLastReset(123);
    assertEquals(testClass.getConnectionLastReset(), 123);

    testClass.setConnectionLastUsed(456);
    assertEquals(testClass.getConnectionLastUsed(), 456);

    Field field = testClass.getClass().getDeclaredField("possiblyBroken");
    field.setAccessible(true);
    field.setBoolean(testClass, true);
    assertTrue(testClass.isPossiblyBroken());

    Object debugHandle = new Object();
    testClass.setDebugHandle(debugHandle);
    assertEquals(debugHandle, testClass.getDebugHandle());

    testClass.setInternalConnection(mockConnection);
    assertEquals(mockConnection, testClass.getInternalConnection());
    assertEquals(mockConnection, testClass.getRawConnection());

    field = testClass.getClass().getDeclaredField("logicallyClosed");
    field.setAccessible(true);
    field.setBoolean(testClass, true);
    assertTrue(testClass.isClosed());

    testClass.setLogStatementsEnabled(true);
    assertTrue(testClass.isLogStatementsEnabled());

    assertEquals(testClass.getPool(), mockPool);
    ArrayList<ReplayLog> testLog = new ArrayList<ReplayLog>();
    testClass.setReplayLog(testLog);
    assertEquals(testClass.getReplayLog(), testLog);
    testClass.setInReplayMode(true);
    assertTrue(testClass.isInReplayMode());
    testClass.setInReplayMode(false);

    testClass.threadUsingConnection = Thread.currentThread();
    assertEquals(Thread.currentThread(), testClass.getThreadUsingConnection());
  }
Exemplo n.º 2
0
  /**
   * Tests sendInitialSQL method.
   *
   * @throws SecurityException
   * @throws NoSuchFieldException
   * @throws IllegalArgumentException
   * @throws IllegalAccessException
   * @throws SQLException
   */
  @Test
  public void testSendInitialSQL()
      throws SecurityException, NoSuchFieldException, IllegalArgumentException,
          IllegalAccessException, SQLException {

    BoneCPConfig mockConfig = createNiceMock(BoneCPConfig.class);
    expect(mockPool.getConfig()).andReturn(mockConfig).anyTimes();

    expect(mockConfig.getInitSQL()).andReturn("test").anyTimes();
    testClass.setInternalConnection(mockConnection);

    Statement mockStatement = createNiceMock(Statement.class);
    ResultSet mockResultSet = createNiceMock(ResultSet.class);
    expect(mockConnection.createStatement()).andReturn(mockStatement).once();
    expect(mockStatement.executeQuery("test")).andReturn(mockResultSet).once();
    mockResultSet.close();
    expectLastCall().once();

    replay(mockConfig, mockPool, mockConnection, mockStatement, mockResultSet);
    testClass.sendInitSQL();
    verify(mockConfig, mockPool, mockConnection, mockStatement, mockResultSet);
  }