can't start test dbunit+h2 problem detected: org.dbunit.dataset.NoSuchTableException
Hello, everybody!
At the beginning, sorry for my mistakes in English that i can make in future.
This is my first experience to participate in forums in english.
I try test my DAO layer in the application with dbunit and local database h2.
Here is my dataset.xml
Code :
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
<Employer idEmployer="10" company_name="JetBrains" phone="237643627" email="jetBrains@soft.com"/>
<Vacancy idVacancy="8" employer_id="10" vacancy_name="java-programmer" vacancy_status="free" last_date="1990-09-24" salary="10000"/>
</dataset>
And my test class:
Code :
package testDaoLayer;
import org.dbunit.DBTestCase;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.ITable;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.dbunit.operation.DatabaseOperation;
import java.io.File;
import java.io.FileInputStream;
import java.sql.SQLException;
import static org.dbunit.PropertiesBasedJdbcDatabaseTester.*;
import static org.junit.Assert.*;
public class TestDao extends DBTestCase{
private IDataSet loadedDataSet=null;
public TestDao() throws SQLException{
super();
System.setProperty(DBUNIT_DRIVER_CLASS, "org.h2.Driver");
System.setProperty(DBUNIT_CONNECTION_URL, "jdbc:h2:~/test.public");
System.setProperty(DBUNIT_USERNAME, "sa");
System.setProperty(DBUNIT_PASSWORD, "root");
}
@Override
protected IDataSet getDataSet() throws Exception {
loadedDataSet = new FlatXmlDataSetBuilder().build(new FileInputStream("dataset.xml"));
return loadedDataSet;
}
protected DatabaseOperation getSetUpOperation(){
return DatabaseOperation.REFRESH;//CLEAN_INSERT;
}
protected DatabaseOperation getTearDownOperation() {
return DatabaseOperation.NONE;
}
public void testCheckingLoadedData() throws Exception {
// Execute the tested code that modify the database here
// ...
// Fetch database data after executing your code
IDataSet databaseDataSet = getDataSet();//getConnection().createDataSet();
ITable actualTable = databaseDataSet.getTable("Employer");
// Load expected data from an XML dataset
IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new File("dataset.xml"));
ITable expectedTable = expectedDataSet.getTable("Employer");
// Assert actual database table match expected table
assertEquals(expectedTable, actualTable);
// assertNotNull(loadedDataSet);
// int rowCount = loadedDataSet.getTable("Employer").getRowCount();
}
}
But when I run this test I get the exception:
Quote:
org.dbunit.dataset.NoSuchTableException: Employer
at org.dbunit.database.DatabaseDataSet.getTableMetaDa ta(DatabaseDataSet.java:288)
at org.dbunit.operation.AbstractOperation.getOperatio nMetaData(AbstractOperation.java:80)
at org.dbunit.operation.RefreshOperation.execute(Refr eshOperation.java:101)
at org.dbunit.AbstractDatabaseTester.executeOperation (AbstractDatabaseTester.java:190)
at org.dbunit.AbstractDatabaseTester.onSetup(Abstract DatabaseTester.java:103)
at org.dbunit.DatabaseTestCase.setUp(DatabaseTestCase .java:156)
at org.junit.internal.runners.OldTestClassRunner.run( OldTestClassRunner.java:35)
at org.junit.runner.JUnitCore.run(JUnitCore.java:121)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunn erWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepa reStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main( JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main (AppMain.java:120)
I use Intellij idea and can see my batabase in right side of ide.
I can't for a some hours solve this problem. Can you help me with it?
Thank you!