1   package com.germinus.merlin;
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.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.springframework.beans.BeanUtils;
12  import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
13  
14  import com.germinus.merlin.mock.IMockMerlinFactory;
15  
16  public abstract class BaseTestCase extends AbstractTransactionalDataSourceSpringContextTests{
17  
18  	protected IMockMerlinFactory mockMerlinFactory;
19  	protected final Log log = LogFactory.getLog(getClass());
20      protected ResourceBundle rb;
21  
22      protected String[] getConfigLocations() {
23  
24  		return new String[] {"classpath*:/context/applicationContext-pageTemplates.xml",
25  							 "classpath*:/context/applicationContext-web.xml",
26  		        			 "classpath*:/context/applicationContext-dao.xml",
27  		        			 "classpath*:/context/applicationContextTest-factory.xml",
28  		        			 "classpath*:/context/applicationContextTest-resources.xml",
29  		        			 "classpath*:/context/applicationContextTest-util.xml",
30  		        			 "classpath*:/context/applicationContext-manager.xml"};
31  		}
32      
33      public BaseTestCase() {
34          // Since a ResourceBundle is not required for each class, just
35          // do a simple check to see if one exists
36          String className = this.getClass().getName();
37  
38          try {
39              rb = ResourceBundle.getBundle(className);
40          } catch (MissingResourceException mre) {
41          	// TODO Es necesario esto?  
42              log.warn("No resource bundle found for: " + className);
43          }
44      }
45      
46      /**
47       * Utility method to populate a javabean-style object with values
48       * from a Properties file
49       * @param obj the model object to populate
50       * @return Object populated object
51       * @throws Exception if BeanUtils fails to copy properly
52       */
53      protected Object populate(Object obj) throws Exception {
54          // loop through all the beans methods and set its properties from
55          // its .properties file
56          Map<String, String> map = new HashMap<String, String>();
57  
58          for (Enumeration<String> keys = rb.getKeys(); keys.hasMoreElements();) {
59              String key = keys.nextElement();
60              map.put(key, rb.getString(key));
61          }
62  
63          BeanUtils.copyProperties(map, obj);
64  
65          return obj;
66      }
67      
68  	/**
69  	 * @return the mockMerlinFactory
70  	 */
71  	public IMockMerlinFactory getMockMerlinFactory() {
72  		return mockMerlinFactory;
73  	}
74  
75  	/**
76  	 * @param mockMerlinFactory the mockMerlinFactory to set
77  	 */
78  	public void setMockMerlinFactory(IMockMerlinFactory mockMerlinFactory) {
79  		this.mockMerlinFactory = mockMerlinFactory;
80  	}
81  }