Hello,
Below is a program which is working fine when the output_p.xml has 2 data when i modify the output_p.xml for 3 or 4 data its starting giving error .. faliure
output_p.xml
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
<MANUFACTURER NAME="HUTCH" ID="3"/>
<MANUFACTURER NAME="ERIC" ID="4"/>
</dataset>
import java.io.FileInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import org.apache.commons.io.File
Utils;
import org.dbunit.Assertion;
import org.dbunit.DatabaseTestCas
e;
import org.dbunit.database.Databa
seConnecti
on;
import org.dbunit.database.IDatab
aseConnect
ion;
import org.dbunit.database.QueryD
ataSet;
import org.dbunit.dataset.IDataSe
t;
import org.dbunit.dataset.xml.Fla
tXmlDataSe
t;
import org.dbunit.operation.*;
public class SampleTest extends DatabaseTestCase {
public SampleTest(String name) {
super(name);
}
private FlatXmlDataSet loadedDataSet;
protected IDatabaseConnection getConnection() throws Exception {
Class driverClass = Class.forName("oracle.jdbc
.OracleDri
ver");
Connection jdbcConnection = DriverManager.getConnectio
n("jdbc:or
acle:thin:
@ip:port:s
id", "uname", "pwd");
return new DatabaseConnection(jdbcCon
nection);
}
protected IDataSet getDataSet() throws Exception {
loadedDataSet = new FlatXmlDataSet(new FileInputStream("output_p.
xml"));
return loadedDataSet;
}
public void testCheckDataLoaded() throws Exception {
assertNotNull(loadedDataSe
t);
int rowCount = loadedDataSet.getTable("MA
NUFACTURER
").getRowC
ount();
assertEquals(2, rowCount);
}
public void testCompareDataSet() throws Exception {
IDataSet createdDataSet = getConnection().createData
Set(new String[]{"MANUFACTURER"});
Assertion.assertEquals(loa
dedDataSet
, createdDataSet);
}
public void testCompareQuery() throws Exception {
QueryDataSet queryDataSet = new QueryDataSet(getConnection
());
queryDataSet.addTable("MAN
UFACTURER"
, "SELECT * FROM MANUFACTURER");
Assertion.assertEquals(loa
dedDataSet
, queryDataSet);
}
}
Now if i change the output_p.xml to below
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
<MANUFACTURER NAME="HUTCH" ID="3"/>
<MANUFACTURER NAME="ERIC" ID="4"/>
<MANUFACTURER NAME="H" ID="5"/>
<MANUFACTURER NAME="E" ID="6"/>
</dataset>
and modify the program to refect 4 rows
public void testCheckDataLoaded() throws Exception {
assertNotNull(loadedDataSe
t);
int rowCount = loadedDataSet.getTable("MA
NUFACTURER
").getRowC
ount();
assertEquals(4, rowCount);
}
and then compile and run its giving failure
..F.F
Time: 5.297
There were 2 failures:
1) testCompareDataSet(SampleT
est)junit.
framework.
AssertionF
ailedError
: value (table=MANUFACTURER, row=0, col=ID): expected:<3> but was:<5>
at org.dbunit.Assertion.asser
tEquals(As
sertion.ja
va:147)
at org.dbunit.Assertion.asser
tEquals(As
sertion.ja
va:80)
at SampleTest.testCompareData
Set(Sample
Test.java:
44)
at sun.reflect.NativeMethodAc
cessorImpl
.invoke0(N
ative Method)
at sun.reflect.NativeMethodAc
cessorImpl
.invoke(Un
known Source)
at sun.reflect.DelegatingMeth
odAccessor
Impl.invok
e(Unknown Source)
2) testCompareQuery(SampleTes
t)junit.fr
amework.As
sertionFai
ledError: value (table=MANUFACTURER, row=0, col=ID): expected:<3> but was:<5>
at org.dbunit.Assertion.asser
tEquals(As
sertion.ja
va:147)
at org.dbunit.Assertion.asser
tEquals(As
sertion.ja
va:80)
at SampleTest.testCompareQuer
y(SampleTe
st.java:50
)
at sun.reflect.NativeMethodAc
cessorImpl
.invoke0(N
ative Method)
at sun.reflect.NativeMethodAc
cessorImpl
.invoke(Un
known Source)
at sun.reflect.DelegatingMeth
odAccessor
Impl.invok
e(Unknown Source)
FAILURES!!!
Tests run: 3, Failures: 2, Errors: 0
Please let me know why the program works for 2 rows and when i increase the rows it started giving error
Thanks
Start Free Trial