コード例 #1
0
  private void assertTableContent(
      final JdbcContentPersistenceService tested,
      final String sysContentType,
      final String id,
      final Date expectedUpdated) {
    final String tablename = tested.getTableName(sysContentType);

    try (final Connection conn = this.getTested().searchiskoDs.getConnection();
        final PreparedStatement statement =
            conn.prepareStatement(
                String.format(
                    "select sys_content_type, updated from %s where id = ?", tablename))) {
      statement.setString(1, id);
      try (final ResultSet rs = statement.executeQuery()) {
        Assert.assertTrue(rs.next());
        Assert.assertEquals(sysContentType, rs.getString(1));
        Timestamp actualTimestamp = rs.getTimestamp(2);
        if (expectedUpdated != null) {
          Assert.assertEquals(new Timestamp(expectedUpdated.getTime()), actualTimestamp);
        } else {
          Assert.assertNotNull(actualTimestamp);
        }
      }
    } catch (SQLException e) {
      Assert.fail(e.getMessage());
    }
  }
コード例 #2
0
 private void assertRowCount(
     JdbcContentPersistenceService tested, String sysContentType, int expectedCount) {
   final String tablename = tested.getTableName(sysContentType);
   int result = 0;
   try (final Connection conn = this.getTested().searchiskoDs.getConnection();
       final PreparedStatement statement =
           conn.prepareStatement(String.format("select count(*) from %s", tablename));
       final ResultSet rs = statement.executeQuery()) {
     while (rs.next()) {
       result = rs.getInt(1);
     }
     Assert.assertEquals(expectedCount, result);
   } catch (SQLException e) {
     Assert.fail(e.getMessage());
   }
 }
コード例 #3
0
  @Test
  public void countRecords() {
    JdbcContentPersistenceService tested = getTested();

    String CT = "count_test_type";

    // case - nonexisting table
    Assert.assertEquals(0, tested.countRecords(CT));

    // case - existing empty table
    tested.ensureTableExists(tested.getTableName(CT));
    Assert.assertEquals(0, tested.countRecords(CT));

    Map<String, Object> content = new HashMap<>();
    tested.store("1", CT, content);
    Assert.assertEquals(1, tested.countRecords(CT));

    tested.store("2", CT, content);
    tested.store("3", CT, content);
    tested.store("asdas", CT, content);
    Assert.assertEquals(4, tested.countRecords(CT));
  }