Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:16:31+00:00 2026-05-30T06:16:31+00:00

I’ve just been using DBUnit for the last 2 days and I got a

  • 0

I’ve just been using DBUnit for the last 2 days and I got a problem comparing a table with an xml file.

I’ve pasted all the code and simplified some code so people can try and find out what the problem is.

Actually, the method that does the extraction (from DB2) works well. I’ve simply added a method that is quite similar to the extract but its function is to compare a table with an XML file. In debug mode, when I get to this line : ITable tableAComparer = dataSet.getTable(table.getSchema().concat(".").concat(table.getTableName()));,
I get a NoSuchTableException which I don’t understand why…

Does anybody have a hint?

Thanks.

public abstract class TestNonRegressionAbstract extends DBTestCase {

private IDatabaseConnection   dbConn;
private Config                cfg;
private ArrayList<Table> tablesToExtract = new ArrayList<Table>();
private String path = null;

/**
 * Methode permettant de cleaner la bd avant le chargement
 * 
 * @see org.dbunit.DatabaseTestCase#setUp()
 */
protected void setUp() throws Exception {
    path = new java.io.File("").getAbsolutePath().concat("/junit/");
}

/**
 * 
 * Méthode qui extrait les tables qui doivent être backupées avant les tests
 * 
 * @throws Exception si une exception est lancée
 */
protected void extractTables() throws Exception {

    try {
        for (Table table : tablesToExtract) {
            dbConn = initDBUnitConnection(table.getSchema());
            QueryDataSet dataSet = new QueryDataSet(dbConn);
            dataSet.addTable(table.getSchema().concat(".").concat(table.getTableName()));
            FlatXmlDataSet.write(dataSet, new FileOutputStream(path + table.getNomFichier()));
            dbConn.close();
            dbConn = null;
        }
    } finally {
        if (dbConn != null)
        dbConn.close();
        dbConn = null;
    }
}

/**
 * Méthode qui compare une table de la bd avec un fichier xml contenant les valeurs de la table 
 * avant l'exécution du test.
 * 
 * @throws Exception l'exception.
 */
protected void compareTables() throws Exception {

    this.getTablesToExtract().add(new Table("PRM", "TCALENDRIER", "PRM_TCALENDRIER.XML"));
    try {
        for (Table table : tablesToExtract) {
            DiffCollectingFailureHandler myHandler = new DiffCollectingFailureHandler();
            dbConn = initDBUnitConnection(table.getSchema());
            dbConn.getConfig().setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);

            QueryDataSet dataSet = new QueryDataSet(dbConn);
            ITable tableAComparer = dataSet.getTable(table.getSchema().concat(".").concat(table.getTableName()));

            ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(tableAComparer, new String[]{"MAJPAR", "MAJTIMESTAMP"});
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new File(path + table.getNomFichier()));
            Assertion.assertEquals(expectedDataSet.getTable(table.getTableName()), filteredTable, myHandler);

            @SuppressWarnings("unchecked")
            List<Difference> diffList = myHandler.getDiffList();

            for (Difference difference : diffList) {
                System.out.println("Différence trouvé :" + difference.getColumnName() 
                        +  " Actuel:" + difference.getActualTable() +  " Attendu:" + difference.getExpectedValue());
            }
            dbConn.close();
            dbConn = null;
        }
    } finally {
        if (dbConn != null)
            dbConn.close();
            dbConn = null;
    }
}

/**
 * Méthode qui initialise la connection DBUnit
 * 
 * @param cfg
 *            la configuration avec les param BD
 * @return La connection
 * @throws Exception
 *             si erreur
 */
private IDatabaseConnection initDBUnitConnection(String schema) throws Exception {
    if (dbConn == null) {
        if (cfg == null) {
            initConfig();
        }
        String driver = cfg.getValue("CRP_DB_DRIVER");
        String dbName = cfg.getValue("CRP_DB_NAME");
        String dbUser = cfg.getValue("CRP_DB_USER");
        String dbPswd = cfg.getValue("CRP_DB_PASSWORD");
        Class.forName(driver);
        Connection connDBDemande = DriverManager.getConnection(dbName, dbUser, dbPswd);

        // Init DBUnit connection
        //dbConn = new DatabaseConnection(connDBDemande);
        dbConn = new DatabaseConnection(connDBDemande, schema);
    }
    return dbConn;
}

private void initConfig() throws Exception {
    if (cfg == null) {
        cfg = new Config("com/foo/bar/junit/nonregression/CRPTest.properties");
    }
}

/**
 * @see org.dbunit.DatabaseTestCase#getDataSet()
 */
@Override
protected IDataSet getDataSet() throws Exception {
    IDataSet databaseDataSet = getDbConn().createDataSet();
    return databaseDataSet; 
}

/**
 * 
 * Méthode qui récupère la table
 * 
 * @param table le nom de la table à récuperer
 * @return la table
 * @throws Exception si une exception survient
 */
protected ITable getDataFromTable(String table) throws Exception {

    ITable actualTable = getDataSet().getTable(table);
    return actualTable; 
}

/**
 * 
 * Méthode qui retourne la bd via DBUnit
 * 
 * @return la connection à la BD via DBUnit
 */
public IDatabaseConnection getDbConn() {
    return this.dbConn;
}


public void setDbConn(IDatabaseConnection aDbConn) {
    this.dbConn = aDbConn;
}

public class Table {

    public Table(String schema, String tableName, String nomFichier) {
        this.schema = schema;
        this.tableName = tableName;
        this.nomFichier = nomFichier;
    }

    private String schema;
    private String tableName;
    private String nomFichier;
    public String getSchema() {
        return this.schema;
    }
    public void setSchema(String aSchema) {
        this.schema = aSchema;
    }
    public String getTableName() {
        return this.tableName;
    }
    public void setTableName(String aTableName) {
        this.tableName = aTableName;
    }
    public String getNomFichier() {
        return this.nomFichier;
    }
    public void setNomFichier(String aNomFichier) {
        this.nomFichier = aNomFichier;
    }

}

public ArrayList<Table> getTablesToExtract() {
    return this.tablesToExtract;
}

public void setTablesToExtract(ArrayList<Table> aTablesToExtract) {
    this.tablesToExtract = aTablesToExtract;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:16:32+00:00Added an answer on May 30, 2026 at 6:16 am

    Finally found the answer to my problem:

    First, I needed to add the table to the QueryDataSet object (dataSet) this way.

    dataSet.addTable(table.getSchema().concat(".").concat(table.getTableName()), table.getSelectStatement());
    

    and by adding the query parameter by adding a SELECT statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an XML file, the creators of it stuck in a bunch social
In my XML file chapters tag has more chapter tag.i need to display chapters
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.