01: package org.geotools.data.jdbc;
02:
03: import org.geotools.data.Transaction;
04: import org.geotools.data.jdbc.collection.JDBCFeatureCollection;
05: import org.geotools.feature.Feature;
06: import org.geotools.feature.FeatureIterator;
07:
08: import com.vividsolutions.jts.geom.Coordinate;
09: import com.vividsolutions.jts.geom.Envelope;
10: import com.vividsolutions.jts.geom.Geometry;
11: import com.vividsolutions.jts.geom.GeometryFactory;
12:
13: public class JDBCFeatureCollectionTest extends JDBCTestSupport {
14:
15: JDBCFeatureCollection collection;
16:
17: protected void setUp() throws Exception {
18: super .setUp();
19:
20: JDBCFeatureSource source = (JDBCFeatureSource) dataStore
21: .getFeatureSource("ft1");
22: JDBCState state = (JDBCState) source.getEntry().getState(
23: Transaction.AUTO_COMMIT);
24:
25: collection = new JDBCFeatureCollection(source, state);
26: }
27:
28: public void testBounds() throws Exception {
29: Envelope e = collection.getBounds();
30: assertNotNull(e);
31:
32: assertEquals(0d, e.getMinX(), 0.1);
33: assertEquals(0d, e.getMinY(), 0.1);
34: assertEquals(2d, e.getMaxX(), 0.1);
35: assertEquals(2d, e.getMaxY(), 0.1);
36: }
37:
38: public void testSize() throws Exception {
39:
40: int size = collection.size();
41: assertEquals(3, size);
42: }
43:
44: public void testFeatures() throws Exception {
45: FeatureIterator features = collection.features();
46:
47: for (int i = 0; i < 3; i++) {
48: assertTrue(features.hasNext());
49:
50: Feature feature = (Feature) features.next();
51: assertNotNull(feature);
52:
53: assertEquals(i + "", feature.getID());
54: assertTrue(new GeometryFactory().createPoint(
55: new Coordinate(i, i)).equals(
56: (Geometry) feature.getAttribute("geometry")));
57: assertEquals(new Integer(i), feature
58: .getAttribute("intProperty"));
59:
60: assertNotNull(feature.getDefaultGeometry());
61: assertEquals(feature.getAttribute("geometry"), feature
62: .getDefaultGeometry());
63: }
64:
65: assertFalse(features.hasNext());
66: }
67: }
|