Package org.dbunit

Examples of org.dbunit.DatabaseUnitException


      try {
    IDataSet testDataSet = new FlatXmlDataSet(new FileInputStream(flatXMLFile));
    DatabaseOperation.REFRESH.execute(getDatabaseConnection(),testDataSet);
    testDataSets.add(testDataSet);
      }catch(AmbiguousTableNameException e) {
          throw new DatabaseUnitException("出现AmbiguousTableNameException异常,使用命令:purge recyclebin清空一下oracle回收站,并为dbunit指定jdbcSchema",e);
      }
  }
View Full Code Here


            Object o = Class.forName(className).newInstance();
            return o;
        }
        catch (ClassNotFoundException e)
        {
            throw new DatabaseUnitException(
                    "Class Not Found: '" + className + "' could not be loaded", e);
        }
        catch (IllegalAccessException e)
        {
            throw new DatabaseUnitException(
                    "Illegal Access: '" + className + "' could not be loaded", e);
        }
        catch (InstantiationException e)
        {
            throw new DatabaseUnitException(
                    "Instantiation Exception: '" + className + "' could not be loaded", e);
        }
    }
View Full Code Here

        // implementation of 'DatabaseMetaData.getSchemas()' is not correct
              // (known issue of MySQL driver).
              String msg = "The given schema '" + this._schema + "' does not exist.";
              // If strict validation is wished throw an exception
              if(validateStrict)
                throw new DatabaseUnitException(msg);
              else
                logger.warn(msg);
            }
        }
        catch(SQLException e)
        {
            throw new DatabaseUnitException("Exception while checking the schema for validity", e);
        }
    }
View Full Code Here

        try
        {
            if (_dest == null)
            {
                throw new DatabaseUnitException("'_dest' is a required attribute of the <export> step.");
            }

            IDataSet dataset = getExportDataSet(connection);
      log("dataset tables: " + Arrays.asList(dataset.getTableNames()), Project.MSG_VERBOSE);

     
            // Write the dataset
            if (_format.equals(FORMAT_CSV))
            {
                CsvDataSetWriter.write(dataset, _dest);
            }
            else
            {
                OutputStream out = new FileOutputStream(_dest);
                try
                {
                    if (_format.equalsIgnoreCase(FORMAT_FLAT))
                    {
                        FlatXmlWriter writer = new FlatXmlWriter(out, getEncoding());
                        writer.setDocType(_doctype);
                        writer.write(dataset);
                    }
                    else if (_format.equalsIgnoreCase(FORMAT_XML))
                    {
                        XmlDataSet.write(dataset, out, getEncoding());
                    }
                    else if (_format.equalsIgnoreCase(FORMAT_DTD))
                    {
                        //TODO Should DTD also support encoding? It is basically an XML file...
                        FlatDtdDataSet.write(dataset, out);//, getEncoding());
                    }
                    else if (_format.equalsIgnoreCase(FORMAT_XLS))
                    {
                        XlsDataSet.write(dataset, out);
                    }
                    else
                    {
                        throw new IllegalArgumentException("The given format '"+_format+"' is not supported.");
                    }
                   
                }
                finally
                {
                    out.close();
                }
            }
           
            log("Successfully wrote file '" + _dest + "'", Project.MSG_INFO);
           
        }
        catch (SQLException e)
        {
          throw new DatabaseUnitException(e);
        }
        catch (IOException e)
        {
            throw new DatabaseUnitException(e);
        }
    }
