差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| study:java:dbunit:testdata [2020/05/20 06:38] – [Prepare test data] banana | study:java:dbunit:testdata [2020/05/20 06:43] (現在) – [Restore table data] banana | ||
|---|---|---|---|
| 行 19: | 行 19: | ||
| //prepare backup file | //prepare backup file | ||
| QueryDataSet _partialDataSet = new QueryDataSet(_connection); | QueryDataSet _partialDataSet = new QueryDataSet(_connection); | ||
| - | _partialDataSet.addTable(" | + | _partialDataSet.addTable(" |
| backupFile = File.createTempFile(" | backupFile = File.createTempFile(" | ||
| //write table data to file | //write table data to file | ||
| 行 61: | 行 61: | ||
| </ | </ | ||
| + | ====== Restore table data ====== | ||
| + | テスト実施後、テーブルデータを元に復元するソースコードを以下に示す。 | ||
| + | |||
| + | <code java> | ||
| + | public class TestSomeTableTransactionService extends AbstractCustomTestCase { | ||
| + | //table backup file | ||
| + | private File backupFile; | ||
| + | |||
| + | /* (non-Javadoc) | ||
| + | * @see parent.AbstractCustomTestCase# | ||
| + | */ | ||
| + | @Override | ||
| + | protected void tearDownHook() throws Exception { | ||
| + | IDatabaseConnection _connection = null; | ||
| + | try { | ||
| + | _connection = databaseTester.getConnection(); | ||
| + | //restore backup file | ||
| + | FlatXmlDataSetBuilder _builder = new FlatXmlDataSetBuilder(); | ||
| + | IDataSet _dataSet = _builder.build(backupFile); | ||
| + | DatabaseOperation.CLEAN_INSERT.execute(_connection, | ||
| + | } finally { | ||
| + | if (_connection != null) _connection.close(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||