Source Code Cross Referenced for TestDataPreparator.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » labor » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.module.labor.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.labor.util;
017:
018:        import java.util.ArrayList;
019:        import java.util.Arrays;
020:        import java.util.List;
021:        import java.util.Map;
022:        import java.util.Properties;
023:
024:        import org.apache.commons.lang.StringUtils;
025:        import org.kuali.module.gl.bo.OriginEntryGroup;
026:        import org.kuali.module.labor.bo.LaborOriginEntry;
027:
028:        /**
029:         * provide with a set of utilities that can be used to prepare test data for unit testing. The core idea is to convert Java
030:         * properties into a list of specified business objects or search criteria.
031:         */
032:        public class TestDataPreparator {
033:            public static final String DEFAULT_FIELD_NAMES = "fieldNames";
034:            public static final String DEFAULT_DELIMINATOR = "deliminator";
035:
036:            /**
037:             * build a list of objects of type "clazz" from the test data provided by the given properties. The default fieldNames and
038:             * deliminator are used.
039:             * 
040:             * @param clazz the the specified object type
041:             * @param properties the given properties that contain the test data
042:             * @param propertyKeyPrefix the test data with the given key prefix can be used to construct the return objects
043:             * @param numberOfData the number of test data matching the search criteria
044:             * @return a list of objects of type "clazz" from the test data provided by the given properties
045:             */
046:            public static List buildTestDataList(Class clazz,
047:                    Properties properties, String propertyKeyPrefix,
048:                    int numberOfData) {
049:                String fieldNames = properties.getProperty(DEFAULT_FIELD_NAMES);
050:                String deliminator = properties
051:                        .getProperty(DEFAULT_DELIMINATOR);
052:                return buildTestDataList(clazz, properties, propertyKeyPrefix,
053:                        fieldNames, deliminator, numberOfData);
054:            }
055:
056:            /**
057:             * build a list of objects of type "clazz" from the test data provided by the given properties
058:             * 
059:             * @param clazz the the specified object type
060:             * @param properties the given properties that contain the test data
061:             * @param propertyKeyPrefix the test data with the given key prefix can be used to construct the return objects
062:             * @param fieldNames the field names of the test data columns
063:             * @param deliminator the deliminator that is used to separate the field from each other
064:             * @param numberOfData the number of test data matching the search criteria
065:             * @return a list of objects of type "clazz" from the test data provided by the given properties
066:             */
067:            public static List buildTestDataList(Class clazz,
068:                    Properties properties, String propertyKeyPrefix,
069:                    String fieldNames, String deliminator, int numberOfData) {
070:                List testDataList = new ArrayList();
071:                for (int i = 1; i <= numberOfData; i++) {
072:                    String propertyKey = propertyKeyPrefix + i;
073:                    try {
074:                        Object testData = clazz.newInstance();
075:                        ObjectUtil.populateBusinessObject(testData, properties,
076:                                propertyKey, fieldNames, deliminator);
077:                        testDataList.add(testData);
078:                    } catch (Exception e) {
079:                        e.printStackTrace();
080:                    }
081:                }
082:                return testDataList;
083:            }
084:
085:            /**
086:             * build a list of objects of type "clazz" from the expected results provided by the given properties. The default fieldNames
087:             * and deliminator are used.
088:             * 
089:             * @param clazz the the specified object type. The instance of this type should be comparable through overriding Object.equals()
090:             * @param properties the given properties that contain the expected results
091:             * @param propertyKeyPrefix the expected results with the given key prefix can be used to construct the return objects
092:             * @param numberOfData the number of the expected results matching the search criteria
093:             * @return a list of objects of type "clazz" from the expected results provided by the given properties
094:             */
095:            public static List buildExpectedValueList(Class clazz,
096:                    Properties properties, String propertyKeyPrefix,
097:                    int numberOfData) {
098:                String fieldNames = properties.getProperty(DEFAULT_FIELD_NAMES);
099:                String deliminator = properties
100:                        .getProperty(DEFAULT_DELIMINATOR);
101:                return buildExpectedValueList(clazz, properties,
102:                        propertyKeyPrefix, fieldNames, deliminator,
103:                        numberOfData);
104:            }
105:
106:            /**
107:             * build a list of objects of type "clazz" from the expected results provided by the given properties
108:             * 
109:             * @param clazz the the specified object type. The instance of this type should be comparable through overriding Object.equals()
110:             * @param properties the given properties that contain the expected results
111:             * @param propertyKeyPrefix the expected results with the given key prefix can be used to construct the return objects
112:             * @param fieldNames the field names of the expected results columns
113:             * @param deliminator the deliminator that is used to separate the field from each other
114:             * @param numberOfData the number of the expected results matching the search criteria
115:             * @return a list of objects of type "clazz" from the expected results provided by the given properties
116:             */
117:            public static List buildExpectedValueList(Class clazz,
118:                    Properties properties, String propertyKeyPrefix,
119:                    String fieldNames, String deliminator, int numberOfData) {
120:                List expectedDataList = new ArrayList();
121:                for (int i = 1; i <= numberOfData; i++) {
122:                    String propertyKey = propertyKeyPrefix + i;
123:                    try {
124:                        Object expectedData = clazz.newInstance();
125:                        ObjectUtil.populateBusinessObject(expectedData,
126:                                properties, propertyKey, fieldNames,
127:                                deliminator);
128:
129:                        if (!expectedDataList.contains(expectedData)) {
130:                            expectedDataList.add(expectedData);
131:                        }
132:                    } catch (Exception e) {
133:                        e.printStackTrace();
134:                    }
135:                }
136:                return expectedDataList;
137:            }
138:
139:            /**
140:             * build the cleanup criteria for "clazz" from the given properties. The default fieldNames and deliminator are used.
141:             * 
142:             * @param clazz the the specified object type.
143:             * @param properties the given properties that contain the cleanup criteria fields and values
144:             * @param propertyKey the given property whose value provides the cleanup criteria values
145:             * @return the cleanup criteria for "clazz" from the given properties
146:             */
147:            public static Map<String, Object> buildCleanupCriteria(Class clazz,
148:                    Properties properties, String propertyKey) {
149:                String fieldNames = properties.getProperty(DEFAULT_FIELD_NAMES);
150:                String deliminator = properties
151:                        .getProperty(DEFAULT_DELIMINATOR);
152:                return buildCleanupCriteria(clazz, properties, propertyKey,
153:                        fieldNames, deliminator);
154:            }
155:
156:            /**
157:             * build the cleanup criteria for "clazz" from the given properties.
158:             * 
159:             * @param clazz the the specified object type.
160:             * @param properties the given properties that contain the cleanup criteria fields and values
161:             * @param propertyKey the given property whose value provides the cleanup criteria values
162:             * @param fieldNames the field names of the cleanup columns
163:             * @param deliminator the deliminator that is used to separate the field from each other
164:             * @return the cleanup criteria for "clazz" from the given properties
165:             */
166:            public static Map<String, Object> buildCleanupCriteria(Class clazz,
167:                    Properties properties, String propertyKey,
168:                    String fieldNames, String deliminator) {
169:                Object instanceOfClazz = null;
170:                try {
171:                    instanceOfClazz = clazz.newInstance();
172:                } catch (Exception e) {
173:                    e.printStackTrace();
174:                    return null;
175:                }
176:
177:                ObjectUtil.populateBusinessObject(instanceOfClazz, properties,
178:                        propertyKey, fieldNames, deliminator);
179:                return ObjectUtil.buildPropertyMap(instanceOfClazz, Arrays
180:                        .asList(StringUtils.split(fieldNames, deliminator)));
181:            }
182:
183:            /**
184:             * build a list of LaborOriginEntry objects from the given properties. The default fieldNames and deliminator are used.
185:             * 
186:             * @param properties the given properties that contain the data that can be used to populate LaborOriginEntry objects
187:             * @param propertyKeyPrefix the data with the given key prefix can be used to construct the return objects
188:             * @param fieldNames the field names of the data columns
189:             * @param deliminator the deliminator that is used to separate the field from each other
190:             * @param numberOfData the number of the data matching the search criteria
191:             * @return a list of LaborOriginEntry objects from the given properties
192:             */
193:            public static List<LaborOriginEntry> getLaborOriginEntryList(
194:                    Properties properties, String propertyKeyPrefix,
195:                    int numberOfInputData, OriginEntryGroup group) {
196:                String fieldNames = properties.getProperty(DEFAULT_FIELD_NAMES);
197:                String deliminator = properties
198:                        .getProperty(DEFAULT_DELIMINATOR);
199:                return getLaborOriginEntryList(properties, propertyKeyPrefix,
200:                        fieldNames, deliminator, numberOfInputData, group);
201:            }
202:
203:            /**
204:             * build a list of LaborOriginEntry objects from the given properties
205:             * 
206:             * @param properties the given properties that contain the data that can be used to populate LaborOriginEntry objects
207:             * @param propertyKeyPrefix the data with the given key prefix can be used to construct the return objects
208:             * @param fieldNames the field names of the data columns
209:             * @param deliminator the deliminator that is used to separate the field from each other
210:             * @param numberOfData the number of the data matching the search criteria
211:             * @return a list of LaborOriginEntry objects from the given properties
212:             */
213:            public static List<LaborOriginEntry> getLaborOriginEntryList(
214:                    Properties properties, String propertyKeyPrefix,
215:                    String fieldNames, String deliminator,
216:                    int numberOfInputData, OriginEntryGroup group) {
217:                List<LaborOriginEntry> inputDataList = new ArrayList<LaborOriginEntry>();
218:                for (int i = 1; i <= numberOfInputData; i++) {
219:                    String propertyKey = propertyKeyPrefix + i;
220:                    LaborOriginEntry inputData = new LaborOriginEntry();
221:                    ObjectUtil.populateBusinessObject(inputData, properties,
222:                            propertyKey, fieldNames, deliminator);
223:                    inputData.setEntryGroupId(group.getId());
224:                    inputDataList.add(inputData);
225:                }
226:                return inputDataList;
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.