001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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.mif;
017:
018: import junit.framework.TestCase;
019: import junit.framework.TestSuite;
020: import org.geotools.data.DataStore;
021: import org.geotools.data.DataStoreFactorySpi.Param;
022: import org.geotools.data.DataStoreFinder;
023: import org.geotools.feature.FeatureType;
024: import java.io.IOException;
025: import java.net.URI;
026:
027: /**
028: * TestCase class for MIFDataStoreFactory
029: *
030: * @author Luca S. Percich, AMA-MI
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/mif/src/test/java/org/geotools/data/mif/MIFDataStoreFactoryTest.java $
032: */
033: public class MIFDataStoreFactoryTest extends TestCase {
034: private MIFDataStoreFactory dsFactory = null;
035: private URI uri = null;
036:
037: /**
038: */
039: public static void main(java.lang.String[] args) throws Exception {
040: junit.textui.TestRunner.run(new TestSuite(
041: MIFDataStoreFactoryTest.class));
042: }
043:
044: /*
045: * @see TestCase#setUp()
046: */
047: protected void setUp() throws Exception {
048: super .setUp();
049: dsFactory = new MIFDataStoreFactory();
050: uri = null;
051: }
052:
053: /*
054: * @see TestCase#tearDown()
055: */
056: protected void tearDown() throws Exception {
057: dsFactory = null;
058: super .tearDown();
059: }
060:
061: /**
062: */
063: public void testGetDisplayName() {
064: assertEquals("MIFDataStore", dsFactory.getDisplayName());
065: }
066:
067: /**
068: * Creates a MIFDataStore using DataStoreFinder
069: */
070: public void testDataStoreFinder() {
071: DataStore ds = null;
072:
073: try {
074: ds = DataStoreFinder.getDataStore(MIFTestUtils.getParams(
075: "mif", MIFTestUtils.fileName(""), uri));
076: } catch (IOException e) {
077: fail(e.getMessage());
078: }
079:
080: assertNotNull("Can't create datastore using DSFinder", ds);
081: assertEquals("Bad class: " + ds.getClass(), true,
082: ds.getClass() == MIFDataStore.class);
083: }
084:
085: /**
086: */
087: public void testCreateDataStore() {
088: DataStore ds = null;
089:
090: try {
091: String strURI = "root-mifdatastore";
092: uri = new URI(strURI);
093: ds = dsFactory.createDataStore(MIFTestUtils.getParams(
094: "mif", MIFTestUtils.fileName(""), uri));
095:
096: FeatureType ft = ds.getSchema("grafo");
097: assertEquals("Bad URI", new URI(strURI), ft.getNamespace());
098: } catch (Exception e) {
099: fail(e.getMessage());
100: }
101:
102: assertNotNull(ds);
103: assertEquals(true, ds.getClass() == MIFDataStore.class);
104: }
105:
106: /**
107: */
108: public void testGetDescription() {
109: assertEquals("MapInfo MIF/MID format datastore", dsFactory
110: .getDescription());
111: }
112:
113: /**
114: * Test the canProcess() method with different sets of (possibly wrong)
115: * parameters
116: */
117: public void testCanProcessPath() {
118: // Opens the test-data directory
119: assertEquals(true, dsFactory.canProcess(MIFTestUtils.getParams(
120: "mif", MIFTestUtils.fileName(""), uri)));
121: }
122:
123: /**
124: */
125: public void testCanProcessWrongDBType() {
126: // fails because dbtype != "mif"
127: assertEquals(false, dsFactory
128: .canProcess(MIFTestUtils.getParams("miffooobar",
129: MIFTestUtils.fileName(""), uri)));
130: }
131:
132: /**
133: */
134: public void testCanProcessMIF() {
135: // Opens a single mif file; works with or without extension, and regardless the extension's case.
136: assertEquals(true, dsFactory.canProcess(MIFTestUtils.getParams(
137: "mif", MIFTestUtils.fileName("grafo"), uri)));
138: assertEquals(true, dsFactory.canProcess(MIFTestUtils.getParams(
139: "mif", MIFTestUtils.fileName("grafo.MIF"), uri)));
140: assertEquals(true, dsFactory.canProcess(MIFTestUtils.getParams(
141: "mif", MIFTestUtils.fileName("grafo.mif"), uri)));
142: }
143:
144: /**
145: */
146: public void testCanProcessWrongPath() {
147: // Fails because an extension other than ".mif" was specified
148: assertEquals(false, dsFactory.canProcess(MIFTestUtils
149: .getParams("mif", MIFTestUtils.fileName("grafo.zip"),
150: uri)));
151:
152: // fails because the path is non-existent
153: assertEquals(false, dsFactory.canProcess(MIFTestUtils
154: .getParams("mif", MIFTestUtils
155: .fileName("some_non_existent_file"), uri)));
156: }
157:
158: /**
159: */
160: public void testIsAvailable() {
161: assertEquals(true, dsFactory.isAvailable());
162: }
163:
164: /**
165: */
166: public void testGetParametersInfo() {
167: Param[] pars = dsFactory.getParametersInfo();
168: assertNotNull(pars);
169: assertEquals(pars[3].key, MIFDataStore.PARAM_FIELDCASE);
170: assertEquals(pars.length, 15);
171: }
172:
173: /**
174: * DOCUMENT ME!
175: */
176: public void testGetImplementationHints() {
177: assertNotNull(dsFactory.getImplementationHints());
178: }
179: }
|