Source Code Cross Referenced for DdMethodBehaviour.java in  » Testing » DDSteps » org » ddsteps » junit » behaviour » 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 » DDSteps » org.ddsteps.junit.behaviour 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* DdMethodBehaviour.java
002:         * 
003:         * DDSteps - Data Driven JUnit Test Steps
004:         * Copyright (C) 2005 Jayway AB
005:         * www.ddsteps.org
006:         * 
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License version 2.1 as published by the Free Software Foundation.
010:         * 
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         * 
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, visit 
018:         * http://www.opensource.org/licenses/lgpl-license.php
019:         */
020:
021:        package org.ddsteps.junit.behaviour;
022:
023:        import java.util.Iterator;
024:
025:        import junit.framework.TestCase;
026:        import junit.framework.TestResult;
027:        import junit.framework.TestSuite;
028:
029:        import org.ddsteps.data.DataLoader;
030:        import org.ddsteps.dataset.DataRow;
031:        import org.ddsteps.dataset.DataTable;
032:        import org.ddsteps.util.TestCaseNameUtils;
033:
034:        /**
035:         * Encapsulates the behaviour of the so called "method test case instance",
036:         * which is the one that spawns the row instances.
037:         * 
038:         * @author adam
039:         * @version $Id: DdMethodBehaviour.java,v 1.1 2005/08/25 08:34:21 adamskogman
040:         *          Exp $
041:         */
042:        public class DdMethodBehaviour extends DdBehaviourBase implements 
043:                DdBehaviour {
044:
045:            /**
046:             * Constructor.
047:             * 
048:             * @param testCase
049:             *            The test case to load.
050:             * @param methodName
051:             *            Name of the test method to run.
052:             * @param dataLoader
053:             *            The data loader to use.
054:             */
055:            public DdMethodBehaviour(TestCase testCase, String methodName,
056:                    DataLoader dataLoader) {
057:                super (testCase, methodName, dataLoader);
058:            }
059:
060:            /**
061:             * Asks the table how many rows there are.
062:             * 
063:             * @see org.ddsteps.junit.behaviour.DdBehaviour#countTestCases()
064:             */
065:            public int countTestCases() {
066:                DataTable table = dataLoader.loadTable(testCase, methodName);
067:                return table.getRowCount();
068:            }
069:
070:            /**
071:             * Goes through the rows in the data table and spawn a new row instance for
072:             * each. Calls <code>setUp</code> and <code>tearDown</code> on the
073:             * calling test case.
074:             * 
075:             * @param result
076:             *            Collects the results for each row.
077:             * @param ddTestCase
078:             *            The test case calling this method.
079:             * @return Always false, since this method will run row instances.
080:             * @see org.ddsteps.junit.behaviour.DdBehaviour#run(TestResult,
081:             *      DdBehaviourCallbackHandler)
082:             */
083:            public boolean run(TestResult result,
084:                    DdBehaviourCallbackHandler ddTestCase) {
085:
086:                try {
087:                    // This call will possibly call back to this behaviuor, to the
088:                    // setUp() method.
089:                    ddTestCase.setUp();
090:
091:                    // Use testCase to load, not the callback handler
092:                    DataTable table = dataLoader
093:                            .loadTable(testCase, methodName);
094:
095:                    for (Iterator iter = table.rowIterator(); iter.hasNext();) {
096:
097:                        DataRow row = (DataRow) iter.next();
098:
099:                        LOG.info("Processing row with id '" + row.getId()
100:                                + "'.");
101:
102:                        // Create a NEW iteration instance of this test class
103:                        TestCase rowInstance = createTestCaseIteration(row
104:                                .getId());
105:
106:                        // Run it. It will handle data loading by itself
107:                        rowInstance.run(result);
108:                    }
109:
110:                    // After all instances
111:                    ddTestCase.tearDown();
112:
113:                } catch (Exception e) {
114:                    // TODO Determine if this should move
115:                    result.addError(testCase, e);
116:                }
117:
118:                // Don't call super, there is nothing to run.
119:                return false;
120:
121:            }
122:
123:            /**
124:             * Factory method for creating the iteration instances.
125:             * 
126:             * @param rowId
127:             *            The row identity.
128:             * @return A test case iteration.
129:             */
130:            protected TestCase createTestCaseIteration(String rowId) {
131:
132:                String instanceName = TestCaseNameUtils.assembleName(
133:                        methodName, rowId);
134:
135:                // Create a NEW iteration instance of this test class
136:                TestCase instance = (TestCase) TestSuite.createTest(testCase
137:                        .getClass(), instanceName);
138:
139:                return instance;
140:            }
141:
142:            /**
143:             * Delegate back to (@link DdBehaviourCallbackHandler#setUpMethod()).
144:             * 
145:             * @see org.ddsteps.junit.behaviour.DdBehaviour#setUp(org.ddsteps.junit.behaviour.DdBehaviourCallbackHandler)
146:             */
147:            public void setUp(DdBehaviourCallbackHandler ddTestCase)
148:                    throws Exception {
149:                ddTestCase.setUpMethod();
150:            }
151:
152:            /**
153:             * Delegate back to (@link DdBehaviourCallbackHandler#tearDownMethod()).
154:             * 
155:             * @see org.ddsteps.junit.behaviour.DdBehaviour#tearDown(org.ddsteps.junit.behaviour.DdBehaviourCallbackHandler)
156:             */
157:            public void tearDown(DdBehaviourCallbackHandler ddTestCase)
158:                    throws Exception {
159:                ddTestCase.tearDownMethod();
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.