Source Code Cross Referenced for ReportTestSuite.java in  » EJB-Server-geronimo » testsuite-maven-plugin » org » apache » geronimo » mavenplugins » testsuite » report » 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 » EJB Server geronimo » testsuite maven plugin » org.apache.geronimo.mavenplugins.testsuite.report 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *  
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.geronimo.mavenplugins.testsuite.report;
017:
018:        import org.xml.sax.Attributes;
019:        import org.xml.sax.SAXException;
020:        import org.xml.sax.helpers.DefaultHandler;
021:
022:        import javax.xml.parsers.ParserConfigurationException;
023:        import javax.xml.parsers.SAXParser;
024:        import javax.xml.parsers.SAXParserFactory;
025:        import java.io.File;
026:        import java.io.IOException;
027:        import java.text.NumberFormat;
028:        import java.text.ParseException;
029:        import java.util.ArrayList;
030:        import java.util.Collections;
031:        import java.util.List;
032:        import java.util.Map;
033:        import java.util.StringTokenizer;
034:
035:        public class ReportTestSuite extends DefaultHandler {
036:            private List testCases;
037:
038:            private int numberOfErrors;
039:
040:            private int numberOfFailures;
041:
042:            private int numberOfSkipped;
043:
044:            private int numberOfTests;
045:
046:            private String name;
047:
048:            private String fullClassName;
049:
050:            private String packageName;
051:
052:            private float timeElapsed;
053:
054:            private NumberFormat numberFormat = NumberFormat.getInstance();
055:
056:            /**
057:             * @noinspection StringBufferField
058:             */
059:            private StringBuffer currentElement;
060:
061:            private ReportTestCase testCase;
062:
063:            public void parse(String xmlPath)
064:                    throws ParserConfigurationException, SAXException,
065:                    IOException {
066:                SAXParserFactory factory = SAXParserFactory.newInstance();
067:
068:                SAXParser saxParser = factory.newSAXParser();
069:
070:                saxParser.parse(new File(xmlPath), this );
071:            }
072:
073:            private int getAttributeAsInt(Attributes attributes, String name) {
074:                // may or may not exist
075:                String valueAsString = attributes.getValue(name);
076:                if (valueAsString != null) {
077:                    return Integer.parseInt(valueAsString);
078:                }
079:                return 0;
080:            }
081:
082:            public void startElement(String uri, String localName,
083:                    String qName, Attributes attributes) throws SAXException {
084:                try {
085:                    if ("testsuite".equals(qName)) {
086:                        numberOfErrors = getAttributeAsInt(attributes, "errors");
087:                        numberOfFailures = getAttributeAsInt(attributes,
088:                                "failures");
089:                        numberOfSkipped = getAttributeAsInt(attributes,
090:                                "skipped");
091:                        numberOfTests = getAttributeAsInt(attributes, "tests");
092:
093:                        Number time = numberFormat.parse(attributes
094:                                .getValue("time"));
095:
096:                        timeElapsed = time.floatValue();
097:
098:                        //check if group attribute is existing
099:                        if (attributes.getValue("group") != null
100:                                && !"".equals(attributes.getValue("group"))) {
101:                            packageName = attributes.getValue("group");
102:
103:                            name = attributes.getValue("name");
104:
105:                            fullClassName = packageName + "." + name;
106:                        } else {
107:                            fullClassName = attributes.getValue("name");
108:
109:                            name = fullClassName.substring(fullClassName
110:                                    .lastIndexOf(".") + 1, fullClassName
111:                                    .length());
112:
113:                            int lastDotPosition = fullClassName
114:                                    .lastIndexOf(".");
115:                            if (lastDotPosition < 0) {
116:                                /* no package name */
117:                                packageName = "";
118:                            } else {
119:                                packageName = fullClassName.substring(0,
120:                                        lastDotPosition);
121:                            }
122:                        }
123:
124:                        testCases = new ArrayList();
125:                    } else if ("testcase".equals(qName)) {
126:                        currentElement = new StringBuffer();
127:
128:                        testCase = new ReportTestCase();
129:
130:                        testCase.setFullClassName(fullClassName);
131:
132:                        testCase.setName(attributes.getValue("name"));
133:
134:                        testCase.setClassName(name);
135:
136:                        String timeAsString = attributes.getValue("time");
137:
138:                        Number time = new Integer(0);
139:
140:                        if (timeAsString != null) {
141:                            time = numberFormat.parse(timeAsString);
142:                        }
143:
144:                        testCase.setTime(time.floatValue());
145:
146:                        testCase.setFullName(packageName + "." + name + "."
147:                                + testCase.getName());
148:                    } else if ("failure".equals(qName)) {
149:                        testCase.addFailure(attributes.getValue("message"),
150:                                attributes.getValue("type"));
151:                    } else if ("error".equals(qName)) {
152:                        testCase.addFailure(attributes.getValue("message"),
153:                                attributes.getValue("type"));
154:                    }
155:                } catch (ParseException e) {
156:                    throw new SAXException(e.getMessage(), e);
157:                }
158:            }
159:
160:            public void endElement(String uri, String localName, String qName)
161:                    throws SAXException {
162:                if ("testcase".equals(qName)) {
163:                    testCases.add(testCase);
164:                } else if ("failure".equals(qName)) {
165:                    Map failure = testCase.getFailure();
166:
167:                    failure
168:                            .put("detail",
169:                                    parseCause(currentElement.toString()));
170:                } else if ("error".equals(qName)) {
171:                    Map error = testCase.getFailure();
172:
173:                    error.put("detail", parseCause(currentElement.toString()));
174:                }
175:            }
176:
177:            public void characters(char[] ch, int start, int length)
178:                    throws SAXException {
179:                String s = new String(ch, start, length);
180:
181:                if (!"".equals(s.trim())) {
182:                    currentElement.append(s);
183:                }
184:            }
185:
186:            public List getTestCases() {
187:                return this .testCases;
188:            }
189:
190:            public int getNumberOfErrors() {
191:                return numberOfErrors;
192:            }
193:
194:            public void setNumberOfErrors(int numberOfErrors) {
195:                this .numberOfErrors = numberOfErrors;
196:            }
197:
198:            public int getNumberOfFailures() {
199:                return numberOfFailures;
200:            }
201:
202:            public void setNumberOfFailures(int numberOfFailures) {
203:                this .numberOfFailures = numberOfFailures;
204:            }
205:
206:            public int getNumberOfSkipped() {
207:                return numberOfSkipped;
208:            }
209:
210:            public void setNumberOfSkipped(int numberOfSkipped) {
211:                this .numberOfSkipped = numberOfSkipped;
212:            }
213:
214:            public int getNumberOfTests() {
215:                return numberOfTests;
216:            }
217:
218:            public void setNumberOfTests(int numberOfTests) {
219:                this .numberOfTests = numberOfTests;
220:            }
221:
222:            public String getName() {
223:                return name;
224:            }
225:
226:            public void setName(String name) {
227:                this .name = name;
228:            }
229:
230:            public String getFName() {
231:                return name;
232:            }
233:
234:            public void setFName(String name) {
235:                this .name = name;
236:            }
237:
238:            public String getPackageName() {
239:                return packageName;
240:            }
241:
242:            public void setPackageName(String packageName) {
243:                this .packageName = packageName;
244:            }
245:
246:            public float getTimeElapsed() {
247:                return this .timeElapsed;
248:            }
249:
250:            public void setTimeElapsed(float timeElapsed) {
251:                this .timeElapsed = timeElapsed;
252:            }
253:
254:            private List parseCause(String detail) {
255:                String fullName = testCase.getFullName();
256:                String name = fullName.substring(fullName.lastIndexOf(".") + 1);
257:                return parseCause(detail, name);
258:            }
259:
260:            private List parseCause(String detail, String compareTo) {
261:                StringTokenizer stringTokenizer = new StringTokenizer(detail,
262:                        "\n");
263:                List parsedDetail = new ArrayList(stringTokenizer.countTokens());
264:
265:                while (stringTokenizer.hasMoreTokens()) {
266:                    String lineString = stringTokenizer.nextToken().trim();
267:                    parsedDetail.add(lineString);
268:                    if (lineString.indexOf(compareTo) >= 0) {
269:                        break;
270:                    }
271:                }
272:
273:                return parsedDetail;
274:            }
275:
276:            public void setTestCases(List testCases) {
277:                this.testCases = Collections.unmodifiableList(testCases);
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.