The concepts of InitialDataSets provide a convenient way to populate your test database (default the in memory database) with a predefined set of data. This means every test can rely on a well defined set of data, loaded into the database, every time a test is executed.
Ejb3Unit comes with two different InitialDataSet implementations:
The following example shows how sets of persistent objects can be created programatically. You need to extend the base class EntityInitialDataSet:
public static class OrderInitialDataSet extends EntityInitialDataSet<Order> { public StockWKNEntityInitialDataSet() { super(Order.class); } public void create() { this.add(new Order(1, "First Order")); this.add(new Order(2, "Second Order")); }
An instance of "OrderInitialDataSet" can be passed to a SessionBeanFixture or a } POJO fixture to prepopulate every test with this Order data.
CSV files provides convinient way to bulk load data into your database. CSVInitialDataSet supports comma separated files. If the special character comma is used indide a column quotes shoud be used
In this case a line wold look like: "500340","ADIDAS SALOMON AG O."," DE0005003404"
If you want to use CSVInitialDataSet a saple code look like this:
private static final CSVInitialDataSet<StockWKNBo> CSV_SET = new CSVInitialDataSet<StockWKNBo>( StockWKNBo.class, "allStocks.csv", "wkn", "isin", "symbol");