Source Code Cross Referenced for JUnitReportCollector.java in  » Web-Services » soapui-1.7.5 » com » eviware » soapui » 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 » Web Services » soapui 1.7.5 » com.eviware.soapui.report 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  soapUI, copyright (C) 2004-2007 eviware.com 
003:         *
004:         *  soapUI is free software; you can redistribute it and/or modify it under the 
005:         *  terms of version 2.1 of the GNU Lesser General Public License as published by 
006:         *  the Free Software Foundation.
007:         *
008:         *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
009:         *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
010:         *  See the GNU Lesser General Public License for more details at gnu.org.
011:         */
012:
013:        package com.eviware.soapui.report;
014:
015:        import java.io.File;
016:        import java.io.FileWriter;
017:        import java.io.PrintWriter;
018:        import java.io.StringWriter;
019:        import java.util.ArrayList;
020:        import java.util.Arrays;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Set;
025:
026:        import com.eviware.soapui.model.testsuite.TestCase;
027:        import com.eviware.soapui.model.testsuite.TestRunContext;
028:        import com.eviware.soapui.model.testsuite.TestRunListener;
029:        import com.eviware.soapui.model.testsuite.TestRunner;
030:        import com.eviware.soapui.model.testsuite.TestStep;
031:        import com.eviware.soapui.model.testsuite.TestStepResult;
032:        import com.eviware.soapui.model.testsuite.TestSuite;
033:        import com.eviware.soapui.model.testsuite.TestRunner.Status;
034:        import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus;
035:        import com.eviware.soapui.support.xml.XmlUtils;
036:
037:        /**
038:         * Collects TestRun results and creates JUnitReports
039:         * 
040:         * @author ole.matzura
041:         */
042:
043:        public class JUnitReportCollector implements  TestRunListener {
044:
045:            HashMap<String, JUnitReport> reports;
046:            HashMap<TestCase, StringBuffer> failures;
047:
048:            public JUnitReportCollector() {
049:                reports = new HashMap<String, JUnitReport>();
050:                failures = new HashMap<TestCase, StringBuffer>();
051:            }
052:
053:            public List<String> saveReports(String path) throws Exception {
054:
055:                List<String> result = new ArrayList<String>();
056:
057:                Iterator<String> keyset = reports.keySet().iterator();
058:                while (keyset.hasNext()) {
059:                    String name = keyset.next();
060:                    JUnitReport report = reports.get(name);
061:                    String fileName = path + File.separatorChar + "TEST-"
062:                            + name + ".xml";
063:                    saveReport(report, fileName);
064:                    result.add(fileName);
065:                }
066:
067:                return result;
068:            }
069:
070:            public HashMap<String, JUnitReport> getReports() {
071:                return reports;
072:            }
073:
074:            private void saveReport(JUnitReport report, String filename)
075:                    throws Exception {
076:                FileWriter fileWriter = new FileWriter(filename);
077:                fileWriter.write(report.toString());
078:                fileWriter.close();
079:            }
080:
081:            public String getReport() {
082:                Set<String> keys = reports.keySet();
083:                if (keys.size() > 0) {
084:                    String key = (String) keys.toArray()[0];
085:                    return reports.get(key).toString();
086:                }
087:                return "No reports..:";
088:            }
089:
090:            public void afterRun(TestRunner testRunner,
091:                    TestRunContext runContext) {
092:                TestCase testCase = testRunner.getTestCase();
093:                JUnitReport report = reports.get(testCase.getTestSuite()
094:                        .getName());
095:
096:                if (Status.INITIALIZED != testRunner.getStatus()
097:                        && Status.RUNNING != testRunner.getStatus()) {
098:                    if (Status.CANCELED == testRunner.getStatus()) {
099:                        report.addTestCaseWithFailure(testCase.getName(),
100:                                testRunner.getTimeTaken(), testRunner
101:                                        .getReason(), "");
102:                    }
103:                    if (Status.FAILED == testRunner.getStatus()) {
104:                        String msg = "";
105:                        if (failures.containsKey(testCase)) {
106:                            msg = failures.get(testCase).toString();
107:                        }
108:                        report.addTestCaseWithFailure(testCase.getName(),
109:                                testRunner.getTimeTaken(), testRunner
110:                                        .getReason(), msg);
111:                    }
112:                    if (Status.FINISHED == testRunner.getStatus()) {
113:                        report.addTestCase(testCase.getName(), testRunner
114:                                .getTimeTaken());
115:                    }
116:
117:                }
118:            }
119:
120:            public void afterStep(TestRunner testRunner,
121:                    TestRunContext runContext, TestStepResult result) {
122:                TestStep currentStep = runContext.getCurrentStep();
123:                TestCase testCase = currentStep.getTestCase();
124:
125:                if (result.getStatus() == TestStepStatus.FAILED) {
126:                    StringBuffer buf = new StringBuffer();
127:                    if (failures.containsKey(testCase)) {
128:                        buf = failures.get(testCase);
129:                    } else
130:                        failures.put(testCase, buf);
131:
132:                    buf.append("<b>" + result.getTestStep().getName()
133:                            + " Failed</b>");
134:                    buf.append("<pre>"
135:                            + XmlUtils.entitize(Arrays.toString(result
136:                                    .getMessages())) + "</pre>\n");
137:
138:                    StringWriter stringWriter = new StringWriter();
139:                    PrintWriter writer = new PrintWriter(stringWriter);
140:                    result.writeTo(writer);
141:
142:                    buf.append(XmlUtils.entitize(stringWriter.toString()));
143:                }
144:            }
145:
146:            public void beforeRun(TestRunner testRunner,
147:                    TestRunContext runContext) {
148:                TestCase testCase = testRunner.getTestCase();
149:                TestSuite testSuite = testCase.getTestSuite();
150:                if (!reports.containsKey(testSuite.getName())) {
151:                    JUnitReport report = new JUnitReport();
152:                    report.setTestSuiteName(testSuite.getName());
153:                    reports.put(testSuite.getName(), report);
154:                }
155:            }
156:
157:            public void beforeStep(TestRunner testRunner,
158:                    TestRunContext runContext) {
159:            }
160:
161:            public void reset() {
162:                reports.clear();
163:                failures.clear();
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.