Source Code Cross Referenced for Tests.java in  » Testing » fit-java » fat » 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 » fit java » fat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2002 Cunningham & Cunningham, Inc.
002:        // Released under the terms of the GNU General Public License version 2 or later.
003:
004:        package fat;
005:
006:        import fit.*;
007:
008:        import java.net.URL;
009:        import java.io.*;
010:
011:        public class Tests extends Fixture {
012:
013:            Parse heads;
014:            String page;
015:
016:            public void doRows(Parse rows) {
017:                heads = rows.parts;
018:                super .doRows(rows.more);
019:            }
020:
021:            public void doCell(Parse cell, int column) {
022:                switch (column) {
023:                case (0):
024:                    page = cell.text();
025:                    break;
026:                default:
027:                    String language = heads.at(column).text();
028:                    String runscript = (String) Frameworks.runscripts
029:                            .get(language);
030:                    performTest(cell, runscript, page);
031:                }
032:            }
033:
034:            public void performTest(Parse cell, String runscript, String page) {
035:                if (runscript == null || runscript.equals("null")
036:                        || page.startsWith("?")) {
037:                    ignore(cell);
038:                    return;
039:                }
040:                String pageUrl = "http://fit.c2.com/wiki.cgi?" + page;
041:                String testUrl = runscript + pageUrl;
042:                try {
043:                    String testResult = get(new URL(testUrl));
044:                    Parse data = testResult.indexOf("<wiki>") >= 0 ? new Parse(
045:                            testResult, new String[] { "wiki", "td" }).parts
046:                            : new Parse(testResult, new String[] { "td" });
047:                    Counts c = count(data);
048:                    String message = anchor(c.right + "/" + c.wrong + "/"
049:                            + c.exceptions + "&nbsp;", testUrl);
050:                    cell.addToBody(message);
051:                    if (c.right > 0 && c.wrong == 0 && c.exceptions == 0) {
052:                        right(cell);
053:                    } else {
054:                        wrong(cell);
055:                        cell.addToBody(data.footnote());
056:                    }
057:                } catch (Throwable e) {
058:                    if (e.getMessage().indexOf("Can't find tag: td") >= 0) {
059:                        cell.addToBody("Can't parse <a href=\"" + testUrl
060:                                + "\">page</a>");
061:                        ignore(cell);
062:                    } else {
063:                        exception(cell, e);
064:                    }
065:                }
066:            }
067:
068:            protected String anchor(String body, String link) {
069:                return "<a href=\"" + link + "\">" + body + "</a>";
070:            }
071:
072:            protected String get(URL url) throws IOException {
073:                InputStream stream = (InputStream) url.getContent();
074:                BufferedReader reader = new BufferedReader(
075:                        new InputStreamReader(stream));
076:                StringBuffer buffer = new StringBuffer(10000);
077:                for (String line; (line = reader.readLine()) != null;) {
078:                    buffer.append(line);
079:                    buffer.append('\n');
080:                }
081:                return buffer.toString();
082:            }
083:
084:            protected Counts count(Parse data) throws Exception {
085:                Counts counts = new Counts();
086:                while (data != null) {
087:                    Color c = Color.parse(data);
088:                    data = data.more;
089:                    if (c == null) {
090:                        continue;
091:                    } else if (c.isGreen()) {
092:                        counts.right++;
093:                    } else if (c.isRed()) {
094:                        counts.wrong++;
095:                    } else if (c.isYellow()) {
096:                        counts.exceptions++;
097:                    } else if (c.isGray()) {
098:                        counts.ignores++;
099:                    }
100:                }
101:                return counts;
102:            }
103:
104:            public static class Color {
105:
106:                int r, g, b;
107:
108:                public Color(int r, int g, int b) {
109:                    this .r = r;
110:                    this .g = g;
111:                    this .b = b;
112:                }
113:
114:                public static Color parse(Parse cell) throws Exception {
115:                    if (cell == null) {
116:                        return null;
117:                    } else {
118:                        String pattern = " bgcolor=";
119:                        String tag = cell.tag.toLowerCase();
120:                        int index = tag.indexOf(pattern);
121:                        if (index >= 0) {
122:                            try {
123:                                index += pattern.length();
124:                                if (tag.charAt(index) == '"')
125:                                    index++;
126:                                if (tag.charAt(index) == '#')
127:                                    index++;
128:                                String hex = tag.substring(index, index + 6);
129:                                int rgb = Integer.parseInt(hex, 16);
130:                                return new Color(rgb >> 16 & 255,
131:                                        rgb >> 8 & 255, rgb & 255);
132:                            } catch (Exception e) {
133:                                throw new Exception("Can't parse bgcolor in: "
134:                                        + cell.tag);
135:                            }
136:                        } else {
137:                            return null;
138:                        }
139:                    }
140:                }
141:
142:                boolean isRed() {
143:                    return r > g && r > b;
144:                }
145:
146:                boolean isGreen() {
147:                    return g > r && g > b;
148:                }
149:
150:                boolean isYellow() {
151:                    return r > b && g > b;
152:                }
153:
154:                boolean isGray() {
155:                    return r == b && g == b;
156:                }
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.