protected Map<String, Object> selectFirst(String selectSql, ConnectionSupplier connectionSupplier) { List<Map<String, Object>> rows = select(selectSql, connectionSupplier); if (rows.isEmpty()) { throw new IllegalStateException("No results for " + selectSql); } else if (rows.size() > 1) { throw new IllegalStateException("Too many results for " + selectSql); } return rows.get(0); }
public void assertColumnDefinition(String table, String column, int expectedType, @Nullable Integer expectedSize) { assertColumnDefinition(table, column, expectedType, expectedSize, null); }
/** * @deprecated do not use DBUnit */ @Deprecated public void assertDbUnit(Class testClass, String filename, String... tables) { assertDbUnit(testClass, filename, new String[0], tables); }
private void prepareDbUnit(InputStream... dataSetStream) { IDatabaseConnection connection = null; try { IDataSet[] dataSets = new IDataSet[dataSetStream.length]; for (int i = 0; i < dataSetStream.length; i++) { dataSets[i] = dbUnitDataSet(dataSetStream[i]); } db.getDbUnitTester().setDataSet(new CompositeDataSet(dataSets)); connection = dbUnitConnection(); new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, db.getDbUnitTester().getDataSet()); } catch (Exception e) { throw translateException("Could not setup DBUnit data", e); } finally { closeQuietly(connection); } }
/** * Executes a SQL request starting with "SELECT COUNT(something) FROM", for example: * <pre>int OpenIssues = countSql("select count('id') from issues where status is not null")</pre> */ public int countSql(String sql) { return countSql(sql, new NewConnectionSupplier()); }
/** * Returns the number of rows in the table. Example: * <pre>int issues = countRowsOfTable("issues")</pre> */ public int countRowsOfTable(String tableName) { return countRowsOfTable(tableName, new NewConnectionSupplier()); }
public Map<String, Object> selectFirst(DbSession dbSession, String selectSql) { return super.selectFirst(selectSql, new DbSessionConnectionSupplier(dbSession)); }
/** * Verify that non-unique index exists on columns */ public void assertIndex(String tableName, String indexName, String expectedColumn, String... expectedSecondaryColumns) { assertIndexImpl(tableName, indexName, false, expectedColumn, expectedSecondaryColumns); }
/** * @deprecated do not use DBUnit */ @Deprecated public void assertDbUnitTable(Class testClass, String filename, String table, String... columns) { IDatabaseConnection connection = dbUnitConnection(); try { IDataSet dataSet = connection.createDataSet(); String path = "/" + testClass.getName().replace('.', '/') + "/" + filename; IDataSet expectedDataSet = dbUnitDataSet(testClass.getResourceAsStream(path)); ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns); ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns); Assertion.assertEquals(filteredExpectedTable, filteredTable); } catch (DatabaseUnitException e) { fail(e.getMessage()); } catch (SQLException e) { throw translateException("Error while checking results", e); } finally { closeQuietly(connection); } }
public int countSql(DbSession dbSession, String sql) { return super.countSql(sql, new DbSessionConnectionSupplier(dbSession)); }
public int countRowsOfTable(DbSession dbSession, String tableName) { return super.countRowsOfTable(tableName, new DbSessionConnectionSupplier(dbSession)); }
public Map<String, Object> selectFirst(String selectSql) { return selectFirst(selectSql, new NewConnectionSupplier()); }
/** * Verify that unique index exists on columns */ public void assertUniqueIndex(String tableName, String indexName, String expectedColumn, String... expectedSecondaryColumns) { assertIndexImpl(tableName, indexName, true, expectedColumn, expectedSecondaryColumns); }
IDatabaseConnection connection = null; try { connection = dbUnitConnection(); throw new IllegalStateException(String.format("File '%s' does not exist", path)); IDataSet expectedDataSet = dbUnitDataSet(inputStream); for (String table : tables) { DiffCollectingFailureHandler diffHandler = new DiffCollectingFailureHandler(); fail(e.getMessage()); } catch (Exception e) { throw translateException("Error while checking results", e); } finally { closeQuietly(connection);
public List<Map<String, Object>> select(String selectSql) { return select(selectSql, new NewConnectionSupplier()); }
protected int countRowsOfTable(String tableName, ConnectionSupplier connectionSupplier) { checkArgument(StringUtils.containsNone(tableName, " "), "Parameter must be the name of a table. Got " + tableName); return countSql("select count(1) from " + tableName.toLowerCase(Locale.ENGLISH), connectionSupplier); }
public List<Map<String, Object>> select(DbSession dbSession, String selectSql) { return super.select(selectSql, new DbSessionConnectionSupplier(dbSession)); }