【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:BaseDaoTestCase.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
package com.welshow.hbp.dao;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
/**
* Base class for running Dao tests.
* @author mraible
*/
public abstract class BaseDaoTestCase extends AbstractTransactionalDataSourceSpringContextTests {
protected final Log log = LogFactory.getLog(getClass());
protected ResourceBundle rb;
protected String[] getConfigLocations() {
setAutowireMode(AUTOWIRE_BY_NAME);
return new String [] {"classpath*:/**/dao/applicationContext-*.xml",
"classpath*:META-INF/applicationContext-*.xml"};
}
public BaseDaoTestCase() {
// Since a ResourceBundle is not required for each class, just
// do a simple check to see if one exists
String className = this.getClass().getName();
try {
rb = ResourceBundle.getBundle(className);
} catch (MissingResourceException mre) {
//log.warn("No resource bundle found for: " + className);
}
}
/**
* Utility method to populate a javabean-style object with values
* from a Properties file
* @param obj
* @return Object populated object
* @throws Exception
*/
protected Object populate(Object obj) throws Exception {
// loop through all the beans methods and set its properties from
// its .properties file
Map map = new HashMap();
for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) {
String key = (String) keys.nextElement();
map.put(key, rb.getString(key));
}
BeanUtils.copyProperties(obj, map);
return obj;
}
}
上一篇:
BaseDAOImpl.java
下一篇:
10例恶性黑色素瘤临床病理与治疗的临床研究