Search in sources :

Example 1 with QueryCapabilities

use of org.geotools.data.QueryCapabilities in project GeoGig by boundlessgeo.

the class WorkingTreeTest method testInsertPagingFeatureSource.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInsertPagingFeatureSource() throws Exception {
    assertEquals(2, super.getGeogig().getPlatform().availableProcessors());
    final List<SimpleFeature> features = ImmutableList.of((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3);
    MemoryDataStore store = new MemoryDataStore();
    store.addFeatures(features);
    final QueryCapabilities caps = mock(QueryCapabilities.class);
    when(caps.isOffsetSupported()).thenReturn(true);
    FeatureSource source = new ForwardingFeatureSource(store.getFeatureSource(pointsName)) {

        @Override
        public QueryCapabilities getQueryCapabilities() {
            return caps;
        }

        @Override
        public FeatureCollection getFeatures(Query query) throws IOException {
            Integer startIndex = query.getStartIndex();
            if (startIndex == null) {
                return super.getFeatures();
            }
            int toIndex = (int) Math.min((long) startIndex + query.getMaxFeatures(), features.size());
            List<SimpleFeature> result = features.subList(startIndex, toIndex);
            return DataUtilities.collection(result);
        }
    };
    assertTrue(source.getQueryCapabilities().isOffsetSupported());
    String treePath = "target_typename";
    workTree.insert(treePath, source, Query.ALL, LISTENER);
    assertEquals(3, workTree.countUnstaged(treePath).featureCount());
}
Also used : ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) FeatureSource(org.geotools.data.FeatureSource) QueryCapabilities(org.geotools.data.QueryCapabilities) Query(org.geotools.data.Query) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 2 with QueryCapabilities

use of org.geotools.data.QueryCapabilities in project GeoGig by boundlessgeo.

the class WorkingTreeTest method testInsertNonPagingFeatureSource.

@Test
public void testInsertNonPagingFeatureSource() throws Exception {
    assertEquals(2, super.getGeogig().getPlatform().availableProcessors());
    final List<SimpleFeature> features = ImmutableList.of((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3);
    MemoryDataStore store = new MemoryDataStore();
    store.addFeatures(features);
    final QueryCapabilities caps = mock(QueryCapabilities.class);
    when(caps.isOffsetSupported()).thenReturn(true);
    @SuppressWarnings("rawtypes") FeatureSource source = store.getFeatureSource(pointsName);
    assertFalse(source.getQueryCapabilities().isOffsetSupported());
    String treePath = "target_typename";
    workTree.insert(treePath, source, Query.ALL, LISTENER);
    assertEquals(3, workTree.countUnstaged(treePath).featureCount());
}
Also used : ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) FeatureSource(org.geotools.data.FeatureSource) QueryCapabilities(org.geotools.data.QueryCapabilities) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Aggregations

FeatureSource (org.geotools.data.FeatureSource)2 QueryCapabilities (org.geotools.data.QueryCapabilities)2 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)2 Test (org.junit.Test)2 ForwardingFeatureSource (org.locationtech.geogig.api.data.ForwardingFeatureSource)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 Query (org.geotools.data.Query)1