|
From: <fc...@us...> - 2007-08-31 12:27:20
|
Revision: 420
http://openutils.svn.sourceforge.net/openutils/?rev=420&view=rev
Author: fcarone
Date: 2007-08-31 05:27:18 -0700 (Fri, 31 Aug 2007)
Log Message:
-----------
[maven-release-plugin] copy for tag openutils-testing-junit-1.1.2
Added Paths:
-----------
tags/openutils-testing-junit-1.1.2/
tags/openutils-testing-junit-1.1.2/pom.xml
tags/openutils-testing-junit-1.1.2/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java
Removed Paths:
-------------
tags/openutils-testing-junit-1.1.2/pom.xml
tags/openutils-testing-junit-1.1.2/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java
Copied: tags/openutils-testing-junit-1.1.2 (from rev 412, trunk/openutils-testing-junit)
Deleted: tags/openutils-testing-junit-1.1.2/pom.xml
===================================================================
--- trunk/openutils-testing-junit/pom.xml 2007-08-30 15:40:19 UTC (rev 412)
+++ tags/openutils-testing-junit-1.1.2/pom.xml 2007-08-31 12:27:18 UTC (rev 420)
@@ -1,62 +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>3</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>openutils-testing-junit</artifactId>
- <name>openutils test utils (junit)</name>
- <version>1.1.2-SNAPSHOT</version>
- <description>openutils test utils</description>
- <properties>
- <spring.version>2.0.6</spring.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.2</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.13</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-hibernate3</artifactId>
- <version>${spring.version}</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.3</version>
- </dependency>
- <dependency>
- <groupId>org.dbunit</groupId>
- <artifactId>dbunit</artifactId>
- <version>2.2</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
Copied: tags/openutils-testing-junit-1.1.2/pom.xml (from rev 419, trunk/openutils-testing-junit/pom.xml)
===================================================================
--- tags/openutils-testing-junit-1.1.2/pom.xml (rev 0)
+++ tags/openutils-testing-junit-1.1.2/pom.xml 2007-08-31 12:27:18 UTC (rev 420)
@@ -0,0 +1,67 @@
+<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>3</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>openutils-testing-junit</artifactId>
+ <name>openutils test utils (junit)</name>
+ <version>1.1.2</version>
+ <description>openutils test utils</description>
+ <properties>
+ <spring.version>2.0.6</spring.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.13</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-hibernate3</artifactId>
+ <version>${spring.version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.dbunit</groupId>
+ <artifactId>dbunit</artifactId>
+ <version>2.2</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.2</connection>
+ <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.2</developerConnection>
+ <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-junit-1.1.2</url>
+ </scm>
+</project>
\ No newline at end of file
Deleted: tags/openutils-testing-junit-1.1.2/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java
===================================================================
--- trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-08-30 15:40:19 UTC (rev 412)
+++ tags/openutils-testing-junit-1.1.2/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-08-31 12:27:18 UTC (rev 420)
@@ -1,257 +0,0 @@
-/*
- * Copyright 2005 Fabrizio Giustina.
- *
- * 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.junit;
-
-import java.io.InputStream;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import org.apache.commons.lang.ClassUtils;
-import org.apache.commons.lang.StringUtils;
-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.excel.XlsDataSet;
-import org.dbunit.dataset.filter.AbstractTableFilter;
-import org.dbunit.dataset.filter.ITableFilter;
-import org.dbunit.dataset.filter.SequenceTableFilter;
-import org.dbunit.dataset.xml.XmlDataSet;
-import org.dbunit.ext.mssql.InsertIdentityOperation;
-import org.dbunit.operation.DatabaseOperation;
-import org.hibernate.SessionFactory;
-import org.springframework.orm.hibernate3.SessionHolder;
-import org.springframework.transaction.support.TransactionSynchronizationManager;
-
-
-/**
- * Base class for running DAO tests.
- * @author fgiust
- * @version $Revision $ ($Author $)
- */
-public abstract class DbUnitTestCase extends SpringTestCase
-{
-
- /**
- * Hibernate session factory.
- */
- private SessionFactory sessionFactory;
-
- private static final String BASETEST_DELETE = "/_BaseDAOTest-delete.xml";
-
- protected static IDataSet truncateDataSet;
-
- /**
- * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code>
- * @return <code>true</code> if deferred close should be used
- */
- protected boolean mimicSessionFilter()
- {
- return true;
- }
-
- /**
- * Returns the table filter that will be used to exclude certain tables from sort/deletion. This may be overridden
- * by subclasses, and is needed when tables have circular references (not handled by dbunit DatabaseSequenceFilter)
- * @return an <code>ITableFilter</code>
- */
- protected ITableFilter getTableFilter()
- {
- return new AbstractTableFilter()
- {
-
- @Override
- public boolean isValidName(String tableName) throws DataSetException
- {
- // default excludes:
- // $ = oracle recycle bin tables
- // JBPM = jbpm tables, with circular references
- return !StringUtils.contains(tableName, "$") && !StringUtils.contains(tableName, "JBPM");
- }
- };
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- // insert values
- IDataSet dataSet = null;
-
- String datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xml";
- InputStream testData = getClass().getResourceAsStream(datesetFileName);
-
- if (testData != null)
- {
- if (log.isDebugEnabled())
- {
- log.debug("loading dataset {}", datesetFileName);
- }
-
- dataSet = new XmlDataSet(testData);
- }
- else
- {
- // check for excel
- datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xls";
- testData = getClass().getResourceAsStream(datesetFileName);
-
- if (testData != null)
- {
- if (log.isDebugEnabled())
- {
- log.debug("loading dataset {}", datesetFileName);
- }
-
- dataSet = new XlsDataSet(testData);
- }
- }
-
- if (dataSet == null)
- {
- log.debug("No test data found with name [{}]", datesetFileName);
- }
- else
- {
-
- DataSource dataSource = (DataSource) ctx.getBean("dataSource");
- IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
-
- // truncate common tables
- if (truncateDataSet == null)
- {
- log.debug("Generating sorted dataset for initial cleanup");
- IDataSet unsortedTruncateDataSet = connection.createDataSet();
-
- ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet(
- getTableFilter(),
- unsortedTruncateDataSet).getTableNames());
- truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet);
- truncateDataSet = new FilteredDataSet(getTableFilter(), truncateDataSet);
- log.debug("Sorted dataset generated");
- }
-
- IDataSet orderedDataset = dataSet;
-
- // if a sorted dataset is available, use table sequence for sorting
- if (truncateDataSet != null)
- {
- ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames());
- orderedDataset = new FilteredDataSet(filter, dataSet);
- }
-
- try
- {
- if (truncateDataSet != null)
- {
- DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet);
- }
- if (dataSet != null)
- {
- InsertIdentityOperation.INSERT.execute(connection, orderedDataset);
- }
- }
- finally
- {
- connection.close();
- }
- }
-
- // mimic the Spring OpenSessionInViewFilter
- if (mimicSessionFilter())
- {
- Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class);
- if (sfbeans.isEmpty())
- {
- fail("No bean of type org.hibernate.SessionFactory found in spring context");
- }
- this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next());
-
- TransactionSynchronizationManager.bindResource(this.getSessionFactory(), new SessionHolder(this
- .getSessionFactory()
- .openSession()));
- }
-
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void tearDown() throws Exception
- {
- if (mimicSessionFilter())
- {
- // close open hibernate sessions, mimic the OpenSessionInViewFilter
- if (TransactionSynchronizationManager.hasResource(this.getSessionFactory()))
- {
- TransactionSynchronizationManager.unbindResource(this.getSessionFactory());
- }
- }
-
- // regenerate db initial state
- String datesetFileName = "/initial-load.xml";
- InputStream testData = getClass().getResourceAsStream(datesetFileName);
-
- if (testData != null)
- {
- log.debug("Restoring db state");
-
- IDataSet dataSet = new XmlDataSet(testData);
-
- DataSource dataSource = (DataSource) ctx.getBean("dataSource");
- IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
-
- try
- {
- DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
- }
- finally
- {
- connection.close();
- }
- }
-
- super.tearDown();
- }
-
- /**
- * Returns the full test name.
- * @see junit.framework.TestCase#getName()
- */
- @Override
- public String getName()
- {
- return ClassUtils.getShortClassName(this.getClass()) + "::" + super.getName();
- }
-
- /**
- * return the current Hibernate SessionFactory
- * @return SessionFactory object
- */
- protected SessionFactory getSessionFactory()
- {
- return sessionFactory;
- }
-}
\ No newline at end of file
Copied: tags/openutils-testing-junit-1.1.2/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java (from rev 418, trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java)
===================================================================
--- tags/openutils-testing-junit-1.1.2/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java (rev 0)
+++ tags/openutils-testing-junit-1.1.2/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-08-31 12:27:18 UTC (rev 420)
@@ -0,0 +1,267 @@
+/*
+ * Copyright 2005 Fabrizio Giustina.
+ *
+ * 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.junit;
+
+import java.io.InputStream;
+import java.sql.SQLException;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang.StringUtils;
+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.excel.XlsDataSet;
+import org.dbunit.dataset.filter.AbstractTableFilter;
+import org.dbunit.dataset.filter.ITableFilter;
+import org.dbunit.dataset.filter.SequenceTableFilter;
+import org.dbunit.dataset.xml.XmlDataSet;
+import org.dbunit.ext.mssql.InsertIdentityOperation;
+import org.dbunit.operation.DatabaseOperation;
+import org.hibernate.SessionFactory;
+import org.springframework.orm.hibernate3.SessionHolder;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+
+
+/**
+ * Base class for running DAO tests.
+ * @author fgiust
+ * @version $Revision $ ($Author $)
+ */
+public abstract class DbUnitTestCase extends SpringTestCase
+{
+
+ /**
+ * Hibernate session factory.
+ */
+ private SessionFactory sessionFactory;
+
+ private static final String BASETEST_DELETE = "/_BaseDAOTest-delete.xml";
+
+ protected static IDataSet truncateDataSet;
+
+ /**
+ * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code>
+ * @return <code>true</code> if deferred close should be used
+ */
+ protected boolean mimicSessionFilter()
+ {
+ return true;
+ }
+
+ /**
+ * Returns the table filter that will be used to exclude certain tables from sort/deletion. This may be overridden
+ * by subclasses, and is needed when tables have circular references (not handled by dbunit DatabaseSequenceFilter)
+ * @return an <code>ITableFilter</code>
+ */
+ protected ITableFilter getTableFilter()
+ {
+ return new AbstractTableFilter()
+ {
+
+ @Override
+ public boolean isValidName(String tableName) throws DataSetException
+ {
+ // default excludes:
+ // $ = oracle recycle bin tables
+ // JBPM = jbpm tables, with circular references
+ return !StringUtils.contains(tableName, "$") && !StringUtils.contains(tableName, "JBPM");
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // insert values
+ IDataSet dataSet = null;
+
+ String datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xml";
+ InputStream testData = getClass().getResourceAsStream(datesetFileName);
+
+ if (testData != null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("loading dataset {}", datesetFileName);
+ }
+
+ dataSet = new XmlDataSet(testData);
+ }
+ else
+ {
+ // check for excel
+ datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xls";
+ testData = getClass().getResourceAsStream(datesetFileName);
+
+ if (testData != null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("loading dataset {}", datesetFileName);
+ }
+
+ dataSet = new XlsDataSet(testData);
+ }
+ }
+
+ if (dataSet == null)
+ {
+ log.debug("No test data found with name [{}]", datesetFileName);
+ }
+ else
+ {
+
+ IDatabaseConnection connection = createConnection();
+
+ // truncate common tables
+ if (truncateDataSet == null)
+ {
+ log.debug("Generating sorted dataset for initial cleanup");
+ IDataSet unsortedTruncateDataSet = connection.createDataSet();
+
+ ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet(
+ getTableFilter(),
+ unsortedTruncateDataSet).getTableNames());
+ truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet);
+ truncateDataSet = new FilteredDataSet(getTableFilter(), truncateDataSet);
+ log.debug("Sorted dataset generated");
+ }
+
+ IDataSet orderedDataset = dataSet;
+
+ // if a sorted dataset is available, use table sequence for sorting
+ if (truncateDataSet != null)
+ {
+ ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames());
+ orderedDataset = new FilteredDataSet(filter, dataSet);
+ }
+
+ try
+ {
+ if (truncateDataSet != null)
+ {
+ DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet);
+ }
+ if (dataSet != null)
+ {
+ InsertIdentityOperation.INSERT.execute(connection, orderedDataset);
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ // mimic the Spring OpenSessionInViewFilter
+ if (mimicSessionFilter())
+ {
+ Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class);
+ if (sfbeans.isEmpty())
+ {
+ fail("No bean of type org.hibernate.SessionFactory found in spring context");
+ }
+ this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next());
+
+ TransactionSynchronizationManager.bindResource(this.getSessionFactory(), new SessionHolder(this
+ .getSessionFactory()
+ .openSession()));
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void tearDown() throws Exception
+ {
+ if (mimicSessionFilter())
+ {
+ // close open hibernate sessions, mimic the OpenSessionInViewFilter
+ if (TransactionSynchronizationManager.hasResource(this.getSessionFactory()))
+ {
+ TransactionSynchronizationManager.unbindResource(this.getSessionFactory());
+ }
+ }
+
+ // regenerate db initial state
+ String datesetFileName = "/initial-load.xml";
+ InputStream testData = getClass().getResourceAsStream(datesetFileName);
+
+ if (testData != null)
+ {
+ log.debug("Restoring db state");
+
+ IDataSet dataSet = new XmlDataSet(testData);
+
+ DataSource dataSource = (DataSource) ctx.getBean("dataSource");
+ IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
+
+ try
+ {
+ DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ super.tearDown();
+ }
+
+ /**
+ * Returns the full test name.
+ * @see junit.framework.TestCase#getName()
+ */
+ @Override
+ public String getName()
+ {
+ return ClassUtils.getShortClassName(this.getClass()) + "::" + super.getName();
+ }
+
+ /**
+ * @return The IDatabase connection to use to insert data
+ * @throws SQLException Thrown on any database connection error
+ */
+ protected IDatabaseConnection createConnection() throws SQLException
+ {
+ DataSource dataSource = (DataSource) ctx.getBean("dataSource");
+ return new DatabaseConnection(dataSource.getConnection());
+ }
+
+ /**
+ * return the current Hibernate SessionFactory
+ * @return SessionFactory object
+ */
+ protected SessionFactory getSessionFactory()
+ {
+ return sessionFactory;
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|