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
35
36 String className = this.getClass().getName();
37
38 try {
39 rb = ResourceBundle.getBundle(className);
40 } catch (MissingResourceException mre) {
41
42 log.warn("No resource bundle found for: " + className);
43 }
44 }
45
46
47
48
49
50
51
52
53 protected Object populate(Object obj) throws Exception {
54
55
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
70
71 public IMockMerlinFactory getMockMerlinFactory() {
72 return mockMerlinFactory;
73 }
74
75
76
77
78 public void setMockMerlinFactory(IMockMerlinFactory mockMerlinFactory) {
79 this.mockMerlinFactory = mockMerlinFactory;
80 }
81 }