I know there have been discussions wrt to dbunit here. I have read most of them but I cant seem to find a solution to my problem.
I have set up hibernate and spring.
DbUnit classes take the default schema from the database, if the schema you want to use is not the default, you need to set the desired schema inside the .xml file and enable the recognition option of the other schemas, see the solution below. I created it.
Example.xml - Multiple Schemas
TEST CLASS
@Before
public void initialize() throws Exception{
//Insert data into database
DatabaseOperation.CLEAN_INSERT.execute(getConnection(), getDataSet());
}
@After
public void cleanup() throws Exception{
//Clean up the database
DatabaseOperation.DELETE_ALL.execute(getConnection(), getDataSet());
System.out.println("DELETADO COM SUCESSO!");
}
private IDatabaseConnection getConnection() throws Exception{
// Get the database connection
Connection con = dataSource.getConnection();
DatabaseMetaData databaseMetaData = con.getMetaData();
DatabaseConnection connection = new DatabaseConnection(con,databaseMetaData.getUserName().toUpperCase());
//Allow multiple schemas to be used
connection.getConfig().setFeature(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);
return connection;
}
private IDataSet getDataSet() throws Exception{
//Get file to insert
File file = new File("src/test/resources/Example.xml");
return new FlatXmlDataSet(file);
}