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


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