Skip to content

Instantly share code, notes, and snippets.

@A-pZ
Last active April 6, 2022 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A-pZ/3cbff9c3b2eebb2617db3cb38dc43840 to your computer and use it in GitHub Desktop.
Save A-pZ/3cbff9c3b2eebb2617db3cb38dc43840 to your computer and use it in GitHub Desktop.
TestDatabaseConfig
package com.github.apz.sample.mapper;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.csv.CsvDataSet;
import org.springframework.core.io.Resource;
import com.github.springtestdbunit.dataset.AbstractDataSetLoader;
public class CSVDataSetLoader extends AbstractDataSetLoader {
@Override
protected IDataSet createDataSet(Resource resource) throws Exception {
return new CsvDataSet(resource.getFile());
}
}
package com.github.apz.sample.mapper;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean;
@Configuration
public class TestDatabaseConfig {
@Bean(name = "dbUnitDatabaseConnection")
public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection(DataSource dataSource) {
DatabaseDataSourceConnectionFactoryBean connectionFactory = new DatabaseDataSourceConnectionFactoryBean();
connectionFactory.setDataSource(dataSource);
return connectionFactory;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment