001: /*
002: * Geotools2 - 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: */
017: package org.geotools.arcsde;
018:
019: import java.io.IOException;
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import junit.framework.TestCase;
025:
026: import org.geotools.arcsde.data.ArcSDEDataStore;
027: import org.geotools.arcsde.data.InProcessViewSupportTestData;
028: import org.geotools.arcsde.data.TestData;
029: import org.geotools.arcsde.pool.ArcSDEConnectionConfig;
030: import org.geotools.arcsde.pool.ArcSDEPooledConnection;
031: import org.geotools.data.DataStore;
032: import org.geotools.data.DataStoreFinder;
033: import org.geotools.feature.FeatureType;
034:
035: import com.esri.sde.sdk.client.SeException;
036:
037: /**
038: * Test suite for {@link ArcSDEDataStoreFactory}
039: *
040: * @author Gabriel Roldan, Axios Engineering
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/ArcSDEDataStoreFactoryTest.java $
042: * @version $Id: ArcSDEDataStoreFactoryTest.java 29135 2008-02-07 19:49:09Z desruisseaux $
043: * @since 2.4.x
044: */
045: public class ArcSDEDataStoreFactoryTest extends TestCase {
046:
047: /**
048: * A datastore factory set up with the {@link #workingParams}
049: */
050: private ArcSDEDataStoreFactory dsFactory;
051:
052: /**
053: * A set of datastore parameters that are meant to work
054: */
055: private Map workingParams;
056:
057: /**
058: * Aset of datastore parameters that though valid (contains all the required
059: * parameters) point to a non available server
060: */
061: private Map nonWorkingParams;
062:
063: /**
064: * A set of datastore parameters that does not conform to the parameters
065: * required by the ArcSDE plugin
066: */
067: private Map illegalParams;
068:
069: private TestData testData;
070:
071: /**
072: * @param name
073: */
074: public ArcSDEDataStoreFactoryTest(String name) {
075: super (name);
076: }
077:
078: /*
079: * (non-Javadoc)
080: *
081: * @see junit.framework.TestCase#setUp()
082: */
083: protected void setUp() throws Exception {
084: super .setUp();
085: this .testData = new TestData();
086: testData.setUp();
087:
088: workingParams = testData.getConProps();
089:
090: nonWorkingParams = new HashMap(workingParams);
091: nonWorkingParams.put(ArcSDEConnectionConfig.SERVER_NAME_PARAM,
092: "non-existent-server");
093:
094: illegalParams = new HashMap(workingParams);
095: illegalParams.put(ArcSDEConnectionConfig.DBTYPE_PARAM,
096: "non-existent-db-type");
097:
098: dsFactory = new ArcSDEDataStoreFactory();
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see junit.framework.TestCase#tearDown()
105: */
106: protected void tearDown() throws Exception {
107: super .tearDown();
108: this .testData.tearDown(true, true);
109: }
110:
111: public void testLookUp() throws IOException {
112: DataStore dataStore;
113:
114: dataStore = DataStoreFinder.getDataStore(nonWorkingParams);
115: assertNull(dataStore);
116:
117: dataStore = DataStoreFinder.getDataStore(workingParams);
118: assertNotNull(dataStore);
119: assertTrue(dataStore instanceof ArcSDEDataStore);
120: }
121:
122: /**
123: * Test method for
124: * {@link org.geotools.arcsde.ArcSDEDataStoreFactory#createNewDataStore(java.util.Map)}.
125: */
126: public void testCreateNewDataStore() {
127: try {
128: dsFactory.createNewDataStore(Collections.EMPTY_MAP);
129: fail("Expected UOE as we can't create new datastores");
130: } catch (UnsupportedOperationException e) {
131: assertTrue(true);
132: }
133: }
134:
135: /**
136: * Test method for
137: * {@link org.geotools.arcsde.ArcSDEDataStoreFactory#canProcess(java.util.Map)}.
138: */
139: public void testCanProcess() {
140: assertFalse(dsFactory.canProcess(illegalParams));
141: assertTrue(dsFactory.canProcess(nonWorkingParams));
142: assertTrue(dsFactory.canProcess(workingParams));
143: }
144:
145: /**
146: * Test method for
147: * {@link org.geotools.arcsde.ArcSDEDataStoreFactory#createDataStore(java.util.Map)}.
148: *
149: * @throws IOException
150: */
151: public void testCreateDataStore() throws IOException {
152: try {
153: dsFactory.createDataStore(nonWorkingParams);
154: } catch (IOException e) {
155: assertTrue(true);
156: }
157:
158: DataStore store = dsFactory.createDataStore(workingParams);
159: assertNotNull(store);
160: assertTrue(store instanceof ArcSDEDataStore);
161: }
162:
163: /**
164: * Test method for
165: * {@link org.geotools.arcsde.ArcSDEDataStoreFactory#createDataStore(java.util.Map)}.
166: *
167: * @throws IOException
168: * @throws SeException
169: */
170: public void testCreateDataStoreWithInProcessViews()
171: throws IOException, SeException {
172: ArcSDEPooledConnection conn = testData.getConnectionPool()
173: .getConnection();
174: try {
175: InProcessViewSupportTestData.setUp(conn);
176: } finally {
177: conn.close();
178: }
179:
180: Map workingParamsWithSqlView = new HashMap(workingParams);
181: workingParamsWithSqlView
182: .putAll(InProcessViewSupportTestData.registerViewParams);
183:
184: DataStore store = dsFactory
185: .createDataStore(workingParamsWithSqlView);
186: assertNotNull(store);
187:
188: FeatureType viewType = store
189: .getSchema(InProcessViewSupportTestData.typeName);
190: assertNotNull(viewType);
191: assertEquals(InProcessViewSupportTestData.typeName, viewType
192: .getTypeName());
193: }
194:
195: }
|