Beispiel #1
0
  public void assertResultSetOrderAgnostic(
      final ResultSet resultSet, final List<DBQueries.Row<Integer, String>> rows) {

    try {
      List<DBQueries.Row<Integer, String>> actual =
          new ArrayList<DBQueries.Row<Integer, String>>(rows.size());
      while (resultSet.next()) {
        actual.add(new DBQueries.Row<Integer, String>(resultSet.getInt(1), resultSet.getString(2)));
      }

      Comparator<DBQueries.Row<Integer, String>> comparator =
          new Comparator<DBQueries.Row<Integer, String>>() {
            @Override
            public int compare(
                DBQueries.Row<Integer, String> o1, DBQueries.Row<Integer, String> o2) {
              int objectKeyComparison = o1.getObjectKey().compareTo(o2.getObjectKey());
              if (objectKeyComparison != 0) {
                return objectKeyComparison;
              }
              return o1.getValue().compareTo(o2.getValue());
            }
          };

      Collections.sort(actual, comparator);
      Collections.sort(rows, comparator);

      Assert.assertEquals(rows, actual);
    } catch (Exception e) {
      throw new IllegalStateException("Unable to verify resultSet", e);
    }
  }
Beispiel #2
0
  public void assertResultSetObjectKeysOrderAgnostic(
      final ResultSet resultSet, final List<Integer> objectKeys) {
    try {
      List<Integer> actual = new ArrayList<Integer>(objectKeys.size());
      while (resultSet.next()) {
        actual.add(resultSet.getInt(1));
      }

      Collections.sort(actual);
      Collections.sort(objectKeys);

      Assert.assertEquals(objectKeys, actual);

    } catch (Exception e) {
      throw new IllegalStateException("Unable to verify resultSet", e);
    }
  }
Beispiel #3
0
  @Test
  public void testBulkRemove() throws SQLException {

    Connection connection = null;
    try {
      ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true);
      initWithTestData(connectionManager);

      List<DBQueries.Row<Integer, String>> expectedRows =
          new ArrayList<DBQueries.Row<Integer, String>>(2);
      expectedRows.add(new DBQueries.Row<Integer, String>(2, "airbags"));
      expectedRows.add(new DBQueries.Row<Integer, String>(3, "abs"));

      connection = connectionManager.getConnection(null);
      DBQueries.bulkRemove(Collections.singletonList(1), NAME, connection);
      assertQueryResultSet("SELECT * FROM " + TABLE_NAME, expectedRows, connectionManager);

    } finally {
      DBUtils.closeQuietly(connection);
    }
  }
Beispiel #4
0
  @Test
  public void testClearIndexTable() throws SQLException {
    Connection connection = null;
    Statement statement = null;
    try {
      ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true);
      createSchema(connectionManager);
      assertObjectExistenceInSQLIteMasterTable(TABLE_NAME, "table", true, connectionManager);
      assertObjectExistenceInSQLIteMasterTable(INDEX_NAME, "index", true, connectionManager);

      connection = spy(connectionManager.getConnection(null));
      statement = spy(connection.createStatement());
      when(connection.createStatement()).thenReturn(statement);
      DBQueries.clearIndexTable(NAME, connection);

      List<DBQueries.Row<Integer, String>> expectedRows = Collections.emptyList();
      assertQueryResultSet("SELECT * FROM " + TABLE_NAME, expectedRows, connectionManager);
      verify(statement, times(1)).close();
    } finally {
      DBUtils.closeQuietly(connection);
      DBUtils.closeQuietly(statement);
    }
  }