001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.shapefile.indexed;
017:
018: import java.io.FileNotFoundException;
019: import java.io.IOException;
020: import java.net.URI;
021: import java.util.Arrays;
022: import java.util.HashMap;
023: import java.util.List;
024: import java.util.Map;
025: import org.geotools.TestData;
026: import org.geotools.data.DataStore;
027: import org.geotools.data.shapefile.ShapefileDataStore;
028: import org.geotools.data.shapefile.ShapefileDataStoreFactory;
029:
030: /**
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStoreFactoryTest.java $
032: */
033: public class IndexedShapefileDataStoreFactoryTest extends
034: TestCaseSupport {
035: private IndexedShapefileDataStoreFactory factory;
036:
037: public IndexedShapefileDataStoreFactoryTest() throws IOException {
038: super ("IndexedShapefileDataStoreFactoryTest");
039: }
040:
041: protected void setUp() throws Exception {
042: factory = new IndexedShapefileDataStoreFactory();
043: }
044:
045: /*
046: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.canProcess(Map)'
047: */
048: public void testCanProcessMap() throws Exception {
049: Map map = new HashMap();
050: map.put(IndexedShapefileDataStoreFactory.URLP.key, TestData
051: .url(ShapefileDataStoreTest.STATE_POP));
052: assertTrue(factory.canProcess(map));
053: }
054:
055: /*
056: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.createDataStore(Map)'
057: */
058: public void testCreateDataStoreMap() throws Exception {
059: testCreateDataStore(true);
060:
061: ShapefileDataStore ds1 = testCreateDataStore(true, true);
062: ShapefileDataStore ds2 = testCreateDataStore(true, true);
063:
064: assertSame(ds1, ds2);
065:
066: ds2 = testCreateDataStore(true, false);
067: assertNotSame(ds1, ds2);
068: }
069:
070: private ShapefileDataStore testCreateDataStore(boolean createIndex)
071: throws Exception {
072: return testCreateDataStore(true, createIndex);
073: }
074:
075: public void testNamespace() throws Exception {
076: ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
077: Map map = new HashMap();
078: URI namespace = new URI("http://jesse.com");
079: map.put(ShapefileDataStoreFactory.NAMESPACEP.key, namespace);
080: map.put(ShapefileDataStoreFactory.URLP.key, TestData
081: .url(ShapefileDataStoreTest.STATE_POP));
082:
083: DataStore store = factory.createDataStore(map);
084: assertEquals(namespace, store.getSchema(
085: ShapefileDataStoreTest.STATE_POP
086: .substring(ShapefileDataStoreTest.STATE_POP
087: .indexOf('/') + 1,
088: ShapefileDataStoreTest.STATE_POP
089: .lastIndexOf('.')))
090: .getNamespace());
091: }
092:
093: private ShapefileDataStore testCreateDataStore(boolean newDS,
094: boolean createIndex) throws Exception {
095: copyShapefiles(ShapefileDataStoreTest.STATE_POP);
096: Map map = new HashMap();
097: map.put(ShapefileDataStoreFactory.URLP.key, TestData.url(this ,
098: ShapefileDataStoreTest.STATE_POP));
099: map.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key,
100: createIndex ? Boolean.TRUE : Boolean.FALSE);
101:
102: ShapefileDataStore ds;
103:
104: if (newDS) {
105: // This may provided a warning if the file already is created
106: ds = (ShapefileDataStore) factory.createNewDataStore(map);
107: } else {
108: ds = (ShapefileDataStore) factory.createDataStore(map);
109: }
110:
111: if (ds instanceof IndexedShapefileDataStore) {
112: IndexedShapefileDataStore indexed = (IndexedShapefileDataStore) ds;
113: testDataStore(IndexedShapefileDataStore.TREE_QIX,
114: createIndex, indexed);
115: }
116: return ds;
117: }
118:
119: private void testDataStore(byte treeType, boolean createIndex,
120: IndexedShapefileDataStore ds) {
121: assertNotNull(ds);
122: assertEquals(treeType, ds.treeType);
123: assertEquals(treeType != IndexedShapefileDataStore.TREE_NONE,
124: ds.useIndex);
125: assertEquals(createIndex
126: && (treeType != IndexedShapefileDataStore.TREE_NONE),
127: ds.createIndex);
128: }
129:
130: /*
131: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.createNewDataStore(Map)'
132: */
133: public void testCreateNewDataStore() throws Exception {
134: ShapefileDataStore ds1 = testCreateDataStore(true, false);
135: ShapefileDataStore ds2 = testCreateDataStore(true, true);
136:
137: assertNotSame(ds1, ds2);
138: }
139:
140: /*
141: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.isAvailable()'
142: */
143: public void testIsAvailable() {
144: assertTrue(factory.isAvailable());
145: }
146:
147: /*
148: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.getParametersInfo()'
149: */
150: public void testGetParametersInfo() {
151: List infos = Arrays.asList(factory.getParametersInfo());
152: assertTrue(infos
153: .contains(IndexedShapefileDataStoreFactory.CREATE_SPATIAL_INDEX));
154: assertTrue(infos
155: .contains(IndexedShapefileDataStoreFactory.URLP));
156: }
157:
158: /*
159: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.getFileExtensions()'
160: */
161: public void testGetFileExtensions() {
162: List ext = Arrays.asList(factory.getFileExtensions());
163: assertTrue(ext.contains(".shp"));
164: }
165:
166: /*
167: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.canProcess(URL)'
168: */
169: public void testCanProcessURL() throws FileNotFoundException {
170: factory.canProcess(TestData
171: .url(ShapefileDataStoreTest.STATE_POP));
172: }
173:
174: /*
175: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.createDataStore(URL)'
176: */
177: public void testCreateDataStoreURL() throws IOException {
178: copyShapefiles(ShapefileDataStoreTest.STATE_POP);
179: DataStore ds = factory.createDataStore(TestData.url(this ,
180: ShapefileDataStoreTest.STATE_POP));
181: testDataStore(IndexedShapefileDataStore.TREE_QIX, true,
182: (IndexedShapefileDataStore) ds);
183: }
184:
185: /*
186: * Test method for 'org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory.getTypeName(URL)'
187: */
188: public void testGetTypeName() throws IOException {
189: factory.getTypeName(TestData
190: .url(ShapefileDataStoreTest.STATE_POP));
191: }
192: }
|