Source Code Cross Referenced for AntJUnitEUTest.java in  » Test-Coverage » GroboUtils » net » sourceforge » groboutils » junit » v1 » iftc » 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 » Test Coverage » GroboUtils » net.sourceforge.groboutils.junit.v1.iftc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)JUnitTestSuiteEUTest.java
003:         *
004:         * Copyright (C) 2002-2003 Matt Albrecht
005:         * groboclown@users.sourceforge.net
006:         * http://groboutils.sourceforge.net
007:         *
008:         *  Permission is hereby granted, free of charge, to any person obtaining a
009:         *  copy of this software and associated documentation files (the "Software"),
010:         *  to deal in the Software without restriction, including without limitation
011:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
012:         *  and/or sell copies of the Software, and to permit persons to whom the 
013:         *  Software is furnished to do so, subject to the following conditions:
014:         *
015:         *  The above copyright notice and this permission notice shall be included in 
016:         *  all copies or substantial portions of the Software. 
017:         *
018:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
019:         *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
020:         *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL 
021:         *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
022:         *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
023:         *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
024:         *  DEALINGS IN THE SOFTWARE.
025:         */
026:
027:        package net.sourceforge.groboutils.junit.v1.iftc;
028:
029:        import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
030:        import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
031:
032:        import javax.xml.parsers.DocumentBuilder;
033:        import javax.xml.parsers.DocumentBuilderFactory;
034:        import org.w3c.dom.Document;
035:        import org.w3c.dom.NodeList;
036:        import org.w3c.dom.Node;
037:        import org.w3c.dom.Element;
038:
039:        import java.io.*;
040:
041:        import junit.framework.Test;
042:        import junit.framework.TestCase;
043:        import junit.framework.TestSuite;
044:        import junit.framework.TestResult;
045:
046:        import java.io.IOException;
047:        import java.lang.reflect.Method;
048:
049:        /**
050:         * Tests the functionality of the Ant JUnit optional tasks for what is
051:         * expected in operation of the naming facilities.
052:         *
053:         * @author    Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
054:         * @since     December 8, 2002
055:         * @version   $Date: 2003/02/10 22:52:21 $
056:         */
057:        public class AntJUnitEUTest extends TestCase {
058:            //-------------------------------------------------------------------------
059:            // Standard JUnit Class-specific declarations
060:            private static final Class THIS_CLASS = AntJUnitEUTest.class;
061:            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
062:                    .getLogger(THIS_CLASS);
063:
064:            private static class MyTest extends TestCase {
065:                public MyTest(String n) {
066:                    super (n);
067:                }
068:            }
069:
070:            public AntJUnitEUTest(String name) {
071:                super (name);
072:            }
073:
074:            //-------------------------------------------------------------------------
075:            // Tests
076:
077:            public void testNoTests1() throws Exception {
078:                MyTest mt[] = {};
079:                assertTestGroup("abc", mt);
080:            }
081:
082:            public void testSet1() throws Exception {
083:                MyTest mt[] = { new MyTest("t1"), new MyTest("t2"), };
084:                assertTestGroup("q.w.e.r.t.y.abc", mt);
085:            }
086:
087:            public void testSet2() throws Exception {
088:                MyTest mt[] = { new MyTest("A.t1[1]"), new MyTest("B.t2[1]"), };
089:                assertTestGroup("q.w.e.r.t.y.abc", mt);
090:            }
091:
092:            public void testSet3() throws Exception {
093:                MyTest mt[] = { new MyTest("A.t1[1]"), new MyTest("B.t2[1]"),
094:                        new MyTest("A.t1[1]"), // copy of first test name
095:                };
096:                assertTestGroup("q.w.e.r.t.y.abc", mt);
097:            }
098:
099:            //-------------------------------------------------------------------------
100:            // Helpers
101:
102:            protected XMLJUnitResultFormatter createFormatter(
103:                    ByteArrayOutputStream baos) {
104:                assertNotNull(baos);
105:                XMLJUnitResultFormatter rf = new XMLJUnitResultFormatter();
106:                rf.setOutput(baos);
107:                return rf;
108:            }
109:
110:            protected Document parseXML(String xmlDoc) throws Exception {
111:                LOG.info("Parsing XML: " + xmlDoc);
112:                InputStream is = new ByteArrayInputStream(xmlDoc.getBytes());
113:                Document doc = DocumentBuilderFactory.newInstance()
114:                        .newDocumentBuilder().parse(is);
115:                is.close();
116:                return doc;
117:            }
118:
119:            protected Element getTestsuiteElement(String xmlDoc)
120:                    throws Exception {
121:                Document doc = parseXML(xmlDoc);
122:                NodeList nl = doc.getElementsByTagName("testsuite");
123:                assertNotNull("null node list.", nl);
124:                assertTrue("empty node list.", nl.getLength() > 0);
125:                Node node = nl.item(0);
126:                assertNotNull("null node 0.", node);
127:                return (Element) node;
128:            }
129:
130:            protected Element[] getTestcaseElements(Element suite)
131:                    throws Exception {
132:                NodeList testNodes = suite.getElementsByTagName("testcase");
133:                if (testNodes == null) {
134:                    LOG.warn("Null node list of testcase elements.");
135:                    return new Element[0];
136:                }
137:                int len = testNodes.getLength();
138:                Element el[] = new Element[len];
139:                for (int i = 0; i < len; ++i) {
140:                    el[i] = (Element) testNodes.item(i);
141:                    LOG.debug("Found testcase node " + el[i]);
142:                }
143:                return el;
144:            }
145:
146:            protected void assertTestGroup(String testsuite, MyTest t[])
147:                    throws Exception {
148:                assertNotNull("Null test array", t);
149:
150:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
151:                XMLJUnitResultFormatter rf = createFormatter(baos);
152:                JUnitTest jt = new JUnitTest(testsuite);
153:                rf.startTestSuite(jt);
154:                for (int i = 0; i < t.length; ++i) {
155:                    rf.startTest(t[i]);
156:                    rf.endTest(t[i]);
157:                }
158:                rf.endTestSuite(jt);
159:
160:                String xml = new String(baos.toByteArray());
161:                baos.close();
162:                Element suiteEl = getTestsuiteElement(xml);
163:
164:                assertEquals("Incorrect test suite name in XML document.",
165:                        testsuite, suiteEl.getAttribute("name"));
166:
167:                Element cases[] = getTestcaseElements(suiteEl);
168:                int casesFound = 0;
169:                for (int i = 0; i < t.length; ++i) {
170:                    MyTest mt = t[i];
171:                    String mtName = mt.getName();
172:                    boolean found = false;
173:                    for (int j = 0; j < cases.length; ++j) {
174:                        if (cases[j] != null) {
175:                            String name = cases[j].getAttribute("name");
176:                            LOG.debug("Checking test '" + mtName
177:                                    + "' against xml element named '" + name
178:                                    + "'.");
179:                            if (mtName.equals(name)) {
180:                                cases[j] = null;
181:                                found = true;
182:                                ++casesFound;
183:                                break;
184:                            }
185:                        }
186:                    }
187:                    assertTrue("Did not find a testcase XML element for test '"
188:                            + t[i].getName() + "'.", found);
189:                }
190:                // check that all cases were found
191:                assertEquals(
192:                        "There were more testcases in the XML than were registered.",
193:                        t.length, casesFound);
194:            }
195:
196:            //-------------------------------------------------------------------------
197:            // Standard JUnit declarations
198:
199:            public static Test suite() {
200:                TestSuite suite = new TestSuite(THIS_CLASS);
201:
202:                return suite;
203:            }
204:
205:            public static void main(String[] args) {
206:                String[] name = { THIS_CLASS.getName() };
207:
208:                // junit.textui.TestRunner.main( name );
209:                // junit.swingui.TestRunner.main( name );
210:
211:                junit.textui.TestRunner.main(name);
212:            }
213:
214:            /**
215:             * 
216:             * @exception Exception thrown under any exceptional condition.
217:             */
218:            protected void setUp() throws Exception {
219:                super .setUp();
220:
221:                // set ourself up
222:            }
223:
224:            /**
225:             * 
226:             * @exception Exception thrown under any exceptional condition.
227:             */
228:            protected void tearDown() throws Exception {
229:                // tear ourself down
230:
231:                super.tearDown();
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.