Source Code Cross Referenced for OnlineTestCase.java in  » GIS » GeoTools-2.4.1 » org » geotools » test » 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 » GIS » GeoTools 2.4.1 » org.geotools.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2005-2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
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:        package org.geotools.test;
017:
018:        import java.io.BufferedInputStream;
019:        import java.io.File;
020:        import java.io.FileInputStream;
021:        import java.io.InputStream;
022:        import java.util.Properties;
023:
024:        import junit.framework.TestCase;
025:
026:        /**
027:         * Test support for test cases which require an "online" resource, such as an
028:         * external server or database.
029:         * <p>
030:         * Online tests work off of a "fixture". A fixture is a properties file which
031:         * defines connection parameters for some remote service. Each online test case
032:         * must define the id of the fixture is uses with {@link #getFixtureId()}.
033:         * </p>
034:         * <p>
035:         * Fixtures are stored under the users home directory, under the "{@code .geotools}"
036:         * directory. In the event that a fixture does not exist, the test case is
037:         * aborted.
038:         * </p>
039:         * <p>
040:         * Online tests connect to remote / online resources. Test cases should do all
041:         * connection / disconnection in the {@link #connect} and {@link #disconnect()}
042:         * methods.
043:         * </p>
044:         *
045:         * @since 2.4
046:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/sample-data/src/main/java/org/geotools/test/OnlineTestCase.java $
047:         * @version $Id: OnlineTestCase.java 25806 2007-06-11 22:04:55Z chorner $
048:         * @author Justin Deoliveira, The Open Planning Project
049:         */
050:        public abstract class OnlineTestCase extends TestCase {
051:            /**
052:             * The test fixture, {@code null} if the fixture is not available.
053:             */
054:            protected Properties fixture;
055:
056:            /**
057:             * Loads the test fixture for the test case.
058:             * <p>
059:             * The fixture is obtained via {@link #getFixtureId()}.
060:             * </p>
061:             */
062:            protected void setUp() throws Exception {
063:                super .setUp();
064:
065:                // load the fixture
066:                File base = new File(System.getProperty("user.home")
067:                        + File.separator + ".geotools");
068:                String fixtureId = getFixtureId();
069:                if (fixtureId == null) {
070:                    fixture = null; // not available (turn test off)            
071:                    return;
072:                }
073:                File fixtureFile = new File(base, fixtureId.replace('.',
074:                        File.separatorChar).concat(".properties"));
075:
076:                if (fixtureFile.exists()) {
077:                    InputStream input = new BufferedInputStream(
078:                            new FileInputStream(fixtureFile));
079:                    try {
080:                        fixture = new Properties();
081:                        fixture.load(input);
082:                    } finally {
083:                        input.close();
084:                    }
085:
086:                    // call the setUp template method
087:                    try {
088:                        connect();
089:                    } catch (Throwable t) {
090:                        // abort the test
091:                        fixture = null;
092:
093:                        if (once) {
094:                            // print out connection failure message once
095:                            // (for people debugging a single test case)
096:                            t.printStackTrace();
097:                            once = false;
098:                        }
099:                    }
100:                }
101:            }
102:
103:            static boolean once = true;
104:
105:            /**
106:             * Tear down method for test, calls through to {@link #disconnect()} if the
107:             * test is active.
108:             */
109:            protected final void tearDown() throws Exception {
110:                if (fixture != null) {
111:                    try {
112:                        disconnect();
113:                    } catch (Throwable t) {
114:                        // do nothing
115:                    }
116:                }
117:            }
118:
119:            /**
120:             * Connection method, called from {@link #setUp()}.
121:             * <p>
122:             * Subclasses should do all initialization / connection here. In the event
123:             * of a connection not being available, this method should throw an
124:             * exception to abort the test case.
125:             * </p>
126:             * 
127:             * @throws Exception if the connection failed.
128:             */
129:            protected void connect() throws Exception {
130:            }
131:
132:            /**
133:             * Disconnection method, called from {@link #tearDown()}.
134:             * <p>
135:             * Subclasses should do all cleanup here.
136:             * </p>
137:             * 
138:             * @throws Exception if the disconnection failed.
139:             */
140:            protected void disconnect() throws Exception {
141:            }
142:
143:            /**
144:             * Override which checks if the fixture is available. If not the test is not
145:             * executed.
146:             */
147:            protected void runTest() throws Throwable {
148:                // if the fixture was loaded, run
149:                if (fixture != null) {
150:                    super .runTest();
151:                }
152:
153:                // otherwise do nothing
154:            }
155:
156:            /**
157:             * The fixture id for the test case.
158:             * <p>
159:             * This name is hierachical, similar to a java package name. Example:
160:             * {@code "postgis.demo_bc"}.
161:             * </p>
162:             * 
163:             * @return The fixture id.
164:             */
165:            protected abstract String getFixtureId();
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.