From: <fg...@us...> - 2008-01-31 13:13:36
|
Revision: 578 http://openutils.svn.sourceforge.net/openutils/?rev=578&view=rev Author: fgiust Date: 2008-01-31 05:13:40 -0800 (Thu, 31 Jan 2008) Log Message: ----------- a few fixes, start tracking changes in changes.xml Modified Paths: -------------- 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 Added Paths: ----------- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/CleanInsertOperation.java trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityCleanInsertOperation.java trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityInsertOperation.java trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlAbstractNoFkOperation.java trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkCleanInsertOperation.java trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkInsertOperation.java trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkTruncateOperation.java trunk/openutils-testing/src/site/changes/ trunk/openutils-testing/src/site/changes/changes.xml 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-30 21:24:20 UTC (rev 577) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-01-31 13:13:40 UTC (rev 578) @@ -65,10 +65,9 @@ boolean truncateAll() default true; /** - * The database operation that will be used to truncate tables. Defaults to - * org.dbunit.operation.TruncateTableOperation + * The database operation that will be used to truncate tables. Defaults to org.dbunit.operation.DeleteAllOperation */ - Class< ? extends DatabaseOperation> truncateOperation() default org.dbunit.operation.TruncateTableOperation.class; + Class< ? extends DatabaseOperation> truncateOperation() default org.dbunit.operation.DeleteAllOperation.class; /** * The database operation that will be used to load datasets. Defaults to org.dbunit.operation.InsertOperation 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-30 21:24:20 UTC (rev 577) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-01-31 13:13:40 UTC (rev 578) @@ -267,19 +267,28 @@ log.debug("Generating sorted dataset for initial cleanup"); IDataSet unsortedDataSet = connection.createDataSet(); - log.debug("Unfiltered truncateDataSet: {}", ArrayUtils.toString(unsortedDataSet.getTableNames())); + if (log.isDebugEnabled()) + { + 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)); + // excluded unwanted tables + unsortedDataSet = new FilteredDataSet(tableFilter, unsortedDataSet); + + // sort tables + ITableFilter sortingFilter = new DatabaseSequenceFilter(connection, unsortedDataSet.getTableNames()); + truncateDataSet = new FilteredDataSet(sortingFilter, unsortedDataSet); + storeTruncateDataset(dataSourceName, connection.getSchema(), truncateDataSet); log.debug("Sorted dataset generated"); } - log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); if (truncateDataSet != null) { + if (log.isDebugEnabled()) + { + log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); + } databaseOperation.execute(connection, truncateDataSet); } } 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-30 21:24:20 UTC (rev 577) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-31 13:13:40 UTC (rev 578) @@ -89,7 +89,6 @@ } finally { - connection.close(); fos.close(); } Added: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/CleanInsertOperation.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/CleanInsertOperation.java (rev 0) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/CleanInsertOperation.java 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,40 @@ +/* + * 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.dbunit; + +import org.dbunit.operation.CompositeOperation; +import org.dbunit.operation.DatabaseOperation; + + +/** + * Mimics the standard <code>DatabaseOperation.CLEAN_INSERT</code> operation with an empty constructor (can be used in + * annotations). + * @author fgiust + * @version $Id: $ + */ +public class CleanInsertOperation extends CompositeOperation +{ + + /** + * @param action1 + * @param action2 + */ + public CleanInsertOperation() + { + super(DatabaseOperation.DELETE_ALL, DatabaseOperation.INSERT); + } + +} Property changes on: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/CleanInsertOperation.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityCleanInsertOperation.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityCleanInsertOperation.java (rev 0) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityCleanInsertOperation.java 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,40 @@ +/* + * 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.dbunit; + +import org.dbunit.ext.mssql.InsertIdentityOperation; +import org.dbunit.operation.DatabaseOperation; + + +/** + * Extends the standard org.dbunit.ext.mssql.InsertIdentityOperation in order to be able to use this class directly in a + * annotation. Wraps a <code>DatabaseOperation.CLEAN_INSERT</code> operation. + * @see org.dbunit.ext.mssql.InsertIdentityOperation + * @author fgiust + * @version $Id: $ + */ +public class MsSqlIndentityCleanInsertOperation extends InsertIdentityOperation +{ + + /** + * @param operation + */ + public MsSqlIndentityCleanInsertOperation() + { + super(DatabaseOperation.CLEAN_INSERT); + } + +} Property changes on: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityCleanInsertOperation.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityInsertOperation.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityInsertOperation.java (rev 0) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityInsertOperation.java 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,40 @@ +/* + * 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.dbunit; + +import org.dbunit.ext.mssql.InsertIdentityOperation; +import org.dbunit.operation.DatabaseOperation; + + +/** + * Extends the standard org.dbunit.ext.mssql.InsertIdentityOperation in order to be able to use this class directly in a + * annotation. Wraps a <code>DatabaseOperation.INSERT</code> operation. + * @see org.dbunit.ext.mssql.InsertIdentityOperation + * @author fgiust + * @version $Id: $ + */ +public class MsSqlIndentityInsertOperation extends InsertIdentityOperation +{ + + /** + * @param operation + */ + public MsSqlIndentityInsertOperation() + { + super(DatabaseOperation.INSERT); + } + +} Property changes on: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MsSqlIndentityInsertOperation.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlAbstractNoFkOperation.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlAbstractNoFkOperation.java (rev 0) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlAbstractNoFkOperation.java 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,90 @@ +/* + * 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.dbunit; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import org.dbunit.DatabaseUnitException; +import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.IDataSet; +import org.dbunit.operation.AbstractOperation; +import org.dbunit.operation.DatabaseOperation; +import org.dbunit.operation.ExclusiveTransactionException; + + +/** + * Extended operation for dbunit that disables FK checks. + * @author fgiust + * @version $Id: $ + */ +public class MySqlAbstractNoFkOperation extends AbstractOperation +{ + + /** + * Wrapped operation. + */ + private final DatabaseOperation operation; + + /** + * Creates a new InsertIdentityOperation object that decorates the specified operation. + * @param operation wrapped operation + */ + public MySqlAbstractNoFkOperation(DatabaseOperation operation) + { + this.operation = operation; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException + { + Connection jdbcConnection = connection.getConnection(); + Statement statement = jdbcConnection.createStatement(); + + try + { + if (!jdbcConnection.getAutoCommit()) + { + throw new ExclusiveTransactionException(); + } + jdbcConnection.setAutoCommit(false); + + // disable FK + statement.execute("SET FOREIGN_KEY_CHECKS=0"); + + try + { + operation.execute(connection, connection.createDataSet()); + } + finally + { + // enable FK + statement.execute("SET FOREIGN_KEY_CHECKS=1"); + jdbcConnection.commit(); + } + + } + finally + { + jdbcConnection.setAutoCommit(true); + statement.close(); + } + } +} Property changes on: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlAbstractNoFkOperation.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkCleanInsertOperation.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkCleanInsertOperation.java (rev 0) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkCleanInsertOperation.java 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,37 @@ +/* + * 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.dbunit; + +import org.dbunit.operation.DatabaseOperation; + + +/** + * Extended operation for dbunit that disables FK checks. + * @author fgiust + * @version $Id: $ + */ +public class MySqlNoFkCleanInsertOperation extends MySqlAbstractNoFkOperation +{ + + /** + * @param operation + */ + public MySqlNoFkCleanInsertOperation() + { + super(DatabaseOperation.TRUNCATE_TABLE); + } + +} Property changes on: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkCleanInsertOperation.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkInsertOperation.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkInsertOperation.java (rev 0) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkInsertOperation.java 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,37 @@ +/* + * 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.dbunit; + +import org.dbunit.operation.DatabaseOperation; + + +/** + * Extended operation for dbunit that disables FK checks. + * @author fgiust + * @version $Id: $ + */ +public class MySqlNoFkInsertOperation extends MySqlAbstractNoFkOperation +{ + + /** + * @param operation + */ + public MySqlNoFkInsertOperation() + { + super(DatabaseOperation.TRUNCATE_TABLE); + } + +} Property changes on: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkInsertOperation.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkTruncateOperation.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkTruncateOperation.java (rev 0) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkTruncateOperation.java 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,37 @@ +/* + * 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.dbunit; + +import org.dbunit.operation.DatabaseOperation; + + +/** + * Extended operation for dbunit that disables FK checks. + * @author fgiust + * @version $Id: $ + */ +public class MySqlNoFkTruncateOperation extends MySqlAbstractNoFkOperation +{ + + /** + * @param operation + */ + public MySqlNoFkTruncateOperation() + { + super(DatabaseOperation.TRUNCATE_TABLE); + } + +} Property changes on: trunk/openutils-testing/src/main/java/it/openutils/testing/dbunit/MySqlNoFkTruncateOperation.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-testing/src/site/changes/changes.xml =================================================================== --- trunk/openutils-testing/src/site/changes/changes.xml (rev 0) +++ trunk/openutils-testing/src/site/changes/changes.xml 2008-01-31 13:13:40 UTC (rev 578) @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<!-- + "type" attribute can be: add, remove, update or fix. +--> +<document> + <properties> + <title>Changes</title> + <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> + </properties> + <body> + <release version="2.0.2" date="in svn" description="2.0.2"> + <action type="add" dev="fgiust"> + New dbunit operation classes for mssql and mysql (extension of standard dbunit operation, but refactored so that + they can be used in annotations). See the javadocs in the it.openutils.testing.dbunit package + </action> + <action type="update" dev="fgiust"> + truncate operation now defaults to DbUnitOperation.DELETE_ALL instead of DbUnitOperation.TRUNCATE. + </action> + <action type="fix" dev="fgiust">DbUnitUtils.exportDataset() doesn't close anymore the provided connection</action> + </release> + <release version="2.0.1" date="2008-01-30" description="2.0.1"> + <action type="fix" dev="fgiust"> + (junit version only). it.openutils.testing.junit.AbstractDbUnitJunitSpringContextTests was totally broken due to + the setup method being protected. Fixed + added tests + </action> + </release> + <release version="2.0" date="2008-01-20" description="2.0 release"> + <action type="update" dev="fgiust">Totally reworked dbunit test framework.</action> + </release> + </body> +</document> \ No newline at end of file Property changes on: trunk/openutils-testing/src/site/changes/changes.xml ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |