use of org.geotoolkit.storage.feature.CheckCloseFeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testStartIndexIterator.
@Test
public void testStartIndexIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.skip(collection.iterator(), 0);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.skip(collection.iterator(), 1);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.skip(collection.iterator(), 2);
assertTrue(ite.next() != null);
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// check has next do not iterate
ite = FeatureStreams.skip(collection.iterator(), 1);
testIterationOnNext(ite, 2);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.skip(checkIte, 1);
while (ite.hasNext()) ite.next();
ite.close();
assertTrue(checkIte.isClosed());
}
use of org.geotoolkit.storage.feature.CheckCloseFeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testFilterIterator.
@Test
public void testFilterIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.filter(collection.iterator(), Filter.include());
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.filter(collection.iterator(), Filter.exclude());
assertEquals(0, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.filter(collection.iterator(), FF.equal(FF.literal("aaa"), FF.property("att_string")));
assertEquals(1, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.filter(collection.iterator(), FF.equal(FF.literal("aaa"), FF.property("att_string")));
assertEquals(id3, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// check has next do not iterate
ite = FeatureStreams.filter(collection.iterator(), Filter.include());
testIterationOnNext(ite, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.filter(checkIte, Filter.include());
while (ite.hasNext()) ite.next();
ite.close();
assertTrue(checkIte.isClosed());
}
use of org.geotoolkit.storage.feature.CheckCloseFeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testReprojectFeatureIterator.
@Test
public void testReprojectFeatureIterator() throws DataStoreException, FactoryException {
Query query = new Query(collection.getType().getName());
FeatureReader reader = collection.getSession().getFeatureStore().getFeatureReader(query);
final CoordinateReferenceSystem targetCRS = CommonCRS.WGS84.geographic();
FeatureReader retyped = FeatureStreams.decorate(reader, new ReprojectMapper(reader.getFeatureType(), targetCRS), new Hints());
int mask = 0;
Feature f;
while (retyped.hasNext()) {
f = retyped.next();
final Object id = f.getPropertyValue(AttributeConvention.IDENTIFIER);
assertEquals(4, f.getType().getProperties(true).size());
assertEquals(targetCRS, JTS.findCoordinateReferenceSystem((Geometry) f.getProperty("att_geom").getValue()));
if (id1.equals(id)) {
mask |= 1 << 0;
assertEquals(GF.createPoint(new Coordinate(0, 3)).toString(), f.getProperty("att_geom").getValue().toString());
} else if (id2.equals(id)) {
mask |= 1 << 1;
assertEquals(GF.createPoint(new Coordinate(0, 1)).toString(), f.getProperty("att_geom").getValue().toString());
} else if (id3.equals(id)) {
mask |= 1 << 2;
assertEquals(GF.createPoint(new Coordinate(0, 2)).toString(), f.getProperty("att_geom").getValue().toString());
}
}
if (mask != 7) {
fail("missing features in iterations");
}
// check has next do not iterate
reader = collection.getSession().getFeatureStore().getFeatureReader(query);
retyped = FeatureStreams.decorate(reader, new ReprojectMapper(reader.getFeatureType(), CommonCRS.WGS84.geographic()), new Hints());
testIterationOnNext(retyped, 3);
// check sub iterator is properly closed
reader = collection.getSession().getFeatureStore().getFeatureReader(query);
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(reader);
assertFalse(checkIte.isClosed());
retyped = FeatureStreams.decorate(checkIte, new ReprojectMapper(checkIte.getFeatureType(), CommonCRS.WGS84.geographic()), new Hints());
while (retyped.hasNext()) retyped.next();
retyped.close();
assertTrue(checkIte.isClosed());
}
use of org.geotoolkit.storage.feature.CheckCloseFeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testModifyIterator.
@Test
public void testModifyIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureType originalType = collection.getType();
Filter filter = Filter.include();
Map<String, Object> values = new HashMap<>();
values.put("att_string", "toto");
FeatureIterator ite = FeatureStreams.update(collection.iterator(), filter, values);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.update(collection.iterator(), filter, values);
while (ite.hasNext()) {
assertTrue(ite.next().getProperty("att_string").getValue().equals("toto"));
}
filter = FF.equal(FF.literal("aaa"), FF.property("att_string"));
ite = FeatureStreams.update(collection.iterator(), filter, values);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.update(collection.iterator(), filter, values);
while (ite.hasNext()) {
Feature f = ite.next();
if (f.getPropertyValue(AttributeConvention.IDENTIFIER).equals(id3)) {
assertTrue(f.getProperty("att_string").getValue().equals("toto"));
} else {
assertFalse(f.getProperty("att_string").getValue().equals("toto"));
}
}
ite = FeatureStreams.update(collection.iterator(), filter, values);
ite.next();
ite.next();
ite.next();
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// check has next do not iterate
ite = FeatureStreams.update(collection.iterator(), filter, values);
testIterationOnNext(ite, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.update(checkIte, filter, values);
while (ite.hasNext()) ite.next();
ite.close();
assertTrue(checkIte.isClosed());
}
use of org.geotoolkit.storage.feature.CheckCloseFeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testWrapReader.
@Test
public void testWrapReader() {
FeatureCollection collection = buildSimpleFeatureCollection();
// check has next do not iterate
FeatureReader reader = FeatureStreams.asReader(collection.iterator(), collection.getType());
testIterationOnNext(reader, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
reader = FeatureStreams.asReader(checkIte, collection.getType());
while (reader.hasNext()) reader.next();
reader.close();
assertTrue(checkIte.isClosed());
}
Aggregations