]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/unit/IndependentDbTestCase.java
Rename into Core
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / unit / IndependentDbTestCase.java
diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/unit/IndependentDbTestCase.java b/org.argeo.slc/src/main/java/org/argeo/slc/unit/IndependentDbTestCase.java
deleted file mode 100644 (file)
index 8a0b07e..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-package org.argeo.slc.unit;\r
-\r
-import java.io.InputStream;\r
-import java.sql.SQLException;\r
-\r
-import javax.sql.DataSource;\r
-\r
-import org.dbunit.DataSourceDatabaseTester;\r
-import org.dbunit.DatabaseUnitException;\r
-import org.dbunit.IDatabaseTester;\r
-import org.dbunit.database.IDatabaseConnection;\r
-import org.dbunit.dataset.IDataSet;\r
-import org.dbunit.dataset.xml.FlatXmlDataSet;\r
-import org.dbunit.operation.DatabaseOperation;\r
-import org.springframework.core.io.ClassPathResource;\r
-import org.springframework.core.io.Resource;\r
-\r
-import org.hibernate.tool.hbm2ddl.SchemaExport;\r
-\r
-import org.argeo.slc.core.SlcException;\r
-\r
-/**\r
- * Helper to make db vendor independent tests using DbUnit data sets. Based on\r
- * {@link DbModel}.\r
- */\r
-public abstract class IndependentDbTestCase extends SpringBasedTestCase {\r
-       private IDatabaseTester databaseTester;\r
-\r
-       /** Creates the DDL of the data model and loads the data. */\r
-       @Override\r
-       protected void setUp() throws Exception {\r
-               super.setUp();\r
-\r
-               databaseTester = new DataSourceDatabaseTester(getDataSource());\r
-               databaseTester.setSetUpOperation(new DatabaseOperation() {\r
-\r
-                       @Override\r
-                       public void execute(IDatabaseConnection connection, IDataSet dataSet)\r
-                                       throws DatabaseUnitException, SQLException {\r
-                               DbModel dbModel = getDbModel();\r
-                               SchemaExport schemaExport = dbModel\r
-                                               .createSchemaExport(connection.getConnection());\r
-                               schemaExport.create(true, true);\r
-\r
-                               DatabaseOperation.INSERT.execute(connection, dataSet);\r
-                       }\r
-\r
-               });\r
-               databaseTester.setDataSet(createDataSet());\r
-               databaseTester.onSetup();\r
-       }\r
-\r
-       @Override\r
-       protected void tearDown() throws Exception {\r
-               if (databaseTester != null) {\r
-                       databaseTester.onTearDown();\r
-               }\r
-               super.tearDown();\r
-       }\r
-\r
-       /**\r
-        * The data source to use. The default implementation returns a bean named\r
-        * {@link #getDataSourceBeanName}\r
-        */\r
-       protected DataSource getDataSource() {\r
-               return (DataSource) getContext().getBean(getDataSourceBeanName());\r
-       }\r
-\r
-       /**\r
-        * The name of the data source bean to use. The default implementation\r
-        * returns <i>dataSource</i>.\r
-        */\r
-       protected String getDataSourceBeanName() {\r
-               return "dataSource";\r
-       }\r
-\r
-       /**\r
-        * Creates the data set to use. The default implementation creates a\r
-        * <code>FlatXmlDataSet</code> load from the resource defined in\r
-        * {@link #getDataSetResource()}\r
-        */\r
-       protected IDataSet createDataSet() {\r
-               try {\r
-                       InputStream in = getDataSetResource().getInputStream();\r
-                       IDataSet dataSet = new FlatXmlDataSet(in);\r
-                       in.close();\r
-                       return dataSet;\r
-               } catch (Exception e) {\r
-                       throw new SlcException("Cannot create data set", e);\r
-               }\r
-       }\r
-\r
-       /**\r
-        * The resource of the data set to load. The default implementation loads a\r
-        * <code>ClassPathResource</code> located at\r
-        * {@link #getDataSetResourceLocation()}.\r
-        */\r
-       protected Resource getDataSetResource() {\r
-               return new ClassPathResource(getDataSetResourceLocation());\r
-       }\r
-\r
-       /**\r
-        * The location of the data set to load. The default implementation loads\r
-        * <i>dataSet.xml</i> found in the same package as the test.\r
-        */\r
-       protected String getDataSetResourceLocation() {\r
-               return inPackage("dataSet.xml");\r
-       }\r
-\r
-       /**\r
-        * The DB model to us to create the DDL of the testes database. The default\r
-        * implementation loads a bean named after {@link #getDbModelBeanName()}.\r
-        */\r
-       protected DbModel getDbModel() {\r
-               return (DbModel) getContext().getBean(getDbModelBeanName());\r
-       }\r
-\r
-       /**\r
-        * The name of the bean to load. The default implementation returns\r
-        * <i>dbModel</i>.\r
-        */\r
-       protected String getDbModelBeanName() {\r
-               return "dbModel";\r
-       }\r
-}\r