01: /*
02: * Geotools2 - 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: */
17: package org.geotools.data.shapefile;
18:
19: import java.io.IOException;
20: import java.util.HashMap;
21: import java.util.Iterator;
22:
23: import org.geotools.data.DataStore;
24: import org.geotools.data.DataStoreFactorySpi;
25: import org.geotools.data.DataStoreFinder;
26: import org.geotools.TestData;
27:
28: /**
29: *
30: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ServiceTest.java $
31: * @version $Id: ServiceTest.java 22666 2006-11-09 03:50:28Z jgarnett $
32: * @author ian
33: */
34: public class ServiceTest extends TestCaseSupport {
35:
36: final String TEST_FILE = "shapes/statepop.shp";
37:
38: public ServiceTest(String testName) throws IOException {
39: super (testName);
40: }
41:
42: /**
43: * Make sure that the loading mechanism is working properly.
44: */
45: public void testIsAvailable() {
46: Iterator list = DataStoreFinder.getAvailableDataStores();
47: boolean found = false;
48: while (list.hasNext()) {
49: DataStoreFactorySpi fac = (DataStoreFactorySpi) list.next();
50: if (fac instanceof ShapefileDataStoreFactory) {
51: found = true;
52: assertNotNull(fac.getDescription());
53: break;
54: }
55: }
56: assertTrue("ShapefileDataSourceFactory not registered", found);
57: }
58:
59: /**
60: * Ensure that we can create a DataStore using url OR string url.
61: */
62: public void testShapefileDataStore() throws Exception {
63: HashMap params = new HashMap();
64: params.put("url", TestData.url(TEST_FILE));
65: DataStore ds = DataStoreFinder.getDataStore(params);
66: assertNotNull(ds);
67: params.put("url", TestData.url(TEST_FILE).toString());
68: assertNotNull(ds);
69: }
70:
71: public void testBadURL() {
72: HashMap params = new HashMap();
73: params.put("url", "aaa://bbb.ccc");
74: try {
75: ShapefileDataStoreFactory f = new ShapefileDataStoreFactory();
76: f.createDataStore(params);
77: fail("did not throw error");
78: } catch (java.io.IOException ioe) {
79: // this is actually good
80: }
81:
82: }
83:
84: }
|