01: package org.geotools.data.jdbc;
02:
03: import java.io.IOException;
04: import java.sql.Date;
05: import java.sql.SQLException;
06: import java.sql.Statement;
07:
08: import org.geotools.data.FeatureSource;
09: import org.geotools.feature.FeatureType;
10: import org.geotools.feature.simple.SimpleTypeBuilder;
11: import org.geotools.feature.simple.SimpleTypeFactoryImpl;
12:
13: import com.vividsolutions.jts.geom.Geometry;
14:
15: public class JDBCDataStoreTest extends JDBCTestSupport {
16:
17: public void testGetNames() throws IOException {
18: String[] typeNames = dataStore.getTypeNames();
19: assertEquals(1, typeNames.length);
20: }
21:
22: public void testGetSchema() throws Exception {
23: FeatureType ft1 = dataStore.getSchema("ft1");
24: assertNotNull(ft1);
25:
26: assertNotNull(ft1.getAttributeType("geometry"));
27: assertNotNull(ft1.getAttributeType("intProperty"));
28: assertNotNull(ft1.getAttributeType("doubleProperty"));
29: assertNotNull(ft1.getAttributeType("stringProperty"));
30:
31: assertEquals(Geometry.class, ft1.getAttributeType("geometry")
32: .getType());
33: assertEquals(Integer.class, ft1.getAttributeType("intProperty")
34: .getType());
35: assertEquals(Double.class, ft1.getAttributeType(
36: "doubleProperty").getType());
37: assertEquals(String.class, ft1.getAttributeType(
38: "stringProperty").getType());
39:
40: }
41:
42: public void testCreateSchema() throws Exception {
43: SimpleTypeBuilder builder = new SimpleTypeBuilder(
44: new SimpleTypeFactoryImpl());
45: builder.setName("ft2");
46: builder.setNamespaceURI(dataStore.getNamespaceURI());
47: builder.attribute("geometry", Geometry.class);
48: builder.attribute("intProperty", Integer.class);
49: builder.attribute("dateProperty", Date.class);
50:
51: FeatureType featureType = builder.feature();
52: dataStore.createSchema(featureType);
53:
54: FeatureType ft2 = dataStore.getSchema("ft2");
55: assertFalse(ft2 == featureType);
56:
57: assertEquals(ft2, featureType);
58:
59: JDBCUtils.statement(dataStore, new JDBCRunnable() {
60: public Object run(Statement st) throws IOException,
61: SQLException {
62: try {
63: st
64: .executeQuery("SELECT * from \"geotools\".\"ft2\";");
65: } catch (SQLException e) {
66: fail("table ft2 does not exist");
67: }
68:
69: return null;
70: }
71: });
72: }
73:
74: public void testGetFeatureSource() throws Exception {
75: FeatureSource featureSource = dataStore.getFeatureSource("ft1");
76: assertNotNull(featureSource);
77: }
78:
79: }
|