use of org.geotoolkit.storage.feature.CheckCloseFeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testSortByIterator.
@Test
public void testSortByIterator() {
SortProperty[] sorts = new SortProperty[] { FF.sort(FF.property("att_string"), SortOrder.ASCENDING) };
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.sort(collection.iterator(), sorts);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collection.iterator(), sorts);
assertEquals(id3, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(id1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(id2, 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.sort(collection.iterator(), sorts);
testIterationOnNext(ite, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.sort(checkIte, sorts);
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 testWrapIterator.
@Test
public void testWrapIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
// check has next do not iterate
FeatureIterator ite = FeatureStreams.asIterator(collection.iterator());
testIterationOnNext(ite, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.asIterator(checkIte);
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 testMaxIterator.
@Test
public void testMaxIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.limit(collection.iterator(), 10);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.limit(collection.iterator(), 2);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.limit(collection.iterator(), 1);
assertEquals(id1, 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.limit(collection.iterator(), 10);
testIterationOnNext(ite, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.limit(checkIte, 10);
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 testSortByIteratorOnComplex.
@Test
public void testSortByIteratorOnComplex() {
FeatureCollection collectionComplex = buildComplexFeatureCollection();
FeatureCollection collection = buildSimpleFeatureCollection();
// test string sort -----------------------------------------------------
SortProperty[] sorts = new SortProperty[] { FF.sort(FF.property("att_string"), SortOrder.DESCENDING) };
FeatureIterator ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(COMPLEX_ID_1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// test string sort -----------------------------------------------------
sorts = new SortProperty[] { FF.sort(FF.property("att_double"), SortOrder.DESCENDING) };
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(COMPLEX_ID_1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// test double sort -----------------------------------------------------
sorts = new SortProperty[] { FF.sort(FF.property("att_double"), SortOrder.ASCENDING) };
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(COMPLEX_ID_1, 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.sort(collectionComplex.iterator(), sorts);
testIterationOnNext(ite, 2);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.sort(checkIte, sorts);
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 testRetypeFeatureIterator.
@Test
public void testRetypeFeatureIterator() throws DataStoreException {
final FeatureCollection collection = buildSimpleFeatureCollection();
final ViewMapper reducedType = new ViewMapper(collection.getType(), AttributeConvention.IDENTIFIER, "att_double");
final Query query = new Query(collection.getType().getName());
FeatureReader reader = collection.getSession().getFeatureStore().getFeatureReader(query);
FeatureReader retyped = FeatureStreams.decorate(reader, reducedType, null);
assertEquals(reducedType.getMappedType(), retyped.getFeatureType());
int mask = 0;
Feature f;
while (retyped.hasNext()) {
f = retyped.next();
final Object id = f.getPropertyValue(AttributeConvention.IDENTIFIER);
assertEquals(2, f.getType().getProperties(true).size());
if (id1.equals(id)) {
mask |= 1 << 0;
assertEquals(3d, (Double) f.getProperty("att_double").getValue(), DELTA);
} else if (id2.equals(id)) {
mask |= 1 << 1;
assertEquals(1d, (Double) f.getProperty("att_double").getValue(), DELTA);
} else if (id3.equals(id)) {
mask |= 1 << 2;
assertEquals(2d, (Double) f.getProperty("att_double").getValue(), DELTA);
}
}
assertEquals("missing features in iterations", 7, mask);
// check has next do not iterate
reader = collection.getSession().getFeatureStore().getFeatureReader(query);
retyped = FeatureStreams.decorate(reader, reducedType, null);
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, reducedType, null);
while (retyped.hasNext()) retyped.next();
retyped.close();
assertTrue(checkIte.isClosed());
}
Aggregations