Source Code Cross Referenced for StaticBehaviourFactory.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:        /* StaticBehaviourFactory.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.io.IOException;
024:        import java.util.Properties;
025:
026:        import junit.framework.TestCase;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:        import org.ddsteps.data.DataLoader;
031:        import org.ddsteps.dataset.DataTable;
032:        import org.ddsteps.util.TestCaseInfo;
033:        import org.ddsteps.util.TestCaseNameUtils;
034:        import org.springframework.core.io.ClassPathResource;
035:        import org.springframework.core.io.support.PropertiesLoaderSupport;
036:
037:        /**
038:         * @author adam
039:         * @version $Id: StaticBehaviourFactory.java,v 1.1 2006/01/29 21:25:39
040:         *          adamskogman Exp $
041:         */
042:        public class StaticBehaviourFactory extends PropertiesLoaderSupport {
043:
044:            /**
045:             * Logger.
046:             */
047:            protected static final Log LOG = LogFactory
048:                    .getLog(StaticBehaviourFactory.class);
049:
050:            /**
051:             * Singleton: Instance of this class.
052:             */
053:            protected static StaticBehaviourFactory instance;
054:
055:            /**
056:             * Field: The loaded properties
057:             */
058:            protected Properties properties;
059:
060:            /**
061:             * Singleton getter.
062:             * 
063:             * @return Singleton instance.
064:             */
065:            public synchronized static StaticBehaviourFactory getInstance() {
066:
067:                if (instance == null) {
068:                    instance = new StaticBehaviourFactory();
069:                    instance.afterPropertiesSet();
070:                }
071:
072:                return instance;
073:            }
074:
075:            /**
076:             * Call this method to get the appropriate behaviour for your testcase.
077:             * 
078:             * @param testCase
079:             *            Your testcase, typically 'this'.
080:             * @param dataLoader
081:             *            A dataLoader.
082:             * @return The behaviour, not null.
083:             */
084:            public static DdBehaviour getBehaviour(TestCase testCase,
085:                    DataLoader dataLoader) {
086:                return getInstance().createBehaviour(testCase, dataLoader);
087:            }
088:
089:            /**
090:             * 
091:             */
092:            public StaticBehaviourFactory() {
093:                super ();
094:                // TODO Refactor this to the DataLoader or into A dataloader
095:                setLocation(new ClassPathResource(
096:                        "/ddsteps-defaults.properties"));
097:                setIgnoreResourceNotFound(false);
098:
099:            }
100:
101:            /**
102:             * Loads the global properties.
103:             * 
104:             * @see org.ddsteps.properties.SystemPropertiesLoaderSupport#afterPropertiesSet()
105:             */
106:            public void afterPropertiesSet() {
107:                try {
108:                    properties = mergeProperties();
109:                } catch (IOException e) {
110:                    LOG
111:                            .info("No ddsteps-defaults.properties (default values for all datadriven tests)"
112:                                    + " in the default package (root of the classpath).");
113:                }
114:            }
115:
116:            /**
117:             * Actual implementation.
118:             * 
119:             * @param testCase
120:             * @param dataLoader
121:             * @return A behaviour, never null.
122:             */
123:            public DdBehaviour createBehaviour(TestCase testCase,
124:                    DataLoader dataLoader) {
125:
126:                TestCaseInfo info = TestCaseNameUtils
127:                        .parseTestCaseName(testCase.getName());
128:
129:                if (info.isMethodInstance()) {
130:                    // It's a method instance, so it may or may not be data driven
131:
132:                    // Try loading the data for this method
133:                    // TODO Improve by adding a hasTable method - save memory!
134:                    DataTable table = dataLoader.loadTable(testCase, info
135:                            .getMethodName());
136:
137:                    if (table != null) {
138:                        // Data Driven!
139:                        return new DdMethodBehaviour(testCase, info
140:                                .getMethodName(), dataLoader);
141:                    } else {
142:                        // Not Data Driven
143:                        // TODO Singleton
144:                        return new JUnitMethodBehaviour();
145:                    }
146:
147:                } else {
148:
149:                    // DataDriven Method
150:                    // Let it load for itself
151:                    DdRowBehaviour rowBehaviour = new DdRowBehaviour(testCase,
152:                            info.getMethodName(), info.getRowId(), dataLoader);
153:                    rowBehaviour.setProperties(properties);
154:                    return rowBehaviour;
155:
156:                }
157:
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.