01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.shapefile.indexed;
17:
18: import java.io.IOException;
19: import java.util.HashMap;
20: import java.util.Iterator;
21: import org.geotools.data.DataStore;
22: import org.geotools.data.DataStoreFactorySpi;
23: import org.geotools.data.DataStoreFinder;
24: import org.geotools.TestData;
25:
26: /**
27: *
28: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/ServiceTest.java $
29: * @version $Id: ServiceTest.java 26202 2007-07-11 18:23:09Z jgarnett $
30: * @author ian
31: */
32: public class ServiceTest extends TestCaseSupport {
33: final String TEST_FILE = "shapes/statepop.shp";
34:
35: public ServiceTest(String testName) throws IOException {
36: super (testName);
37: }
38:
39: public static void main(java.lang.String[] args) {
40: verbose = true;
41: junit.textui.TestRunner.run(suite(ServiceTest.class));
42: }
43:
44: /**
45: * Make sure that the loading mechanism does not pick up this factory!
46: */
47: public void testIsNotAvailable() {
48: Iterator list = DataStoreFinder.getAvailableDataStores();
49: boolean found = false;
50:
51: while (list.hasNext()) {
52: DataStoreFactorySpi fac = (DataStoreFactorySpi) list.next();
53:
54: if (fac instanceof IndexedShapefileDataStoreFactory) {
55: found = true;
56: assertNotNull(fac.getDescription());
57:
58: break;
59: }
60: }
61: assertFalse("ShapefileDataSourceFactory not registered", found);
62: }
63:
64: /**
65: * Ensure that we can create a DataStore using url OR string url.
66: */
67: public void testShapefileDataStore() throws Exception {
68: HashMap params = new HashMap();
69: params.put("url", TestData.url(TEST_FILE));
70:
71: DataStore ds = DataStoreFinder.getDataStore(params);
72: assertNotNull(ds);
73: params.put("url", TestData.url(TEST_FILE).toString());
74: assertNotNull(ds);
75: }
76:
77: public void testBadURL() {
78: HashMap params = new HashMap();
79: params.put("url", "aaa://bbb.ccc");
80:
81: try {
82: IndexedShapefileDataStoreFactory f = new IndexedShapefileDataStoreFactory();
83: f.createDataStore(params);
84: fail("did not throw error");
85: } catch (java.io.IOException ioe) {
86: // this is actually good
87: }
88: }
89: }
|