Source Code Cross Referenced for TestResultDescription.java in  » 6.0-JDK-Modules » j2me » gunit » framework » 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 » 6.0 JDK Modules » j2me » gunit.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)TestResultDescription.java	1.5 06/10/10
003:         * 
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation. 
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt). 
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA 
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions. 
025:         */
026:
027:        package gunit.framework;
028:
029:        import java.io.*;
030:        import java.util.*;
031:        import java.awt.*;
032:        import java.net.*;
033:
034:        /**
035:         * <code>TestResultDescription</code> describes the test result in text
036:         * and/or image formats. The testcase developer needs to provide the 
037:         * following for testcases that needs user verification.
038:         * <ul>
039:         *  <li>create a file with the same name as the TestCase java file with
040:         *      the <b>.java</b> extension replaced with <b>.xml</b> in the same
041:         *      same directory as the java source file</li>
042:         *  <li>Inside the xml file, specify the text and image description for
043:         *      each of the testcase method that needs user verification as 
044:         *      mentioned in the section <b>Format</b> below</li>
045:         * </ul>
046:         * <h4>Format</h4>
047:         * <pre>
048:         * &lt;methodName&gt;
049:         *    &lt;test&gt;
050:         *      <b>test description line 1</b>
051:         *      <b>test description line 2</b>
052:         *         ...
053:         *      <b>test description line n</b>
054:         *    &lt;/test&gt;
055:         *    &lt;image&gt;
056:         *      <b>URL of the imagefile</b>
057:         *    &lt;/image&gt;
058:         * &lt;/methodName&gt;
059:         * </pre>
060:         */
061:        public class TestResultDescription {
062:            // Map<Class,Map<String,TestResultDescription>>
063:            static Map descriptionMap = new HashMap();
064:            static final TestResultDescription defaultDescription = new TestResultDescription();
065:
066:            static TestResultDescription getInstance(Class c, String methodName) {
067:                Map class_desc_map = (Map) descriptionMap.get(c);
068:                if (class_desc_map == null) {
069:                    String file = c.getName();
070:                    int index = file.lastIndexOf('.');
071:                    if (index > 0) {
072:                        // there is a package name, extract just the class name
073:                        file = file.substring(index + 1);
074:                    }
075:                    file = file + ".xml";
076:                    InputStream stream = c.getResourceAsStream(file);
077:                    class_desc_map = new HashMap(); // create empty one
078:                    if (stream != null)
079:                        XMLParser.parse(stream, class_desc_map);
080:                    descriptionMap.put(c, class_desc_map);
081:                }
082:
083:                TestResultDescription desc = (TestResultDescription) class_desc_map
084:                        .get(methodName);
085:                if (desc != null)
086:                    return desc;
087:                return defaultDescription;
088:            }
089:
090:            private String text;
091:            private String imageURL;
092:
093:            private TestResultDescription() {
094:                this (null, null);
095:            }
096:
097:            private TestResultDescription(String text, String imageURL) {
098:                this .text = text;
099:                this .imageURL = imageURL;
100:            }
101:
102:            public String getText() {
103:                return this .text;
104:            }
105:
106:            public String getImageURL() {
107:                return this .imageURL;
108:            }
109:
110:            public Image getImage() {
111:                Image ret = null;
112:                if (this .imageURL == null)
113:                    return null;
114:                try {
115:                    URL url = new URL(this .imageURL);
116:                    ret = Toolkit.getDefaultToolkit().createImage(url);
117:                    BaseTestCase.trackImage(ret);
118:                } catch (Exception ex) {
119:                }
120:                return ret;
121:            }
122:
123:            static class XMLParser {
124:                private static final String TEXT_START_TAG = "<text>";
125:                private static final String IMAGE_START_TAG = "<image>";
126:                private static final String TEXT_END_TAG = "</text>";
127:                private static final String IMAGE_END_TAG = "</image>";
128:
129:                static void parse(InputStream stream, Map map) {
130:                    BufferedReader reader = null;
131:                    String line = null;
132:                    String method_start_tag = null;
133:                    boolean in_text_tag = false;
134:                    boolean in_image_tag = false;
135:                    String image_content = null;
136:                    StringBuffer text_content = new StringBuffer("");
137:                    try {
138:                        reader = new BufferedReader(new InputStreamReader(
139:                                stream));
140:                        while ((line = reader.readLine()) != null) {
141:                            line = line.trim(); // trim white spaces
142:                            if (line.startsWith("</")) { // check if end tag
143:                                if (TEXT_END_TAG.equals(line) && in_text_tag) {
144:                                    in_text_tag = false;
145:                                } else if (IMAGE_END_TAG.equals(line)
146:                                        && in_image_tag) {
147:                                    in_image_tag = false;
148:                                } else if (method_start_tag != null
149:                                        && line.substring(2).startsWith(
150:                                                method_start_tag)) {
151:                                    // process an end tag only if
152:                                    // we had processed a start tag AND
153:                                    // the end tag markup is the same as the start tag
154:
155:                                    TestResultDescription desc = new TestResultDescription(
156:                                            text_content.toString(),
157:                                            image_content);
158:                                    map.put(method_start_tag, desc);
159:
160:                                    text_content.delete(0, text_content
161:                                            .length());
162:                                    image_content = null;
163:                                    method_start_tag = null;
164:                                    in_text_tag = false; // force it
165:                                    in_image_tag = false; // force it
166:                                }
167:                            } else if (line.startsWith(TEXT_START_TAG)) {
168:                                in_text_tag = true;
169:                            } else if (line.startsWith(IMAGE_START_TAG)) {
170:                                in_image_tag = true;
171:                            } else if (in_text_tag) {
172:                                text_content.append(line + " ");
173:                            } else if (in_image_tag) {
174:                                image_content = line;
175:                            } else if (line.startsWith("<")) { // check for start tag
176:                                int end_index = line.indexOf(">");
177:                                if (end_index < 0)
178:                                    continue; // no markup termination
179:                                line = line.substring(1, end_index).trim();
180:                                if (line.length() < 0)
181:                                    continue; // no content inside markup
182:                                method_start_tag = line;
183:                            }
184:                        }
185:                    } catch (Exception ex) {
186:                    } finally {
187:                        try {
188:                            reader.close();
189:                        } catch (Exception ex) {
190:                        }
191:                    }
192:                }
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.