01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2006-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; either
09: * version 2.1 of the License, or (at your option) any later version.
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.catalog.shapefile;
17:
18: import java.io.File;
19: import java.io.FileNotFoundException;
20: import java.io.IOException;
21: import java.net.URI;
22: import java.net.URL;
23: import java.util.HashMap;
24: import java.util.List;
25:
26: import junit.framework.TestCase;
27:
28: import org.geotools.TestData;
29: import org.geotools.catalog.Service;
30: import org.geotools.catalog.ServiceInfo;
31: import org.geotools.data.shapefile.ShapefileDataStoreFactory;
32: import org.geotools.data.shapefile.indexed.TestCaseSupport;
33:
34: public class ShapefileServiceTest extends TestCaseSupport {
35: final static String STATE_POP = "shapes/statepop.shp";
36:
37: /**
38: * Test that shapefile geo resource throws a FileNotFoundException when
39: * the file does not exist.
40: *
41: */
42: public void testShapefileNotExists() throws Exception {
43: URI uri = new URI("file:///home/nouser/nofile.shp");
44: HashMap params = new HashMap();
45: params.put(ShapefileDataStoreFactory.URLP.key, uri.toURL());
46:
47: Service service = new ShapefileService(null, uri, params);
48: try {
49: service.getInfo(null);
50: fail("Expected a filenot found exception");
51: } catch (FileNotFoundException e) {
52: //ok
53: }
54: }
55:
56: //
57: public void testShapefileExists() throws Exception {
58: File file = copyShapefiles(STATE_POP);
59: URL url = file.toURL();
60:
61: HashMap params = new HashMap();
62: params.put(ShapefileDataStoreFactory.URLP.key, url);
63:
64: Service service = new ShapefileService(null, new URI(url
65: .toString()), params);
66:
67: // show we can connect
68: ServiceInfo info = service.getInfo(null);
69: assertNotNull(info);
70:
71: List members = service.members(null);
72: assertEquals(1, members.size());
73:
74: ShapefileGeoResource resource = (ShapefileGeoResource) members
75: .get(0);
76: resource.getInfo(null);
77: }
78: }
|