From: <fg...@us...> - 2008-01-26 18:39:40
|
Revision: 549 http://openutils.svn.sourceforge.net/openutils/?rev=549&view=rev Author: fgiust Date: 2008-01-26 10:39:46 -0800 (Sat, 26 Jan 2008) Log Message: ----------- javadocs Modified Paths: -------------- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitConfiguration.java trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java trunk/openutils-testing/src/main/java/it/openutils/testing/RegExpTableFilter.java Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitConfiguration.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitConfiguration.java 2008-01-26 18:14:12 UTC (rev 548) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitConfiguration.java 2008-01-26 18:39:46 UTC (rev 549) @@ -24,6 +24,7 @@ /** + * A DbUnitConfiguration can contain one or more {@link DbUnitExecution}. * @author fgiust * @version $Id: $ */ @@ -33,6 +34,11 @@ @Documented public @interface DbUnitConfiguration { - DbUnitExecution[] dbUnitExecutions() default {}; + /** + * Array of {@link DbUnitExecution} + */ + DbUnitExecution[] dbUnitExecutions() default { + }; + } \ No newline at end of file Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-01-26 18:14:12 UTC (rev 548) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-01-26 18:39:46 UTC (rev 549) @@ -38,18 +38,41 @@ /** * The resource locations to use for loading dbunit dataset. */ - String[] datasets() default {}; + String[] datasets() default { + }; + + /** + * The name of the datasource to use. If can be left unset only if there is only one DataSource available in the + * Spring context. + */ String dataSource() default ""; + /** + * Db schema name that will be given to dbUnit. Can be left unset if not needed (database specific) + */ String schema() default ""; + /** + * A regexp that can match table names. Any table matching this regular expression will not be considered by DbUnit. + * By default tables starting with $ are ignored (oracle recycle bin). + */ String excludedTables() default "(^\\$(.*))"; // oracle recycle bin + /** + * If true, <strong>all</strong> the tables in the database will be truncated before loading any dataset. + */ boolean truncateAll() default true; + /** + * The database operation that will be used to truncate tables. Defaults to + * org.dbunit.operation.TruncateTableOperation + */ Class< ? extends DatabaseOperation> truncateOperation() default org.dbunit.operation.TruncateTableOperation.class; + /** + * The database operation that will be used to load datasets. Defaults to org.dbunit.operation.InsertOperation + */ Class< ? extends DatabaseOperation> insertOperation() default org.dbunit.operation.InsertOperation.class; } \ No newline at end of file Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-01-26 18:14:12 UTC (rev 548) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-01-26 18:39:46 UTC (rev 549) @@ -15,11 +15,7 @@ */ package it.openutils.testing; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.net.URL; import java.sql.SQLException; import java.util.HashMap; @@ -36,10 +32,8 @@ import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.FilteredDataSet; import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.excel.XlsDataSet; import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.dataset.filter.SequenceTableFilter; -import org.dbunit.dataset.xml.XmlDataSet; import org.dbunit.operation.DatabaseOperation; import org.dbunit.operation.DeleteAllOperation; import org.dbunit.operation.DeleteOperation; @@ -322,39 +316,4 @@ return (DataSource) applicationContext.getBean(name); } - /** - * Exports a list of table to an xml/xsl file - * @param file The file name we save the dataset to - * @param dataSource datasource to use - * @param schema optional schema name - * @param tableNames optional list of table names - * @throws IOException An IO Exception. - * @throws DataSetException A dataset exception. - * @throws SQLException A SQL Exception. - */ - public void exportDataset(File file, DataSource dataSource, String schema, String[] tableNames) throws IOException, - DataSetException, SQLException - { - IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection(), schema); - - IDataSet fullDataSet = connection.createDataSet(); - - if (tableNames != null && tableNames.length > 0) - { - fullDataSet = new FilteredDataSet(tableNames, fullDataSet); - } - - OutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); - if (file.getName().toLowerCase().endsWith(".xls")) - { - XlsDataSet.write(fullDataSet, fos); - } - else - { - XmlDataSet.write(fullDataSet, fos); - } - fos.close(); - - log.info("Dataset exported at {}", file.getAbsolutePath()); - } } Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-26 18:14:12 UTC (rev 548) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-26 18:39:46 UTC (rev 549) @@ -47,14 +47,22 @@ private static Logger log = LoggerFactory.getLogger(DbUnitUtils.class); /** - * @param connection - * @param tableNames - * @param file - * @param xls - * @throws SQLException - * @throws IOException - * @throws DataSetException + * Do not instantiate. */ + private DbUnitUtils() + { + // do not instantiate + } + + /** + * Exports a list of table to an xml/xsl file + * @param file The file name we save the dataset to + * @param connection connection to use + * @param tableNames optional list of table names + * @throws IOException An IO Exception. + * @throws DataSetException A dataset exception. + * @throws SQLException A SQL Exception. + */ public static void exportDataset(IDatabaseConnection connection, String[] tableNames, File file) throws SQLException, IOException, DataSetException { @@ -89,10 +97,10 @@ } /** - * @param url - * @return - * @throws IOException - * @throws DataSetException + * @param url dataset url (can be an xml or excel file) + * @return loaded dataset + * @throws IOException error reading the file + * @throws DataSetException error loading the dataset */ public static IDataSet loadDataset(URL url) throws IOException, DataSetException { Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/RegExpTableFilter.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/RegExpTableFilter.java 2008-01-26 18:14:12 UTC (rev 548) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/RegExpTableFilter.java 2008-01-26 18:39:46 UTC (rev 549) @@ -22,6 +22,7 @@ /** + * A table filter that excludes tables mathing the given regexp. * @author fgiust * @version $Id: $ */ @@ -30,6 +31,10 @@ private Pattern pattern; + /** + * Instantiates a new RegExpTableFilter + * @param pattern regexp pattern + */ public RegExpTableFilter(String pattern) { if (pattern != null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-02-19 13:41:05
|
Revision: 630 http://openutils.svn.sourceforge.net/openutils/?rev=630&view=rev Author: fcarone Date: 2008-02-19 05:41:04 -0800 (Tue, 19 Feb 2008) Log Message: ----------- DatatypeFactory annotation configuration added Modified Paths: -------------- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-02-19 10:36:14 UTC (rev 629) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-02-19 13:41:04 UTC (rev 630) @@ -22,12 +22,14 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.dbunit.database.DatabaseConfig; +import org.dbunit.dataset.datatype.IDataTypeFactory; import org.dbunit.operation.DatabaseOperation; /** * @author fgiust - * @version $Id: $ + * @version $Id$ */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @@ -54,6 +56,11 @@ String schema() default ""; /** + * The datatype factory (DatabaseConfig.PROPERTY_DATATYPE_FACTORY) to use. Can be left unset if not needed. + */ + Class< ? extends IDataTypeFactory> dataTypeFactory(); + + /** * A regexp that can match table names. Any table matching this regular expression will not be considered by DbUnit. * By default tables starting with $ are ignored (oracle recycle bin). */ Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-02-19 10:36:14 UTC (rev 629) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-02-19 13:41:04 UTC (rev 630) @@ -26,12 +26,14 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.dbunit.DatabaseUnitException; +import org.dbunit.database.DatabaseConfig; import org.dbunit.database.DatabaseConnection; import org.dbunit.database.DatabaseSequenceFilter; import org.dbunit.database.IDatabaseConnection; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.FilteredDataSet; import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.datatype.IDataTypeFactory; import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.dataset.filter.SequenceTableFilter; import org.dbunit.operation.DatabaseOperation; @@ -48,7 +50,7 @@ /** * @author fgiust - * @version $Id: $ + * @version $Id$ */ public class DbUnitTestContext { @@ -128,6 +130,12 @@ getDatasource(dataSourceName).getConnection(), schema); + if (dbUnitExecution.dataTypeFactory() != null) + { + IDataTypeFactory dataTypeFactory = dbUnitExecution.dataTypeFactory().newInstance(); + connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, dataTypeFactory); + } + try { ITableFilter tableFilter = new RegExpTableFilter(dbUnitExecution.excludedTables()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |