01: package org.geotools.data.dir;
02:
03: import java.io.File;
04: import java.io.FileNotFoundException;
05: import java.io.IOException;
06: import java.util.Arrays;
07: import java.util.HashMap;
08: import java.util.Map;
09:
10: import org.geotools.TestData;
11:
12: import junit.framework.TestCase;
13:
14: public class DirectoryDataStoreTest extends TestCase {
15:
16: public void testFeatureTypes() throws IOException {
17: DirectoryDataStoreFactory factory = new DirectoryDataStoreFactory();
18: Map params = new HashMap();
19: copyShapefiles("shapes/archsites.shp");
20: File f = copyShapefiles("shapes/bugsites.shp");
21: params.put(DirectoryDataStoreFactory.DIRECTORY.key, f
22: .getParentFile().toURL());
23: params.put(DirectoryDataStoreFactory.CREATE_SUFFIX_ORDER.key,
24: new String[] { "shp" });
25: DirectoryDataStore store = (DirectoryDataStore) factory
26: .createDataStore(params);
27: assertTrue(store.getTypeNames().length > 0);
28: assertTrue(Arrays.asList(store.getTypeNames()).contains(
29: "archsites"));
30: assertTrue(Arrays.asList(store.getTypeNames()).contains(
31: "bugsites"));
32: }
33:
34: /**
35: * Copies the specified shape file into the {@code test-data} directory, together with its
36: * sibling ({@code .dbf}, {@code .shp}, {@code .shx} and {@code .prj} files).
37: */
38: protected File copyShapefiles(final String name) throws IOException {
39: assertTrue(TestData.copy(this , sibling(name, "dbf")).canRead());
40: assertTrue(TestData.copy(this , sibling(name, "shp")).canRead());
41: try {
42: assertTrue(TestData.copy(this , sibling(name, "shx"))
43: .canRead());
44: } catch (FileNotFoundException e) {
45: // Ignore: this file is optional.
46: }
47: try {
48: assertTrue(TestData.copy(this , sibling(name, "prj"))
49: .canRead());
50: } catch (FileNotFoundException e) {
51: // Ignore: this file is optional.
52: }
53: return TestData.copy(this , name);
54: }
55:
56: /**
57: * Helper method for {@link #copyShapefiles}.
58: */
59: private static String sibling(String name, final String ext) {
60: final int s = name.lastIndexOf('.');
61: if (s >= 0) {
62: name = name.substring(0, s);
63: }
64: return name + '.' + ext;
65: }
66: }
|