Advertisement

08.31.2006 at 11:37PM PDT, ID: 21975024
[x]
Attachment Details

DBUNIT Program Error

Asked by JavaGuru2003 in Java Programming Language

Tags: dbunit

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.FileUtils;
import org.dbunit.Assertion;
import org.dbunit.DatabaseTestCase;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.database.QueryDataSet;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
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.OracleDriver");
        Connection jdbcConnection = DriverManager.getConnection("jdbc:oracle:thin:@ip:port:sid", "uname", "pwd");
        return new DatabaseConnection(jdbcConnection);
    }

    protected IDataSet getDataSet() throws Exception {
            loadedDataSet = new FlatXmlDataSet(new FileInputStream("output_p.xml"));
            return loadedDataSet;
    }
      
    public void testCheckDataLoaded() throws Exception {
            assertNotNull(loadedDataSet);
        int rowCount = loadedDataSet.getTable("MANUFACTURER").getRowCount();
        assertEquals(2, rowCount);
    }

    public void testCompareDataSet() throws Exception {
            IDataSet createdDataSet = getConnection().createDataSet(new String[]{"MANUFACTURER"});
        Assertion.assertEquals(loadedDataSet, createdDataSet);
    }

    public void testCompareQuery() throws Exception {
            QueryDataSet queryDataSet = new QueryDataSet(getConnection());
        queryDataSet.addTable("MANUFACTURER", "SELECT * FROM MANUFACTURER");
        Assertion.assertEquals(loadedDataSet, 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(loadedDataSet);
        int rowCount = loadedDataSet.getTable("MANUFACTURER").getRowCount();
        assertEquals(4, rowCount);
    }

and then compile and run its giving failure

..F.F
Time: 5.297
There were 2 failures:
1) testCompareDataSet(SampleTest)junit.framework.AssertionFailedError: value (table=MANUFACTURER, row=0, col=ID): expected:<3> but was:<5>
        at org.dbunit.Assertion.assertEquals(Assertion.java:147)
        at org.dbunit.Assertion.assertEquals(Assertion.java:80)
        at SampleTest.testCompareDataSet(SampleTest.java:44)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2) testCompareQuery(SampleTest)junit.framework.AssertionFailedError: value (table=MANUFACTURER, row=0, col=ID): expected:<3> but was:<5>
        at org.dbunit.Assertion.assertEquals(Assertion.java:147)
        at org.dbunit.Assertion.assertEquals(Assertion.java:80)
        at SampleTest.testCompareQuery(SampleTest.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(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
[+][-]08.31.2006 at 11:58PM PDT, ID: 17435012

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.31.2006 at 11:58PM PDT, ID: 17435016

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:09AM PDT, ID: 17435044

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:15AM PDT, ID: 17435063

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:20AM PDT, ID: 17435078

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:29AM PDT, ID: 17435110

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:31AM PDT, ID: 17435122

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:32AM PDT, ID: 17435126

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:34AM PDT, ID: 17435129

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:37AM PDT, ID: 17435144

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:39AM PDT, ID: 17435152

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:42AM PDT, ID: 17435162

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:44AM PDT, ID: 17435167

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:48AM PDT, ID: 17435177

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 12:56AM PDT, ID: 17435199

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 01:04AM PDT, ID: 17435226

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.01.2006 at 01:07AM PDT, ID: 17435237

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: dbunit
Sign Up Now!
Solution Provided By: objects
Participating Experts: 3
Solution Grade: A
 
 
[+][-]09.01.2006 at 01:09AM PDT, ID: 17435245

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.07.2006 at 03:06AM PDT, ID: 17469374

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.07.2006 at 04:28PM PDT, ID: 17475725

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32