01: package org.geotools.data.jdbc;
02:
03: import org.geotools.feature.FeatureType;
04: import org.opengis.filter.Filter;
05: import org.opengis.filter.FilterFactory;
06:
07: /**
08: * Test case for {@link SQLBuilder}.
09: *
10: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
11: *
12: */
13: public class SQLBuilderTest extends JDBCTestSupport {
14:
15: SQLBuilder builder;
16: FeatureType source;
17: Filter filter;
18:
19: protected void setUp() throws Exception {
20: super .setUp();
21:
22: source = dataStore.getSchema("ft1");
23: builder = new SQLBuilder(dataStore);
24:
25: FilterFactory ff = dataStore.getFilterFactory();
26: filter = ff.equal(ff.property("intProperty"), ff.literal(1),
27: false);
28: }
29:
30: public void testCreateTable() throws Exception {
31: String sql = builder.createTable(source);
32:
33: assertEquals(
34: "CREATE TABLE \"geotools\".\"ft1\" ( \"geometry\" OTHER, \"intProperty\" INTEGER, \"doubleProperty\" DOUBLE, \"stringProperty\" VARCHAR_IGNORECASE )",
35: sql);
36: }
37:
38: public void testBounds() throws Exception {
39: String sql = builder.bounds(source);
40:
41: assertEquals(
42: "SELECT envelope(\"geometry\") FROM \"geotools\".\"ft1\"",
43: sql);
44: }
45:
46: public void testBoundsWithFilter() {
47: String sql = builder.bounds(source, filter);
48:
49: assertEquals(
50: "SELECT envelope(\"geometry\") FROM \"geotools\".\"ft1\""
51: + " WHERE ( \"intProperty\" ) = ( 1 )", sql);
52: }
53:
54: public void testCount() throws Exception {
55: String sql = builder.count(source);
56:
57: assertEquals("SELECT count(*) FROM \"geotools\".\"ft1\"", sql);
58: }
59:
60: public void testCountWithFilter() throws Exception {
61: String sql = builder.count(source, filter);
62:
63: assertEquals("SELECT count(*) FROM \"geotools\".\"ft1\""
64: + " WHERE ( \"intProperty\" ) = ( 1 )", sql);
65: }
66:
67: public void testSelect() throws Exception {
68: String sql = builder.select(source, (Filter) null);
69:
70: System.out.println(sql);
71: assertEquals(
72: "SELECT \"id\", \"geometry\", \"intProperty\", \"doubleProperty\", "
73: + "\"stringProperty\" FROM \"geotools\".\"ft1\"",
74: sql);
75: }
76: }
|