1 package org.appfuse.dao; 2 3 import java.util.Enumeration ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 import java.util.MissingResourceException ; 7 import java.util.ResourceBundle ; 8 9 import org.apache.commons.beanutils.BeanUtils; 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; 13 14 18 public abstract class BaseDaoTestCase extends AbstractTransactionalDataSourceSpringContextTests { 19 protected final Log log = LogFactory.getLog(getClass()); 20 protected ResourceBundle rb; 21 22 protected String [] getConfigLocations() { 23 setAutowireMode(AUTOWIRE_BY_NAME); 24 return new String [] {"classpath*:/**/dao/applicationContext-*.xml", 25 "classpath*:META-INF/applicationContext-*.xml"}; 26 } 27 28 public BaseDaoTestCase() { 29 String className = this.getClass().getName(); 32 33 try { 34 rb = ResourceBundle.getBundle(className); 35 } catch (MissingResourceException mre) { 36 } 38 } 39 40 47 protected Object populate(Object obj) throws Exception { 48 Map map = new HashMap (); 51 52 for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) { 53 String key = (String ) keys.nextElement(); 54 map.put(key, rb.getString(key)); 55 } 56 57 BeanUtils.copyProperties(obj, map); 58 59 return obj; 60 } 61 } 62 | Popular Tags |