|
From: <fg...@us...> - 2008-01-27 11:12:16
|
Revision: 559
http://openutils.svn.sourceforge.net/openutils/?rev=559&view=rev
Author: fgiust
Date: 2008-01-27 03:12:20 -0800 (Sun, 27 Jan 2008)
Log Message:
-----------
[maven-release-plugin] copy for tag openutils-testing-2.0
Added Paths:
-----------
tags/openutils-testing-2.0/
tags/openutils-testing-2.0/pom.xml
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitConfiguration.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitExecution.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitTestContext.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitUtils.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/RegExpTableFilter.java
tags/openutils-testing-2.0/src/site/apt/dbunit.apt
tags/openutils-testing-2.0/src/site/apt/index.apt
tags/openutils-testing-2.0/src/site/site.xml
Removed Paths:
-------------
tags/openutils-testing-2.0/pom.xml
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitConfiguration.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitExecution.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitTestContext.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitUtils.java
tags/openutils-testing-2.0/src/main/java/it/openutils/testing/RegExpTableFilter.java
tags/openutils-testing-2.0/src/site/apt/index.apt
tags/openutils-testing-2.0/src/site/site.xml
Copied: tags/openutils-testing-2.0 (from rev 539, trunk/openutils-testing)
Deleted: tags/openutils-testing-2.0/pom.xml
===================================================================
--- trunk/openutils-testing/pom.xml 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/pom.xml 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,65 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>net.sourceforge.openutils</groupId>
- <artifactId>openutils</artifactId>
- <version>6</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>openutils-testing</artifactId>
- <name>openutils test utils</name>
- <version>2.0-SNAPSHOT</version>
- <description>openutils test utils</description>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl104-over-slf4j</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.3</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.dbunit</groupId>
- <artifactId>dbunit</artifactId>
- <version>2.2</version>
- <optional>true</optional>
- <exclusions>
- <exclusion>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </exclusion>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- <exclusion>
- <groupId>junit-addons</groupId>
- <artifactId>junit-addons</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- </dependencies>
- <properties>
- <spring.version>2.5.1</spring.version>
- </properties>
-</project>
Copied: tags/openutils-testing-2.0/pom.xml (from rev 558, trunk/openutils-testing/pom.xml)
===================================================================
--- tags/openutils-testing-2.0/pom.xml (rev 0)
+++ tags/openutils-testing-2.0/pom.xml 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,70 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sourceforge.openutils</groupId>
+ <artifactId>openutils</artifactId>
+ <version>7</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>openutils-testing</artifactId>
+ <name>openutils test utils</name>
+ <version>2.0</version>
+ <description>openutils test utils</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl104-over-slf4j</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.dbunit</groupId>
+ <artifactId>dbunit</artifactId>
+ <version>2.2</version>
+ <optional>true</optional>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <properties>
+ <spring.version>2.5.1</spring.version>
+ </properties>
+
+ <scm>
+ <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-2.0</connection>
+ <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-2.0</developerConnection>
+ <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-2.0</url>
+ </scm>
+</project>
Deleted: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitConfiguration.java
===================================================================
--- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitConfiguration.java 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitConfiguration.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,38 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.testing;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-/**
- * @author fgiust
- * @version $Id: $
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-@Inherited
-@Documented
-public @interface DbUnitConfiguration {
-
- DbUnitExecution[] dbUnitExecutions() default {};
-
-}
\ No newline at end of file
Copied: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitConfiguration.java (from rev 549, trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitConfiguration.java)
===================================================================
--- tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitConfiguration.java (rev 0)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitConfiguration.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,44 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.testing;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * A DbUnitConfiguration can contain one or more {@link DbUnitExecution}.
+ * @author fgiust
+ * @version $Id: $
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Inherited
+@Documented
+public @interface DbUnitConfiguration {
+
+ /**
+ * Array of {@link DbUnitExecution}
+ */
+ DbUnitExecution[] dbUnitExecutions() default {
+
+ };
+
+}
\ No newline at end of file
Deleted: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitExecution.java
===================================================================
--- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,55 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.testing;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.dbunit.operation.DatabaseOperation;
-
-
-/**
- * @author fgiust
- * @version $Id: $
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-@Inherited
-@Documented
-public @interface DbUnitExecution {
-
- /**
- * The resource locations to use for loading dbunit dataset.
- */
- String[] datasets() default {};
-
- String dataSource() default "";
-
- String schema() default "";
-
- String excludedTables() default "(^\\$(.*))"; // oracle recycle bin
-
- boolean truncateAll() default true;
-
- Class< ? extends DatabaseOperation> truncateOperation() default org.dbunit.operation.TruncateTableOperation.class;
-
- Class< ? extends DatabaseOperation> insertOperation() default org.dbunit.operation.InsertOperation.class;
-
-}
\ No newline at end of file
Copied: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitExecution.java (from rev 549, trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java)
===================================================================
--- tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitExecution.java (rev 0)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,78 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.testing;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.dbunit.operation.DatabaseOperation;
+
+
+/**
+ * @author fgiust
+ * @version $Id: $
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Inherited
+@Documented
+public @interface DbUnitExecution {
+
+ /**
+ * The resource locations to use for loading dbunit dataset.
+ */
+ 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
Deleted: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitTestContext.java
===================================================================
--- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,246 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.testing;
-
-import java.io.IOException;
-import java.net.URL;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.dbunit.DatabaseUnitException;
-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.filter.ITableFilter;
-import org.dbunit.dataset.filter.SequenceTableFilter;
-import org.dbunit.operation.DatabaseOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
-
-
-/**
- * @author fgiust
- * @version $Id: $
- */
-public class DbUnitTestContext
-{
-
- /**
- * Logger.
- */
- private static Logger log = LoggerFactory.getLogger(DbUnitTestContext.class);
-
- private Object testcase;
-
- private ApplicationContext applicationContext;
-
- /**
- * Dataset cache.
- */
- private Map<String, IDataSet> datasetCache = new HashMap<String, IDataSet>();
-
- /**
- * Truncate dataset cache. This is kept as a static attribute since the creation of the dataset is very expensive
- * and it doesn't change across tests.
- */
- protected static Map<String, IDataSet> truncateDataSetCache = new HashMap<String, IDataSet>();
-
- public DbUnitTestContext(Object testcase, ApplicationContext applicationContext)
- {
- this.testcase = testcase;
- this.applicationContext = applicationContext;
- }
-
- /**
- * Setup the Database before running the test method.
- * @throws Exception Any exception.
- */
- @SuppressWarnings("unchecked")
- public void setUpDbUnit() throws Exception
- {
- DbUnitExecution singleDbUnitExecution = testcase.getClass().getAnnotation(DbUnitExecution.class);
-
- DbUnitExecution[] executions;
- if (singleDbUnitExecution != null)
- {
- executions = new DbUnitExecution[]{singleDbUnitExecution };
- }
- else
- {
- DbUnitConfiguration dbUnitConfiguration = testcase.getClass().getAnnotation(DbUnitConfiguration.class);
- executions = dbUnitConfiguration.dbUnitExecutions();
- }
-
- for (DbUnitExecution dbUnitExecution : executions)
- {
- String[] datasets = dbUnitExecution.datasets();
- String dataSourceName = dbUnitExecution.dataSource();
- String schema = dbUnitExecution.schema();
- if (StringUtils.isEmpty(schema))
- {
- schema = null;
- }
-
- IDatabaseConnection connection = new DatabaseConnection(
- getDatasource(dataSourceName).getConnection(),
- schema);
-
- try
- {
- ITableFilter tableFilter = new RegExpTableFilter(dbUnitExecution.excludedTables());
-
- if (dbUnitExecution.truncateAll())
- {
- truncateAll(connection, tableFilter, dataSourceName, dbUnitExecution
- .truncateOperation()
- .newInstance());
- }
-
- DatabaseOperation dbOperation = dbUnitExecution.insertOperation().newInstance();
- for (String datasetFile : datasets)
- {
- importDataSet(createDataset(datasetFile), connection, tableFilter, dataSourceName, dbOperation);
- }
- }
- finally
- {
- connection.close();
- }
- }
- }
-
- /**
- * @param datasetFile
- * @return
- * @throws IOException
- * @throws DataSetException
- */
- private IDataSet createDataset(String datasetFile) throws IOException, DataSetException
- {
- IDataSet dataSet = datasetCache.get(datasetFile);
- if (dataSet == null)
- {
- URL datasetUrl = getClass().getResource(datasetFile);
- if (datasetUrl == null)
- {
- throw new IllegalArgumentException("Dataset " + datasetFile + " not found");
- }
- dataSet = DbUnitUtils.loadDataset(datasetUrl);
- datasetCache.put(datasetFile, dataSet);
- }
- return dataSet;
- }
-
- private void importDataSet(IDataSet dataSet, IDatabaseConnection connection, ITableFilter tableFilter,
- String dataSourceName, DatabaseOperation databaseOperation) throws SQLException, DataSetException,
- DatabaseUnitException
- {
-
- if (dataSet == null)
- {
- throw new IllegalArgumentException("dataSet is null");
- }
-
- IDataSet orderedDataset = new FilteredDataSet(tableFilter, dataSet);
- if (log.isDebugEnabled())
- {
- log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames()));
- }
-
- // if a sorted dataset is available, use table sequence for sorting
- IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema());
- if (truncateDataSet != null)
- {
- ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames());
- orderedDataset = new FilteredDataSet(filter, dataSet);
- }
-
- if (dataSet != null)
- {
- databaseOperation.execute(connection, orderedDataset);
- }
-
- }
-
- /**
- * @param connection
- * @param tableFilter
- * @throws SQLException
- * @throws DataSetException
- * @throws DatabaseUnitException
- */
- private void truncateAll(IDatabaseConnection connection, ITableFilter tableFilter, String dataSourceName,
- DatabaseOperation databaseOperation) throws SQLException, DataSetException, DatabaseUnitException
- {
- IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema());
- if (truncateDataSet == null)
- {
- log.debug("Generating sorted dataset for initial cleanup");
- IDataSet unsortedDataSet = connection.createDataSet();
-
- log.debug("Unfiltered truncateDataSet: {}", ArrayUtils.toString(unsortedDataSet.getTableNames()));
-
- ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet(
- tableFilter,
- unsortedDataSet).getTableNames());
- truncateDataSet = new FilteredDataSet(tableFilter, new FilteredDataSet(filter, unsortedDataSet));
- storeTruncateDataset(dataSourceName, connection.getSchema(), truncateDataSet);
- log.debug("Sorted dataset generated");
- }
-
- log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames()));
- if (truncateDataSet != null)
- {
- databaseOperation.execute(connection, truncateDataSet);
- }
- }
-
- private IDataSet getTruncateDataset(String datasourceName, String schema)
- {
- return truncateDataSetCache.get(datasourceName + "_" + StringUtils.defaultString(schema));
- }
-
- private IDataSet storeTruncateDataset(String datasourceName, String schema, IDataSet dataset)
- {
- return truncateDataSetCache.put(datasourceName + "_" + StringUtils.defaultString(schema), dataset);
- }
-
- @SuppressWarnings("unchecked")
- protected DataSource getDatasource(String name)
- {
- if (StringUtils.isEmpty(name))
- {
- Map<String, DataSource> dsMap = applicationContext.getBeansOfType(DataSource.class);
- if (dsMap == null || dsMap.size() != 1)
- {
- throw new RuntimeException(
- "Unable to find a datasource in spring applicationContext, please specify the datasource bean name "
- + "using the \"datasource\" attribute of @DbUnitConfiguration");
- }
- return dsMap.values().iterator().next();
- }
- return (DataSource) applicationContext.getBean(name);
- }
-}
Copied: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitTestContext.java (from rev 549, trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java)
===================================================================
--- tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitTestContext.java (rev 0)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,319 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.testing;
+
+import java.io.IOException;
+import java.net.URL;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.dbunit.DatabaseUnitException;
+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.filter.ITableFilter;
+import org.dbunit.dataset.filter.SequenceTableFilter;
+import org.dbunit.operation.DatabaseOperation;
+import org.dbunit.operation.DeleteAllOperation;
+import org.dbunit.operation.DeleteOperation;
+import org.dbunit.operation.InsertOperation;
+import org.dbunit.operation.RefreshOperation;
+import org.dbunit.operation.TruncateTableOperation;
+import org.dbunit.operation.UpdateOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+
+
+/**
+ * @author fgiust
+ * @version $Id: $
+ */
+public class DbUnitTestContext
+{
+
+ /**
+ * Truncate dataset cache. This is kept as a static attribute since the creation of the dataset is very expensive
+ * and it doesn't change across tests.
+ */
+ protected static Map<String, IDataSet> truncateDataSetCache = new HashMap<String, IDataSet>();
+
+ /**
+ * Logger.
+ */
+ private static Logger log = LoggerFactory.getLogger(DbUnitTestContext.class);
+
+ /**
+ * The test instance.
+ */
+ private Object testcase;
+
+ /**
+ * Spring application context.
+ */
+ private ApplicationContext applicationContext;
+
+ /**
+ * Dataset cache.
+ */
+ private Map<String, IDataSet> datasetCache = new HashMap<String, IDataSet>();
+
+ /**
+ * Instantiates a new DbUnitTestContext
+ * @param testcase test instance
+ * @param applicationContext Spring application context
+ */
+ public DbUnitTestContext(Object testcase, ApplicationContext applicationContext)
+ {
+ this.testcase = testcase;
+ this.applicationContext = applicationContext;
+ }
+
+ /**
+ * Setup the Database before running the test method.
+ * @throws Exception Any exception.
+ */
+ @SuppressWarnings("unchecked")
+ public void setUpDbUnit() throws Exception
+ {
+ DbUnitExecution singleDbUnitExecution = testcase.getClass().getAnnotation(DbUnitExecution.class);
+
+ DbUnitExecution[] executions = null;
+ if (singleDbUnitExecution != null)
+ {
+ executions = new DbUnitExecution[]{singleDbUnitExecution };
+ }
+ else
+ {
+ DbUnitConfiguration dbUnitConfiguration = testcase.getClass().getAnnotation(DbUnitConfiguration.class);
+ if (dbUnitConfiguration != null)
+ {
+ executions = dbUnitConfiguration.dbUnitExecutions();
+ }
+ }
+ if (executions != null)
+ {
+ for (DbUnitExecution dbUnitExecution : executions)
+ {
+ String[] datasets = dbUnitExecution.datasets();
+ String dataSourceName = dbUnitExecution.dataSource();
+ String schema = dbUnitExecution.schema();
+ if (StringUtils.isEmpty(schema))
+ {
+ schema = null;
+ }
+
+ IDatabaseConnection connection = new DatabaseConnection(
+ getDatasource(dataSourceName).getConnection(),
+ schema);
+
+ try
+ {
+ ITableFilter tableFilter = new RegExpTableFilter(dbUnitExecution.excludedTables());
+
+ if (dbUnitExecution.truncateAll())
+ {
+ truncateAll(connection, tableFilter, dataSourceName, getDatabaseOperation(dbUnitExecution
+ .truncateOperation()));
+ }
+
+ DatabaseOperation dbOperation = getDatabaseOperation(dbUnitExecution.insertOperation());
+ for (String datasetFile : datasets)
+ {
+ importDataSet(createDataset(datasetFile), connection, tableFilter, dataSourceName, dbOperation);
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+ }
+ }
+
+ /**
+ * Instantiates the givec Database Operation. Standard operations in the <code>org.dbunit.operation</code> package
+ * have protected constructors and needs to be accessed using the public static fields in
+ * <code>org.dbunit.operation.DatabaseOperation</code>.
+ * @param dboperationClass db operation class
+ * @return db operation instance
+ * @throws InstantiationException if the given db operation class cannot be instantiated
+ * @throws IllegalAccessException if the given db operation class cannot be instantiated
+ */
+ private DatabaseOperation getDatabaseOperation(Class< ? extends DatabaseOperation> dboperationClass)
+ throws InstantiationException, IllegalAccessException
+ {
+ if (UpdateOperation.class.equals(dboperationClass))
+ {
+ return DatabaseOperation.UPDATE;
+ }
+ else if (InsertOperation.class.equals(dboperationClass))
+ {
+ return DatabaseOperation.INSERT;
+ }
+ else if (RefreshOperation.class.equals(dboperationClass))
+ {
+ return DatabaseOperation.REFRESH;
+ }
+ else if (DeleteOperation.class.equals(dboperationClass))
+ {
+ return DatabaseOperation.DELETE;
+ }
+ else if (DeleteAllOperation.class.equals(dboperationClass))
+ {
+ return DatabaseOperation.DELETE_ALL;
+ }
+ else if (TruncateTableOperation.class.equals(dboperationClass))
+ {
+ return DatabaseOperation.TRUNCATE_TABLE;
+ }
+ else if (DeleteOperation.class.equals(dboperationClass))
+ {
+ return DatabaseOperation.UPDATE;
+ }
+
+ return dboperationClass.newInstance();
+
+ }
+
+ /**
+ * Creates a dataset instance by fetching a file from the classpath
+ * @param datasetFile name of the file, will be loaded from the classpath
+ * @return IDataSet instance
+ * @throws IOException
+ * @throws DataSetException
+ */
+ private IDataSet createDataset(String datasetFile) throws IOException, DataSetException
+ {
+ IDataSet dataSet = datasetCache.get(datasetFile);
+ if (dataSet == null)
+ {
+ URL datasetUrl = getClass().getResource(datasetFile);
+ if (datasetUrl == null)
+ {
+ throw new IllegalArgumentException("Dataset " + datasetFile + " not found");
+ }
+ dataSet = DbUnitUtils.loadDataset(datasetUrl);
+ datasetCache.put(datasetFile, dataSet);
+ }
+ return dataSet;
+ }
+
+ private void importDataSet(IDataSet dataSet, IDatabaseConnection connection, ITableFilter tableFilter,
+ String dataSourceName, DatabaseOperation databaseOperation) throws SQLException, DataSetException,
+ DatabaseUnitException
+ {
+
+ if (dataSet == null)
+ {
+ throw new IllegalArgumentException("dataSet is null");
+ }
+
+ IDataSet orderedDataset = new FilteredDataSet(tableFilter, dataSet);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames()));
+ }
+
+ // if a sorted dataset is available, use table sequence for sorting
+ IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema());
+ if (truncateDataSet != null)
+ {
+ ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames());
+ orderedDataset = new FilteredDataSet(filter, dataSet);
+ }
+
+ if (dataSet != null)
+ {
+ databaseOperation.execute(connection, orderedDataset);
+ }
+
+ }
+
+ /**
+ * @param connection
+ * @param tableFilter
+ * @throws SQLException
+ * @throws DataSetException
+ * @throws DatabaseUnitException
+ */
+ private void truncateAll(IDatabaseConnection connection, ITableFilter tableFilter, String dataSourceName,
+ DatabaseOperation databaseOperation) throws SQLException, DataSetException, DatabaseUnitException
+ {
+ IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema());
+ if (truncateDataSet == null)
+ {
+ log.debug("Generating sorted dataset for initial cleanup");
+ IDataSet unsortedDataSet = connection.createDataSet();
+
+ log.debug("Unfiltered truncateDataSet: {}", ArrayUtils.toString(unsortedDataSet.getTableNames()));
+
+ ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet(
+ tableFilter,
+ unsortedDataSet).getTableNames());
+ truncateDataSet = new FilteredDataSet(tableFilter, new FilteredDataSet(filter, unsortedDataSet));
+ storeTruncateDataset(dataSourceName, connection.getSchema(), truncateDataSet);
+ log.debug("Sorted dataset generated");
+ }
+
+ log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames()));
+ if (truncateDataSet != null)
+ {
+ databaseOperation.execute(connection, truncateDataSet);
+ }
+ }
+
+ private IDataSet getTruncateDataset(String datasourceName, String schema)
+ {
+ return truncateDataSetCache.get(datasourceName + "_" + StringUtils.defaultString(schema));
+ }
+
+ private IDataSet storeTruncateDataset(String datasourceName, String schema, IDataSet dataset)
+ {
+ return truncateDataSetCache.put(datasourceName + "_" + StringUtils.defaultString(schema), dataset);
+ }
+
+ /**
+ * Loads a named datasource from the spring context.
+ * @param name datasource name.
+ * @return Datasource instance
+ */
+ @SuppressWarnings("unchecked")
+ protected DataSource getDatasource(String name)
+ {
+ if (StringUtils.isEmpty(name))
+ {
+ Map<String, DataSource> dsMap = applicationContext.getBeansOfType(DataSource.class);
+ if (dsMap == null || dsMap.size() != 1)
+ {
+ throw new RuntimeException(
+ "Unable to find a datasource in spring applicationContext, please specify the datasource bean name "
+ + "using the \"datasource\" attribute of @DbUnitConfiguration");
+ }
+ return dsMap.values().iterator().next();
+ }
+ return (DataSource) applicationContext.getBean(name);
+ }
+
+}
Deleted: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitUtils.java
===================================================================
--- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,115 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.testing;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.sql.SQLException;
-
-import org.apache.commons.lang.StringUtils;
-import org.dbunit.database.IDatabaseConnection;
-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.xml.XmlDataSet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * @author fgiust
- * @version $Id: $
- */
-public final class DbUnitUtils
-{
-
- /**
- * Logger.
- */
- private static Logger log = LoggerFactory.getLogger(DbUnitUtils.class);
-
- /**
- * @param connection
- * @param tableNames
- * @param file
- * @param xls
- * @throws SQLException
- * @throws IOException
- * @throws DataSetException
- */
- public static void exportDataset(IDatabaseConnection connection, String[] tableNames, File file)
- throws SQLException, IOException, DataSetException
- {
- OutputStream fos = null;
-
- try
- {
- IDataSet fullDataSet = connection.createDataSet();
-
- if (tableNames != null && tableNames.length > 0)
- {
- fullDataSet = new FilteredDataSet(tableNames, fullDataSet);
- }
-
- fos = new FileOutputStream(file);
- if (StringUtils.equalsIgnoreCase(StringUtils.substringAfterLast(file.getName(), "."), "xls"))
- {
- XlsDataSet.write(fullDataSet, fos);
- }
- else
- {
- XmlDataSet.write(fullDataSet, fos);
- }
- }
- finally
- {
- connection.close();
- fos.close();
- }
-
- log.debug("Dataset exported at {}", file.getAbsolutePath());
- }
-
- /**
- * @param url
- * @return
- * @throws IOException
- * @throws DataSetException
- */
- public static IDataSet loadDataset(URL url) throws IOException, DataSetException
- {
- if (url == null)
- {
- throw new IllegalArgumentException("URL is null");
- }
- InputStream is = url.openStream();
- IDataSet dataSet = null;
-
- if (is != null)
- {
- log.debug("loading dataset {}", url.getFile());
- dataSet = url.getFile().endsWith(".xls") ? new XlsDataSet(is) : new XmlDataSet(is);
- is.close();
- }
- return dataSet;
- }
-
-}
Copied: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitUtils.java (from rev 549, trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java)
===================================================================
--- tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitUtils.java (rev 0)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,123 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.testing;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.sql.SQLException;
+
+import org.apache.commons.lang.StringUtils;
+import org.dbunit.database.IDatabaseConnection;
+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.xml.XmlDataSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * @author fgiust
+ * @version $Id: $
+ */
+public final class DbUnitUtils
+{
+
+ /**
+ * Logger.
+ */
+ private static Logger log = LoggerFactory.getLogger(DbUnitUtils.class);
+
+ /**
+ * 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
+ {
+ OutputStream fos = null;
+
+ try
+ {
+ IDataSet fullDataSet = connection.createDataSet();
+
+ if (tableNames != null && tableNames.length > 0)
+ {
+ fullDataSet = new FilteredDataSet(tableNames, fullDataSet);
+ }
+
+ fos = new FileOutputStream(file);
+ if (StringUtils.equalsIgnoreCase(StringUtils.substringAfterLast(file.getName(), "."), "xls"))
+ {
+ XlsDataSet.write(fullDataSet, fos);
+ }
+ else
+ {
+ XmlDataSet.write(fullDataSet, fos);
+ }
+ }
+ finally
+ {
+ connection.close();
+ fos.close();
+ }
+
+ log.debug("Dataset exported at {}", file.getAbsolutePath());
+ }
+
+ /**
+ * @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
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException("URL is null");
+ }
+ InputStream is = url.openStream();
+ IDataSet dataSet = null;
+
+ if (is != null)
+ {
+ log.debug("loading dataset {}", url.getFile());
+ dataSet = url.getFile().endsWith(".xls") ? new XlsDataSet(is) : new XmlDataSet(is);
+ is.close();
+ }
+ return dataSet;
+ }
+
+}
Deleted: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/RegExpTableFilter.java
===================================================================
--- trunk/openutils-testing/src/main/java/it/openutils/testing/RegExpTableFilter.java 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/RegExpTableFilter.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,50 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.testing;
-
-import java.util.regex.Pattern;
-
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.filter.AbstractTableFilter;
-
-
-/**
- * @author fgiust
- * @version $Id: $
- */
-public class RegExpTableFilter extends AbstractTableFilter
-{
-
- private Pattern pattern;
-
- public RegExpTableFilter(String pattern)
- {
- if (pattern != null)
- {
- this.pattern = Pattern.compile(pattern);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isValidName(String tableName) throws DataSetException
- {
- return pattern == null || !pattern.matcher(tableName).matches();
- }
-
-}
Copied: tags/openutils-testing-2.0/src/main/java/it/openutils/testing/RegExpTableFilter.java (from rev 549, trunk/openutils-testing/src/main/java/it/openutils/testing/RegExpTableFilter.java)
===================================================================
--- tags/openutils-testing-2.0/src/main/java/it/openutils/testing/RegExpTableFilter.java (rev 0)
+++ tags/openutils-testing-2.0/src/main/java/it/openutils/testing/RegExpTableFilter.java 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,55 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.testing;
+
+import java.util.regex.Pattern;
+
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.filter.AbstractTableFilter;
+
+
+/**
+ * A table filter that excludes tables mathing the given regexp.
+ * @author fgiust
+ * @version $Id: $
+ */
+public class RegExpTableFilter extends AbstractTableFilter
+{
+
+ private Pattern pattern;
+
+ /**
+ * Instantiates a new RegExpTableFilter
+ * @param pattern regexp pattern
+ */
+ public RegExpTableFilter(String pattern)
+ {
+ if (pattern != null)
+ {
+ this.pattern = Pattern.compile(pattern);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isValidName(String tableName) throws DataSetException
+ {
+ return pattern == null || !pattern.matcher(tableName).matches();
+ }
+
+}
Copied: tags/openutils-testing-2.0/src/site/apt/dbunit.apt (from rev 550, trunk/openutils-testing/src/site/apt/dbunit.apt)
===================================================================
--- tags/openutils-testing-2.0/src/site/apt/dbunit.apt (rev 0)
+++ tags/openutils-testing-2.0/src/site/apt/dbunit.apt 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,76 @@
+ --------------------------
+ O p e n u t i l s
+ --------------------------
+ Fabrizio Giustina
+ --------------------------
+
+
+DbUnit tests
+
+ Openutils provide a base class that take cares of the common operations involved in preparing the test environment using
+ DbUnit.
+
+ You can extend <<<it.openutils.testing.testng.AbstractDbUnitTestNGSpringContextTests>>> or
+ <<<it.openutils.testing.junit.AbstractDbUnitJunitSpringContextTests>>>, depending on the test framework of your choice
+ (remember to include the appropriate dependency, openutils-testing-testng or openutils-testing-junit).
+ Apart from the underline test framework used, there is no difference in how those class will work.
+
+ Those base classes extend the standard <<<Abstract*SpringContextTests>>> classes provided by Spring, so they support
+ dependency injection and needs to be configured from a Spring context.
+
+How to
+
+ All the setup can be configured using annotations. This is a sample test that can make use of data loaded by DbUnit:
+
++----------------------------------------------+
+
+@ContextConfiguration(locations = {"/spring-tests.xml" })
+@DbUnitExecution(datasets = {"/db1-load.xml" })
+public class SampleDbUnitTest extends AbstractDbUnitTestNGSpringContextTests
+{
+ @Test
+ public void testSomething() {
+ ...
+ }
+}
+
++----------------------------------------------+
+
+ The <<<DbUnitExecution>>> annotation controls how the setup will be performed. It can be configured with a list of file names
+ (xml od xsl DbUnit datasets) that will be loaded before every single method in this test class is executed.
+
+ In detail the setup that will be performed before each method is:
+
+ * truncate *any table* in the database. This can be turned of by the <<<truncateAll>>> DbUnitExecution parameter
+
+ * load the given datasets into the db
+
+ []
+
+ You can setup also more than one execution if your tests depend on more than one database or schema, annotating your
+ class like in this example:
+
++----------------------------------------------+
+
+@DbUnitConfiguration(dbUnitExecutions = {
+ @DbUnitExecution(datasets = {"/db1-load.xml" }, dataSource = "dataSource1"),
+ @DbUnitExecution(datasets = {"/db2-load.xml" }, dataSource = "dataSource2") })
+
++----------------------------------------------+
+
+
+ Note that this test classes don't extend Spring transactional tests, so you need to manually turn on Transactions using
+ standard Spring annotations:
+
++----------------------------------------------+
+
+@TestExecutionListeners({TransactionalTestExecutionListener.class })
+@Transactional
+
++----------------------------------------------+
+
+ Also note that the content of your db will definitively be modified by these tests, they are expected to be run on a
+ test-only instance!
+
+
+
Deleted: tags/openutils-testing-2.0/src/site/apt/index.apt
===================================================================
--- trunk/openutils-testing/src/site/apt/index.apt 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/src/site/apt/index.apt 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,8 +0,0 @@
- --------------------------
- O p e n u t i l s
- --------------------------
- Fabrizio Giustina
- --------------------------
-
-openutils-testing
-
Copied: tags/openutils-testing-2.0/src/site/apt/index.apt (from rev 550, trunk/openutils-testing/src/site/apt/index.apt)
===================================================================
--- tags/openutils-testing-2.0/src/site/apt/index.apt (rev 0)
+++ tags/openutils-testing-2.0/src/site/apt/index.apt 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,27 @@
+ --------------------------
+ O p e n u t i l s
+ --------------------------
+ Fabrizio Giustina
+ --------------------------
+
+openutils-testing
+
+ Openutils-testing extends the standard spring testing framework by providing more high-level base testing classes and utils.
+
+ In particular, it provides a {{{dbunit.html}framework for using with dbunit in Spring test cases}}.
+
+ The openutils-testing jar only contains generic classes that don't depends on any specific test framework. You should
+ depend on openutils-testing-testng or openutils-testing-junit
+
+
+
+Released versions
+
+ openutils-testing-testng:
+
+ {{{http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-testing-testng}http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-testing-testng}}
+
+ openutils-testing-junit:
+
+ {{{http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-testing-junit}http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-testing-junit}}
+
Deleted: tags/openutils-testing-2.0/src/site/site.xml
===================================================================
--- trunk/openutils-testing/src/site/site.xml 2008-01-20 19:22:22 UTC (rev 539)
+++ tags/openutils-testing-2.0/src/site/site.xml 2008-01-27 11:12:20 UTC (rev 559)
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="Openutils testing">
- <publishDate position="left" format="yyyy-MM-dd" />
- <bannerRight>
- <name>Openutils</name>
- <src>http://openutils.sourceforge.net/images/openutils-logo.png</src>
- <href>http://openutils.sourceforge.net</href>
- </bannerRight>
- <bannerLeft>
- <name>Sourceforge</name>
- <src>http://sourceforge.net/sflogo.php?group_id=150467&amp;type=2</src>
- <href>http://www.sourceforge.net/projects/openutils</href>
- </bannerLeft>
- <body>
- <head>
- <link rel="icon" href="images/favicon.ico" />
- </head>
- <menu name="openutils testing">
- <item name="Usage" href="index.html"></item>
- </menu>
- <menu ref="modules" inherit="bottom" />
- <menu ref="reports" inherit="bottom" />
- </body>
- <skin>
- <groupId>net.sourceforge.openutils</groupId>
- <artifactId>openutils-maven-skin</artifactId>
- <version>1.0</version>
- </skin>
-</project>
Copied: tags/openutils-testing-2.0/src/site/site.xml (from rev 553, trunk/openutils-testing/src/site/site.xml)
===================================================================
--- tags/openutils-testing-2.0/src/site/site.xml (rev 0)
+++ tags/openutils-testing-2.0/src/site/site.xml 2008-01-27 11:12:20 UTC (rev 559)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Openutils testing">
+ <publishDate position="navigation-bottom" format="yyyy-MM-dd" />
+ <version position="navigation-bottom" />
+ <bannerRight>
+ <name>Openutils</name>
+ <src>http://openutils.sourceforge.net/images/openutils-logo.png</src>
+ <href>http://openutils.sourceforge.net</href>
+ </bannerRight>
+ <bannerLeft>
+ <name>Sourceforge</name>
+ <src>http://sourceforge.net/sflogo.php?group_id=150467&amp;type=2</src>
+ <href>http://www.sourceforge.net/projects/openutils</href>
+ </bannerLeft>
+ <body>
+ <head>
+ <link rel="icon" href="images/favicon.ico" />
+ </head>
+ <breadcrumbs>
+ <item name="openutils" href="http://openutils.sourceforge.net/" />
+ <item name="openutils-testing" href="http://openutils.sourceforge.net/openutils-testing" />
+ </breadcrumbs>
+ <menu name="openutils testing">
+ <item name="Usage" href="index.html"></item>
+ <item name="DbUnit tests" href="dbunit.html"></item>
+ </menu>
+ <menu ref="modules" inherit="bottom" />
+ <menu ref="reports" inherit="bottom" />
+ </body>
+ <skin>
+ <groupId>net.sourceforge.openutils</groupId>
+ <artifactId>openutils-maven-skin</artifactId>
+ <version>1.0</version>
+ </skin>
+</project>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|