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


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