001: /*
002: * Geotools2 - 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: */
017: package org.geotools.data.complex;
018:
019: import java.io.IOException;
020: import java.net.URL;
021: import java.util.Collections;
022: import java.util.HashMap;
023: import java.util.Map;
024: import java.util.logging.Level;
025:
026: import junit.framework.TestCase;
027:
028: import org.geotools.data.DataAccess;
029: import org.geotools.data.DataAccessFinder;
030: import org.geotools.data.DataStoreFactorySpi;
031: import org.geotools.data.feature.FeatureAccess;
032: import org.geotools.data.feature.FeatureSource2;
033: import org.geotools.feature.iso.Types;
034: import org.geotools.util.logging.Logging;
035: import org.opengis.feature.type.Name;
036:
037: /**
038: *
039: * @author Gabriel Roldan, Axios Engineering
040: * @version $Id: ComplexDataStoreFactoryTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/community-schemas/community-schema-ds/src/test/java/org/geotools/data/complex/ComplexDataStoreFactoryTest.java $
042: * @since 2.4
043: */
044: public class ComplexDataStoreFactoryTest extends TestCase {
045:
046: ComplexDataStoreFactory factory;
047:
048: Map params;
049:
050: private static final String NSURI = "http://online.socialchange.net.au";
051:
052: static final Name mappedTypeName = Types.typeName(NSURI,
053: "RoadSegment");
054:
055: protected void setUp() throws Exception {
056: super .setUp();
057: factory = new ComplexDataStoreFactory();
058: params = new HashMap();
059: params.put("dbtype", "complex");
060: URL resource = getClass().getResource(
061: "/test-data/roadsegments.xml");
062: if (resource == null) {
063: fail("Can't find resouce /test-data/roadsegments.xml");
064: }
065: params.put("url", resource);
066: }
067:
068: protected void tearDown() throws Exception {
069: super .tearDown();
070: factory = null;
071: params = null;
072: }
073:
074: /**
075: * Test method for
076: * 'org.geotools.data.complex.ComplexDataStoreFactory.createDataStore(Map)'
077: */
078: public void testCreateDataStorePreconditions() {
079: Map badParams = new HashMap();
080: try {
081: factory.createDataStore(badParams);
082: fail("allowed bad params");
083: } catch (IOException e) {
084: // OK
085: }
086: badParams.put("dbtype", "complex");
087: try {
088: factory.createDataStore(badParams);
089: fail("allowed bad params");
090: } catch (IOException e) {
091: // OK
092: }
093: badParams.put("url", "file://_inexistentConfigFile123456.xml");
094: try {
095: factory.createDataStore(badParams);
096: fail("allowed bad params");
097: } catch (IOException e) {
098: // OK
099: }
100: }
101:
102: /*
103: * public void test2()throws Exception{ String configFile =
104: * "file:/home/gabriel/workspaces/complex_sco/GEOS/conf/data/featureTypes/complexWQ_Plus/wq_plus_mappings.xml";
105: * Map params = new HashMap(); params.put("dbtype", "complex");
106: * params.put("config", configFile);
107: *
108: * DataStore ds = DataStoreFinder.getDataStore(params); assertNotNull(ds);
109: * assertTrue(ds instanceof ComplexDataStore);
110: *
111: * org.opengis.feature.type.FeatureType ft = ds.getSchema("wq_plus");
112: * assertNotNull(ft);
113: *
114: * FeatureSource fs = ds.getFeatureSource("wq_plus"); assertNotNull(fs);
115: * FeatureIterator fi = fs.getFeatures().features(); while(fi.hasNext()){
116: * Feature f = fi.next(); assertNotNull(f); Object result = XPath.get(f,
117: * "measurement/result"); assertNotNull(result); } fi.close();
118: *
119: * Envelope bounds = fs.getBounds(); assertNotNull(bounds); }
120: */
121:
122: /**
123: *
124: * @throws IOException
125: */
126: public void testCreateDataStore() throws IOException {
127: FeatureAccess ds = (FeatureAccess) factory
128: .createDataStore(params);
129: assertNotNull(ds);
130: FeatureSource2 mappedSource = (FeatureSource2) ds
131: .access(mappedTypeName);
132: assertNotNull(mappedSource);
133: assertSame(ds, mappedSource.getDataStore());
134: }
135:
136: /**
137: *
138: * @throws IOException
139: */
140: public void testFactoryLookup() throws IOException {
141: DataAccess ds = DataAccessFinder.createAccess(params);
142: assertNotNull(ds);
143: assertTrue(ds instanceof ComplexDataStore);
144:
145: FeatureSource2 mappedSource = (FeatureSource2) ds
146: .access(mappedTypeName);
147: assertNotNull(mappedSource);
148: }
149:
150: /**
151: * Test method for
152: * 'org.geotools.data.complex.ComplexDataStoreFactory.createNewDataStore(Map)'
153: */
154: public void testCreateNewDataStore() throws IOException {
155: try {
156: factory.createNewDataStore(Collections.EMPTY_MAP);
157: fail("unsupported?");
158: } catch (UnsupportedOperationException e) {
159: // OK
160: }
161: }
162:
163: /**
164: * Test method for
165: * 'org.geotools.data.complex.ComplexDataStoreFactory.getParametersInfo()'
166: */
167: public void testGetParametersInfo() {
168: DataStoreFactorySpi.Param[] params = factory
169: .getParametersInfo();
170: assertNotNull(params);
171: assertEquals(2, params.length);
172: assertEquals(String.class, params[0].type);
173: assertEquals(URL.class, params[1].type);
174: }
175:
176: /**
177: *
178: * Test method for
179: * 'org.geotools.data.complex.ComplexDataStoreFactory.canProcess(Map)'
180: */
181: public void testCanProcess() {
182: Map params = new HashMap();
183: assertFalse(factory.canProcess(params));
184: params.put("dbtype", "arcsde");
185: params.put("url", "http://somesite.net/config.xml");
186: assertFalse(factory.canProcess(params));
187: params.remove("url");
188: params.put("dbtype", "complex");
189: assertFalse(factory.canProcess(params));
190:
191: params.put("url", "http://somesite.net/config.xml");
192: assertTrue(factory.canProcess(params));
193: }
194:
195: /**
196: *
197: * Test method for
198: * 'org.geotools.data.complex.ComplexDataStoreFactory.isAvailable()'
199: */
200: public void testIsAvailable() {
201: assertTrue(factory.isAvailable());
202: }
203:
204: /**
205: *
206: * Test method for
207: * 'org.geotools.data.complex.ComplexDataStoreFactory.getImplementationHints()'
208: */
209: public void testGetImplementationHints() {
210: assertNotNull(factory.getImplementationHints());
211: assertEquals(0, factory.getImplementationHints().size());
212: }
213:
214: }
|