KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > appfuse > dao > BaseDaoTestCase


1 package org.appfuse.dao;
2
3 import java.util.Enumeration JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Map JavaDoc;
6 import java.util.MissingResourceException JavaDoc;
7 import java.util.ResourceBundle JavaDoc;
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 /**
15  * Base class for running Dao tests.
16  * @author mraible
17  */

18 public abstract class BaseDaoTestCase extends AbstractTransactionalDataSourceSpringContextTests {
19     protected final Log log = LogFactory.getLog(getClass());
20     protected ResourceBundle JavaDoc rb;
21
22     protected String JavaDoc[] getConfigLocations() {
23         setAutowireMode(AUTOWIRE_BY_NAME);
24         return new String JavaDoc [] {"classpath*:/**/dao/applicationContext-*.xml",
25                               "classpath*:META-INF/applicationContext-*.xml"};
26     }
27     
28     public BaseDaoTestCase() {
29         // Since a ResourceBundle is not required for each class, just
30
// do a simple check to see if one exists
31
String JavaDoc className = this.getClass().getName();
32
33         try {
34             rb = ResourceBundle.getBundle(className);
35         } catch (MissingResourceException JavaDoc mre) {
36             //log.warn("No resource bundle found for: " + className);
37
}
38     }
39
40     /**
41      * Utility method to populate a javabean-style object with values
42      * from a Properties file
43      * @param obj
44      * @return Object populated object
45      * @throws Exception
46      */

47     protected Object JavaDoc populate(Object JavaDoc obj) throws Exception JavaDoc {
48         // loop through all the beans methods and set its properties from
49
// its .properties file
50
Map JavaDoc map = new HashMap JavaDoc();
51
52         for (Enumeration JavaDoc keys = rb.getKeys(); keys.hasMoreElements();) {
53             String JavaDoc key = (String JavaDoc) 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