Source Code Cross Referenced for HashMapper.java in  » Testing » jtestcase » org » jtestcase » core » mapping » 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 » Testing » jtestcase » org.jtestcase.core.mapping 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jtestcase.core.mapping;
002:
003:        import java.io.FileNotFoundException;
004:        import java.util.HashMap;
005:        import java.util.Iterator;
006:
007:        import org.jtestcase.JTestCaseException;
008:        import org.jtestcase.core.digester.DigesterException;
009:        import org.jtestcase.core.digester.JTestCaseDigester;
010:        import org.jtestcase.core.model.AssertParamGroupInstance;
011:        import org.jtestcase.core.model.AssertParamInstance;
012:        import org.jtestcase.core.model.ParamGroupInstance;
013:        import org.jtestcase.core.model.ParamInstance;
014:        import org.jtestcase.core.type.ComplexTypeConverter;
015:        import org.jtestcase.core.type.TypeConversionException;
016:        import org.jtestcase.util.MultiKeyHashtable;
017:
018:        public class HashMapper {
019:
020:            /**
021:             * The digester used for parsing the XML
022:             */
023:            private JTestCaseDigester digester;
024:
025:            /**
026:             * Type convert facility. This class is used to map "string" representation
027:             * of type to contrete instances of the type represented
028:             */
029:            private ComplexTypeConverter typeConverter;
030:
031:            public HashMapper(JTestCaseDigester digester,
032:                    ComplexTypeConverter typeConverter) {
033:                this .digester = digester;
034:                this .typeConverter = typeConverter;
035:            }
036:
037:            /**
038:             * <p>
039:             * Get all params for a given TestCaseInstance. Hashed key is param's name,
040:             * value is value of param. This method is normally used with
041:             * getNameOfTestCases().
042:             * </p>
043:             * <p>
044:             * HashMap's key is param's name defined in
045:             * /tests/class/method/params/param@name,
046:             * </p>
047:             * <p>
048:             * HashMap's value is param's Object value with type as indicated in
049:             * /test/class/method/params/param@type.
050:             * </p>
051:             * 
052:             * @return HashMap.
053:             * @throws JTestCaseException
054:             *             if an internal error occurs
055:             * @throws IllegalAccessException 
056:             * @throws InstantiationException 
057:             */
058:            public HashMap getTestCaseParams(String className, String method,
059:                    String testcase) throws JTestCaseException,
060:                    InstantiationException, IllegalAccessException {
061:                HashMap paramValues = new HashMap();
062:                try {
063:                    Iterator paramInstances = digester.getParamsInstances(
064:                            className, method, testcase).iterator();
065:                    while (paramInstances.hasNext()) {
066:                        ParamInstance paramInstance = (ParamInstance) paramInstances
067:                                .next();
068:                        Object value = typeConverter
069:                                ._convertType(paramInstance);
070:                        paramValues.put(paramInstance.getName(), value);
071:                    }
072:                    Iterator paramGroupInstances = digester
073:                            .getParamGroupInstances(className, method, testcase)
074:                            .iterator();
075:                    while (paramGroupInstances.hasNext()) {
076:                        ParamGroupInstance paramGroupInstance = (ParamGroupInstance) paramGroupInstances
077:                                .next();
078:                        _getParamValuesFromGroupInstance(paramGroupInstance
079:                                .getName(), paramValues, paramGroupInstance);
080:                    }
081:                } catch (TypeConversionException tce) {
082:                    throw new JTestCaseException(tce.getMessage());
083:                } catch (DigesterException de) {
084:                    throw new JTestCaseException(
085:                            "Error retrieving params in xml file : \n"
086:                                    + de.getMessage());
087:                } catch (FileNotFoundException de) {
088:                    throw new JTestCaseException("Cannot read xml file : \n"
089:                            + de.getMessage());
090:                }
091:
092:                return paramValues;
093:            }
094:
095:            /**
096:             * Extracts the param values from a ParamGroupInstance
097:             * 
098:             * @param path
099:             *            the path so far
100:             * @param flatParams
101:             *            the hashtable with the params
102:             * @param paramGroupInstance
103:             *            the ParamGroupInstance object to be analysed
104:             * @throws JTestCaseException
105:             *             if an internal error occurs
106:             * @throws IllegalAccessException 
107:             * @throws InstantiationException 
108:             */
109:            private void _getParamValuesFromGroupInstance(String path,
110:                    HashMap flatParams, ParamGroupInstance paramGroupInstance)
111:                    throws JTestCaseException, InstantiationException,
112:                    IllegalAccessException {
113:                Iterator paramIter = paramGroupInstance.getParamInstances()
114:                        .iterator();
115:                try {
116:                    while (paramIter.hasNext()) {
117:                        ParamInstance param = (ParamInstance) paramIter.next();
118:                        Object value = typeConverter._convertType(param);
119:                        flatParams.put(path + "/" + param.getName(), value);
120:                    }
121:                    Iterator paramGroupIter = paramGroupInstance
122:                            .getParamGroupInstances().iterator();
123:                    while (paramGroupIter.hasNext()) {
124:                        ParamGroupInstance paramGroup = (ParamGroupInstance) paramGroupIter
125:                                .next();
126:                        _getParamValuesFromGroupInstance(path + "/"
127:                                + paramGroup.getName(), flatParams, paramGroup);
128:                    }
129:                } catch (TypeConversionException tce) {
130:                    throw new JTestCaseException(tce.getMessage());
131:                }
132:            }
133:
134:            /**
135:             * Get all assert params for a given method and its test case value into
136:             * Hashtable. Hashed key is assert param's name, value is String value of
137:             * assert param. This method is normally used with getNameOfTestCases().
138:             * 
139:             * @param method -
140:             *            name of tested method. Defined in data file in
141:             *            /tests/class/method@test-case.
142:             * @param testcase -
143:             *            name of test case. Defined in data file in
144:             *            /tests/class/method@test-case. Should be unique for the given
145:             *            "methodName".
146:             * @return Hashtable. Key is assert param's name defined in
147:             *         /tests/class/method/asserts/assertparm@name, value is assert
148:             *         param's Object value with type as indecated in
149:             *         /test/class/method/asserts/assert@type. If not "type" specified
150:             *         in data file, then "String" is default type.
151:             * @throws JTestCaseException
152:             *             if an internal error occurs
153:             * @throws IllegalAccessException 
154:             * @throws InstantiationException 
155:             * @throws FileNotFoundException
156:             */
157:            public MultiKeyHashtable getTestCaseAssertParams(String className,
158:                    String method, String testcase) throws JTestCaseException,
159:                    InstantiationException, IllegalAccessException {
160:                MultiKeyHashtable assertValues = new MultiKeyHashtable();
161:                try {
162:                    Iterator assertInstances = digester
163:                            .getAssertsParamInstances(className, method,
164:                                    testcase).iterator();
165:                    while (assertInstances.hasNext()) {
166:                        AssertParamInstance assertInstance = (AssertParamInstance) assertInstances
167:                                .next();
168:                        String[] key = new String[2];
169:                        key[0] = assertInstance.getName();
170:                        key[1] = assertInstance.getAction();
171:                        Object value = typeConverter
172:                                ._convertType(assertInstance);
173:                        assertValues.put(key, value);
174:                    }
175:                    Iterator assertParamGroupInstances = digester
176:                            .getAssertParamGroupInstances(className, method,
177:                                    testcase).iterator();
178:                    while (assertParamGroupInstances.hasNext()) {
179:                        AssertParamGroupInstance assertParamGroupInstance = (AssertParamGroupInstance) assertParamGroupInstances
180:                                .next();
181:                        _getAssertParamValuesFromGroupInstance(
182:                                assertParamGroupInstance.getName(),
183:                                assertValues, assertParamGroupInstance);
184:                    }
185:                } catch (TypeConversionException tce) {
186:                    throw new JTestCaseException(
187:                            "Error converting assert to Java type");
188:                } catch (DigesterException e) {
189:                    throw new JTestCaseException("Error retrieving asserts.");
190:                } catch (FileNotFoundException de) {
191:                    throw new JTestCaseException("Cannot read xml file : \n"
192:                            + de.getMessage());
193:                }
194:                return assertValues;
195:            }
196:
197:            /**
198:             * Extracts the assert values from a AssertGroupInstance
199:             * 
200:             * @param path
201:             *            the path so far
202:             * @param flatAsserts
203:             *            the hashtable with the asserts
204:             * @param assertGroupInstance
205:             *            the AssertGroupInstance object to be analysed
206:             * @throws JTestCaseException
207:             *             if an internal error occurs
208:             * @throws IllegalAccessException 
209:             * @throws InstantiationException 
210:             */
211:            protected void _getAssertParamValuesFromGroupInstance(String path,
212:                    MultiKeyHashtable flatAsserts,
213:                    AssertParamGroupInstance assertParamGroupInstance)
214:                    throws JTestCaseException, InstantiationException,
215:                    IllegalAccessException {
216:                Iterator assertIter = assertParamGroupInstance
217:                        .getAssertParamInstances().iterator();
218:                try {
219:                    while (assertIter.hasNext()) {
220:                        AssertParamInstance asert = (AssertParamInstance) assertIter
221:                                .next();
222:                        Object value = typeConverter._convertType(asert);
223:                        String[] key = new String[2];
224:                        key[0] = path + "/" + asert.getName();
225:                        key[1] = asert.getAction();
226:                        flatAsserts.put(key, value);
227:                    }
228:                    Iterator assertGroupIter = assertParamGroupInstance
229:                            .getAssertParamGroupInstances().iterator();
230:                    while (assertGroupIter.hasNext()) {
231:                        AssertParamGroupInstance assertGroup = (AssertParamGroupInstance) assertGroupIter
232:                                .next();
233:                        _getAssertParamValuesFromGroupInstance(path + "/"
234:                                + assertGroup.getName(), flatAsserts,
235:                                assertGroup);
236:                    }
237:                } catch (TypeConversionException tce) {
238:
239:                    throw new JTestCaseException(
240:                            "Error converting param to Java type");
241:
242:                }
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.