\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 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
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) getApplicationContext().getBean(\r
- getDataSourceBeanName());\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
}\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) getApplicationContext().getBean(getDbModelBeanName());\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
import junit.framework.TestCase;\r
\r
+/** Helper for tests using a Spring application co,text. */\r
public class SpringBasedTestCase extends TestCase {\r
private ApplicationContext context;\r
\r
* implementation uses a class path xml application context and calls\r
* {@link #getApplicationContextLocation()}.\r
*/\r
- protected ApplicationContext getApplicationContext() {\r
+ protected ApplicationContext getContext() {\r
if (context == null) {\r
context = new ClassPathXmlApplicationContext(\r
getApplicationContextLocation());\r
}\r
\r
/**\r
- * Get the application context location used by the default implementation\r
- * of {@link #getApplicationContext()}.\r
+ * Th location of the application to load. The default implementation\r
+ * returns <i>applicationContext.xml</i> found in the same package as the\r
+ * test.\r
*/\r
protected String getApplicationContextLocation() {\r
return inPackage("applicationContext.xml");\r
}\r
- \r
- protected String inPackage(String suffix){\r
+\r
+ /**\r
+ * Prefixes the package of the class after converting the '.' to '/' in\r
+ * order to have a resource path.\r
+ */\r
+ protected String inPackage(String suffix) {\r
String prefix = getClass().getPackage().getName().replace('.', '/');\r
- return prefix+'/'+suffix;\r
+ return prefix + '/' + suffix;\r
}\r
}\r