View Full Code Here

    public void execute(IDatabaseConnection connection) throws DatabaseUnitException
    {
        logger.debug("execute(connection={}) - start", connection);
        if (_operation == null)
        {
            throw new DatabaseUnitException("Operation.execute(): setType(String) must be called before execute()!");
        }

        if (_operation == DatabaseOperation.NONE)
        {
            return;
        }

        try {
            DatabaseOperation operation = (_transaction ? new TransactionOperation(_operation) : _operation);
            // TODO This is not very nice and the design should be reviewed but it works for now (gommma)
            boolean useForwardOnly = _forwardOperation && ! isOrdered();
            IDataSet dataset = getSrcDataSet(getSrc(), getFormat(), useForwardOnly);
            if (_nullToken != null) {
                dataset = new ReplacementDataSet(dataset);
                ((ReplacementDataSet)dataset).addReplacementObject(_nullToken, null);
            }
            if(isOrdered())
            {
                DatabaseSequenceFilter databaseSequenceFilter = new DatabaseSequenceFilter(connection);
                dataset = new FilteredDataSet(databaseSequenceFilter, dataset);
            }
            operation.execute(connection, dataset);
        }
        catch (SQLException e)
        {
            throw new DatabaseUnitException(e);
        }
    }
View Full Code Here

      IDataSet[] dataSetsArray = (IDataSet[])queryDataSets.toArray( new IDataSet[queryDataSets.size()] );
            return new CompositeDataSet(dataSetsArray);
        }
        catch (SQLException e)
        {
            throw new DatabaseUnitException(e);
        }
    }
View Full Code Here

            }
            return new CachedDataSet(producer);
        }
        catch (IOException e)
        {
            throw new DatabaseUnitException(e);
        }
    }
View Full Code Here

            String tableName = tableNames[i];
            ITable expectedTable;
      try {
        expectedTable = expectedDataset.getTable(tableName);
      } catch (NoSuchTableException e) {
        throw new DatabaseUnitException("Did not find table in source file '" +
            _src + "' using format '" + getFormat() + "'", e);
      }
            ITableMetaData expectedMetaData = expectedTable.getTableMetaData();

            ITable actualTable;
      try {
        actualTable = actualDataset.getTable(tableName);
      } catch (NoSuchTableException e) {
        throw new DatabaseUnitException("Did not find table in actual dataset '" +
            actualDataset + "' via db connection '" + connection + "'", e);
      }
            // Only compare columns present in expected table. Extra columns
            // are filtered out from actual database table.
            actualTable = DefaultColumnFilter.includedColumnsTable(
View Full Code Here

    {
        try
        {
            if (_dest == null)
            {
                throw new DatabaseUnitException("'_dest' is a required attribute of the <export> step.");
            }

            IDataSet dataset = getDatabaseDataSet(connection, _tables, false);

      log("dataset tables: " + Arrays.asList(dataset.getTableNames()), Project.MSG_VERBOSE);
     
            // Write the dataset
            if (_format.equals(FORMAT_CSV))
            {
                CsvDataSetWriter.write(dataset, _dest);
            }
            else
            {
                OutputStream out = new FileOutputStream(_dest);
                try
                {
                    if (_format.equalsIgnoreCase(FORMAT_FLAT))
                    {
                        FlatXmlWriter writer = new FlatXmlWriter(out);
                        writer.setDocType(_doctype);
                        writer.write(dataset);
                    }
                    else if (_format.equalsIgnoreCase(FORMAT_XML))
                    {
                        XmlDataSet.write(dataset, out);
                    }
                    else if (_format.equalsIgnoreCase(FORMAT_DTD))
                    {
                        FlatDtdDataSet.write(dataset, out);
                    }
                   
                }
                finally
                {
                    out.close();
                }
            }
           
        }
        catch (IOException e)
        {
            throw new DatabaseUnitException(e);
        }
    }
View Full Code Here

    public void execute(IDatabaseConnection connection) throws DatabaseUnitException
    {
        if (_operation == null)
        {
            throw new DatabaseUnitException("Operation.execute(): setType(String) must be called before execute()!");
        }

        if (_operation == DatabaseOperation.NONE)
        {
            return;
        }

        try
        {
              DatabaseOperation operation = (_transaction ? new TransactionOperation(_operation) : _operation);
            IDataSet dataset = getSrcDataSet(getSrc(), getFormat(), _forwardOperation);
            operation.execute(connection, dataset);
        }
        catch (SQLException e)
        {
            throw new DatabaseUnitException(e);
        }
    }
View Full Code Here

TOP

Related Classes of org.dbunit.DatabaseUnitException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.