https://github.com/link-intersystems/dbunit-extensions
Extensions for the dbunit testing library.
https://github.com/link-intersystems/dbunit-extensions
Last synced: 4 months ago
JSON representation
Extensions for the dbunit testing library.
- Host: GitHub
- URL: https://github.com/link-intersystems/dbunit-extensions
- Owner: link-intersystems
- License: apache-2.0
- Created: 2022-04-05T08:54:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-15T05:07:52.000Z (over 3 years ago)
- Last Synced: 2025-01-01T06:14:08.410Z (over 1 year ago)
- Language: Java
- Size: 1.88 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://coveralls.io/github/link-intersystems/dbunit-extensions?branch=master)
[](https://mvnrepository.com/artifact/com.link-intersystems.dbunit)
[](https://github.com/link-intersystems/dbunit-extensions/issues)
# DBUnit compatibility
The dbunit compatibility tests, test this library against dbunit versions
[](https://mvnrepository.com/artifact/org.dbunit/dbunit) to
[](https://mvnrepository.com/artifact/org.dbunit/dbunit)

## [lis-dbunit-migration](lis-dbunit-migration/README.md)
A module that provides support for data set migration.
https://github.com/link-intersystems/dbunit-extensions/blob/beb9b68c3b4e8277bb9f67e7463770bc80383c0c/lis-dbunit-migration/lis-dbunit-migration-integration-tests/src/test/java/com/link_intersystems/dbunit/migration/DataSetMigrationDocTest.java#L28-L41
## [lis-dbunit-stream](lis-dbunit-stream/README.md)
The stream module provides a lot of utility classes for dbunit stream handling.
It also contains the `stream.commands` package that provides a high level
api for common dbunit tasks.
Connection sourceConnection = ...; // java.sql.Connection
DatabaseConnection databaseConnection = new DatabaseConnection(sourceConnection);
DatabaseDataSet databaseDataSet = new DatabaseDataSet(databaseConnection, false);
DataSetCommand migrateCommand = new DataSetCommand(databaseDataSet);
migrateCommand.setTables("actor", "film_actor", "film");
migrateCommand.setTableOrder(new DatabaseTableOrder(databaseConnection));
migrateCommand.setResultDecorator(ds -> new ConsistentDatabaseDataSet(databaseConnection, ds));
migrateCommand.setCsvConsumer("target/export/csv");
migrateCommand.exec();
## [lis-dbunit-dataset](lis-dbunit-dataset/README.md)
For details take a look at [lis-dbunit-dataset](lis-dbunit-dataset/README.md)
### TableBrowser
The `TableBrowser` can be used to extract a dataset based on a kind of extract description.
This description can be build using a domain-specific language. E.g.
https://github.com/link-intersystems/dbunit-extensions/blob/beb9b68c3b4e8277bb9f67e7463770bc80383c0c/lis-dbunit-dataset/src/test/java/com/link_intersystems/dbunit/dataset/browser/main/TableBrowserDocTest.java#L19-L31
### ConsistentDataSetLoader
The `ConsistentDataSetLoader` is another option to load consistent datasets. You can
pass it an SQL-Select statement.
https://github.com/link-intersystems/dbunit-extensions/blob/beb9b68c3b4e8277bb9f67e7463770bc80383c0c/lis-dbunit-dataset/src/test/java/com/link_intersystems/dbunit/dataset/consistency/ConsistentDataSetLoaderDocTest.java#L24-L52
## lis-dbunit-table
Provides extensions for dealing with dbunit tables.
- **MergedTable**: Merged two or more tables by the primary key definition so that the result table's rows are distinct.
- **TableList**: A list of tables that can be packed to make the tables unique using MergedTables.
- **CellRowFilter**: Filters rows based on a column predicate.
- **ColumnList**: Provides filter and query methods for a list of columns.
- **ColumnPredicates**: Convenience class that provides reusable predicates that can be applied to columns.
- **TableUtil**: Convenience methods for table related queries.
ITable table = ...;
TableUtil tableUtil = new TableUtil(table);
Row row = tableUtil.getRowById(321);
for (Object cellValua : row) {
System.out.println(cellValue)
}
## lis-dbunit-beans
Provides Java Beans support for IDataSets which allows you to define a data set from a collection of beans. Since
Java Beans are based on Java classes you can use refactoring tools to reflect database schema changes.
List> beanLists = new ArrayList<>();
BeanList employeeBeans = new BeanList<>(EmployeeBean.class, asList(EmployeeBean.king(), EmployeeBean.blake()));
beanLists.add(employeeBeans);
BeanList departmentBeans = new BeanList<>(DepartmentBean.class, asList(DepartmentBean.accounting(), DepartmentBean.sales(), DepartmentBean.research()));
beanLists.add(departmentBeans);
beanDataSet = new BeanDataSet(beanLists);
The `ITableMetaData` for bean based data sets is determined using a `BeanTableMetaDataProvider`. The `DefaultBeanTableMetaDataProvider`
can be customized by setting a `PropertyConversion`. The `PropertyConversion` is responsible for converting bean properties to
database types and vice versa. The `DefaultPropertyConversion` uses the `DefaultDataTypeRegistry` and the `DefaultPropertyTypeRegistry`
to convert property values.
## lis-dbunit-sql
Provides support for generating sql insert scripts from a IDataSet.
// Instantiate a SqlDialect
// Either from
// - com.link-intersystems.commons:lis-commons-sql
// or
// - com.link-intersystems.commons:lis-commons-sql-hibernate
SqlDialect sqlDialect = new DefaultSqlDialect();
// Create a SqlStatementWriter that generates the sql script.
Writer writer = ....; // from java.io
SqlStatementWriter sqlStatementWriter = new SqlStatementWriter(sqlDialect, writer);
// Configure the output format if needed
SqlFormatSettings sqlFormatSettings = new SqlFormatSettings();
sqlStatementWriter.setSqlFormatSettings(sqlFormatSettings);
IDataSet dataSet = ...; // A dbunit data set to export.
DataSetProducerAdapter dataSetProducerAdapter = new DataSetProducerAdapter(dataSet);
dataSetProducerAdapter.setConsumer(sqlStatementWriter);
dataSetProducerAdapter.produce();