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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-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;
009:         *    version 2.1 of the License.
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.data.shapefile.indexed;
017:
018:        import java.io.File;
019:        import java.io.IOException;
020:        import java.io.BufferedReader;
021:        import java.io.FileNotFoundException;
022:        import java.util.ArrayList;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        import junit.framework.Test;
027:        import junit.framework.TestCase;
028:        import junit.framework.TestSuite;
029:
030:        import org.geotools.feature.Feature;
031:        import org.geotools.feature.FeatureCollection;
032:        import org.geotools.TestData;
033:
034:        import com.vividsolutions.jts.geom.Geometry;
035:        import com.vividsolutions.jts.io.ParseException;
036:        import com.vividsolutions.jts.io.WKTReader;
037:
038:        /**
039:         * Base class for test suite. This class is not abstract for the purpose of
040:         * {@link TestCaseSupportTest}, but should not be instantiated otherwise.
041:         * It should be extented (which is why the constructor is protected).
042:         * <p>
043:         * Note: a nearly identical copy of this file exists in the {@code plugin/shapefile} module.
044:         *
045:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/TestCaseSupport.java $
046:         * @version $Id: TestCaseSupport.java 26202 2007-07-11 18:23:09Z jgarnett $
047:         * @author  Ian Schneider
048:         * @author  Martin Desruisseaux
049:         */
050:        public abstract class TestCaseSupport extends TestCase {
051:            /**
052:             * Set to {@code true} if {@code println} are wanted during normal execution.
053:             * It doesn't apply to message displayed in case of errors.
054:             */
055:            protected static boolean verbose = false;
056:
057:            /**
058:             * Stores all temporary files here - delete on tear down.
059:             */
060:            private final List tmpFiles = new ArrayList();
061:
062:            protected TestCaseSupport() {
063:            }
064:
065:            /**
066:             * Creates a new instance of {@code TestCaseSupport} with the given name.
067:             */
068:            protected TestCaseSupport(final String name) {
069:                super (name);
070:            }
071:
072:            /**
073:             * Deletes all temporary files created by {@link #getTempFile}.
074:             * This method is automatically run after each test.
075:             */
076:            protected void tearDown() throws Exception {
077:                // it seems that not all files marked as temp will get erased, perhaps
078:                // this is because they have been rewritten? Don't know, don't _really_
079:                // care, so I'll just delete everything
080:                final Iterator f = tmpFiles.iterator();
081:                while (f.hasNext()) {
082:                    File tf = (File) f.next();
083:                    dieDieDIE(sibling(tf, "dbf"));
084:                    dieDieDIE(sibling(tf, "shx"));
085:                    dieDieDIE(sibling(tf, "fix"));
086:                    dieDieDIE(sibling(tf, "qix"));
087:                    dieDieDIE(sibling(tf, "grx"));
088:                    dieDieDIE(sibling(tf, "prj"));
089:                    tf.delete();
090:                    f.remove();
091:                }
092:                super .tearDown();
093:            }
094:
095:            private void dieDieDIE(File file) {
096:                if (file.exists()) {
097:                    if (file.delete()) {
098:                        // dead
099:                    } else {
100:                        file.deleteOnExit(); // dead later
101:                    }
102:                }
103:            }
104:
105:            /**
106:             * Helper method for {@link #tearDown}.
107:             */
108:            protected static File sibling(final File f, final String ext) {
109:                return new File(f.getParent(), sibling(f.getName(), ext));
110:            }
111:
112:            /**
113:             * Helper method for {@link #copyShapefiles}.
114:             */
115:            protected static String sibling(String name, final String ext) {
116:                final int s = name.lastIndexOf('.');
117:                if (s >= 0) {
118:                    name = name.substring(0, s);
119:                }
120:                return name + '.' + ext;
121:            }
122:
123:            /**
124:             * Read a geometry of the given name.
125:             *
126:             * @param  wktResource The resource name to load, without its {@code .wkt} extension.
127:             * @return The geometry.
128:             * @throws IOException if reading failed.
129:             */
130:            protected Geometry readGeometry(final String wktResource)
131:                    throws IOException {
132:                final BufferedReader stream = TestData.openReader("wkt/"
133:                        + wktResource + ".wkt");
134:                final WKTReader reader = new WKTReader();
135:                final Geometry geom;
136:                try {
137:                    geom = reader.read(stream);
138:                } catch (ParseException pe) {
139:                    IOException e = new IOException(
140:                            "parsing error in resource " + wktResource);
141:                    e.initCause(pe);
142:                    throw e;
143:                }
144:                stream.close();
145:                return geom;
146:            }
147:
148:            /**
149:             * Returns the first feature in the given feature collection.
150:             */
151:            protected Feature firstFeature(FeatureCollection fc) {
152:                return fc.features().next();
153:            }
154:
155:            /**
156:             * Creates a temporary file, to be automatically deleted at the end of the test suite.
157:             */
158:            protected File getTempFile() throws IOException {
159:                File tmpFile = File.createTempFile("test-shp", ".shp");
160:                assertTrue(tmpFile.isFile());
161:                // keep track of all temp files so we can delete them
162:                tmpFiles.add(tmpFile);
163:                tmpFile.deleteOnExit();
164:                return tmpFile;
165:            }
166:
167:            /**
168:             * Copies the specified shape file into the {@code test-data} directory, together with its
169:             * sibling ({@code .dbf}, {@code .shp}, {@code .shx} and {@code .prj} files).
170:             */
171:            protected File copyShapefiles(final String name) throws IOException {
172:                if (this .getClass().getResourceAsStream("test-data") == null) {
173:                    String root = getClass().getResource(".").getFile();
174:                    File file = new File(root + "/" + "test-data");
175:                    if (file.mkdirs()) {
176:                        file.deleteOnExit();
177:                    }
178:                }
179:                assertTrue(TestData.copy(this , sibling(name, "dbf")).canRead());
180:                assertTrue(TestData.copy(this , sibling(name, "shp")).canRead());
181:                try {
182:                    assertTrue(TestData.copy(this , sibling(name, "shx"))
183:                            .canRead());
184:                } catch (FileNotFoundException e) {
185:                    // Ignore: this file is optional.
186:                }
187:                try {
188:                    assertTrue(TestData.copy(this , sibling(name, "prj"))
189:                            .canRead());
190:                } catch (FileNotFoundException e) {
191:                    // Ignore: this file is optional.
192:                }
193:                try {
194:                    assertTrue(TestData.copy(this , sibling(name, "grx"))
195:                            .canRead());
196:                } catch (FileNotFoundException e) {
197:                    // Ignore: this file is optional.
198:                }
199:                try {
200:                    assertTrue(TestData.copy(this , sibling(name, "fix"))
201:                            .canRead());
202:                } catch (FileNotFoundException e) {
203:                    // Ignore: this file is optional.
204:                }
205:                try {
206:                    assertTrue(TestData.copy(this , sibling(name, "qix"))
207:                            .canRead());
208:                } catch (FileNotFoundException e) {
209:                    // Ignore: this file is optional.
210:                }
211:                return TestData.copy(this , name);
212:            }
213:
214:            /**
215:             * Returns the test suite for the given class.
216:             */
217:            public static Test suite(Class c) {
218:                return new TestSuite(c);
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.