KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > service > core > BaseManagerTestCase


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.service.core;
17
18 import com.blandware.atleap.common.util.ConvertUtil;
19 import org.apache.commons.beanutils.BeanUtils;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.jmock.MockObjectTestCase;
23
24 import java.util.Map JavaDoc;
25 import java.util.MissingResourceException JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27
28 /**
29  * <p>Abstract base testcase for testing Managers. Provides facility for logging and
30  * some additional methods</p>
31  * <p><a HREF="BaseManagerTestCase.java.htm"><i>View Source</i></a></p>
32  *
33  * @author Matt Raible <a HREF="mailto:matt@raibledesigns.com">&lt;matt@raibledesigns.com&gt;</a>
34  * @version $Revision: 1.5 $ $Date: 2006/03/12 08:46:06 $
35  */

36 public abstract class BaseManagerTestCase extends MockObjectTestCase {
37     //~ Static fields/initializers =============================================
38

39     protected final Log log = LogFactory.getLog(getClass());
40     protected ResourceBundle JavaDoc rb;
41
42     //~ Constructors ===========================================================
43

44     public BaseManagerTestCase() {
45         // Since a ResourceBundle is not required for each class, just
46
// do a simple check to see if one exists
47
String JavaDoc className = this.getClass().getName();
48
49         try {
50             rb = ResourceBundle.getBundle(className);
51         } catch ( MissingResourceException JavaDoc mre ) {
52             //log.warn("No resource bundle found for: " + className);
53
}
54     }
55
56     //~ Methods ================================================================
57

58     /**
59      * Utility method to populate a javabean-style object with values
60      * from a Properties file
61      *
62      * @param obj bean to populate with properties
63      * @return populated bean
64      * @throws Exception
65      */

66     protected Object JavaDoc populate(Object JavaDoc obj) throws Exception JavaDoc {
67         // loop through all the beans methods and set its properties from
68
// its .properties file
69
Map JavaDoc map = ConvertUtil.convertBundleToMap(rb);
70
71         BeanUtils.copyProperties(obj, map);
72
73         return obj;
74     }
75 }
76
Popular Tags