📄 basetestcase.java
字号:
package com.longtime.wap.common.util;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.dbunit.DBTestCase;
import org.dbunit.PropertiesBasedJdbcDatabaseTester;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.operation.DatabaseOperation;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class BaseTestCase extends DBTestCase {
protected ApplicationContext context;
public BaseTestCase() {
context = new FileSystemXmlApplicationContext("/WebRoot/WEB-INF/applicationContext.xml");
String driver = this.getProperties("dataSource.properties").getProperty("ds.driver");
String url = this.getProperties("dataSource.properties").getProperty("ds.url");
String username = this.getProperties("dataSource.properties").getProperty("ds.username");
String password = this.getProperties("dataSource.properties").getProperty("ds.password");
String alias = this.getProperties("dataSource.properties").getProperty("ds.alias");
System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, driver );
System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, url );
System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, username );
System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, password );
System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA, alias );
}
protected IDataSet getDataSet() throws Exception {
return new FlatXmlDataSet(new FileInputStream("test//com//longtime//wap//wap_dataset.xml"));
}
protected DatabaseOperation getSetUpOperation() throws Exception {
return DatabaseOperation.CLEAN_INSERT;
}
protected DatabaseOperation getTearDownOperation() throws Exception {
return DatabaseOperation.CLEAN_INSERT;
}
public Properties getProperties(String str){
Properties properties = new Properties();
try{
InputStream is =getClass().getResourceAsStream("/"+str);
properties.load(is);
if(is != null)
is.close();
}
catch(IOException ioexception){
System.out.println("Open config file failure.");
}
catch(NullPointerException e){
System.out.println("is is null");
}
return properties;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -