public void testGetFeatureTypes() throws IOException { String[] names = data.getTypeNames(); assertEquals(2, names.length); assertTrue(contains(names, "road")); assertTrue(contains(names, "river")); }
@Test public void testExportFromTreeWithSeveralFeatureTypesUsingNonexistantTypeId() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; try { geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .setFilterFeatureTypeId(RevObjectTestSupport.hashString("fake")).call(); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage(), e.getMessage().contains("filter feature type")); } }
@Test public void testExportFromTreeWithSeveralFeatureTypesUsingNonexistantTypeId() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; try { geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .setFilterFeatureTypeId(RevObjectTestSupport.hashString("fake")).call(); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage(), e.getMessage().contains("filter feature type")); } }
@Test public void testExportFromWrongFeatureType() throws Exception { MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; try { geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call(); fail(); } catch (IllegalArgumentException e) { assertTrue(true); } }
@Test public void testExportFromWrongFeatureType() throws Exception { MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; try { geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call(); fail(); } catch (IllegalArgumentException e) { assertTrue(true); } }
@Test public void testExportFromTreeWithSeveralFeatureTypes() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; try { geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call(); fail(); } catch (GeoToolsOpException e) { assertEquals(GeoToolsOpException.StatusCode.MIXED_FEATURE_TYPES, e.statusCode); } }
@Test public void testExportFromTreeWithSeveralFeatureTypes() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; try { geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call(); fail(); } catch (GeoToolsOpException e) { assertEquals(GeoToolsOpException.StatusCode.MIXED_FEATURE_TYPES, e.statusCode); } }
@Test public void testExportFromWorkingTree() throws Exception { Feature[] points = new Feature[] { points1, points2, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), points.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, points)); }
@Test public void testExportFromWorkingTree() throws Exception { Feature[] points = new Feature[] { points1, points2, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), points.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, points)); }
@Test public void testExportWithAlterUsingDefaultFeatureType() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .setAlter(true).call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), points.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, points)); }
@Test public void testExportWithAlterUsingDefaultFeatureType() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .setAlter(true).call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), points.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, points)); }
@Test public void testExportWithBBOXFilter() throws Exception { Feature[] points = new Feature[] { points1, points2, points3 }; for (Feature feature : points) { insert(feature); } geogig.command(AddOp.class).call(); geogig.command(CommitOp.class).setAll(true).call(); MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; ReferencedEnvelope bbox = (ReferencedEnvelope) points1.getBounds(); geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath("HEAD:" + pointsName) .setBBoxFilter(bbox).call(); featureSource = dataStore.getFeatureSource(typeName); assertEquals(1, featureSource.getCount(Query.ALL)); }
@Test public void testExportFromTreeWithSeveralFeatureTypesUsingDefaultFeatureType() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } Feature[] expectedPoints = new Feature[] { points2, points3 }; MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .exportDefaultFeatureType().call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), expectedPoints.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, expectedPoints)); }
@Test public void testExportWithAlterUsingFeatureTypeId() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } MemoryDataStore dataStore = new MemoryDataStore(modifiedPointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .setAlter(true).setFilterFeatureTypeId( RevFeatureType.builder().type(modifiedPointsType).build().getId()) .call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), points.length); SimpleFeatureIterator features = featureCollection.features(); while (features.hasNext()) { List<Object> attributes = features.next().getAttributes(); assertEquals(4, attributes.size()); } }
@Test public void testExportFromTreeWithSeveralFeatureTypesUsingDefaultFeatureType() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } Feature[] expectedPoints = new Feature[] { points2, points3 }; MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .exportDefaultFeatureType().call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), expectedPoints.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, expectedPoints)); }
@Test public void testExportWithBBOXFilter() throws Exception { Feature[] points = new Feature[] { points1, points2, points3 }; for (Feature feature : points) { insert(feature); } geogig.command(AddOp.class).call(); geogig.command(CommitOp.class).setAll(true).call(); MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; ReferencedEnvelope bbox = (ReferencedEnvelope) points1.getBounds(); geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath("HEAD:" + pointsName) .setBBoxFilter(bbox).call(); featureSource = dataStore.getFeatureSource(typeName); assertEquals(1, featureSource.getCount(Query.ALL)); }
@Test public void testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } Feature[] expectedPoints = new Feature[] { points1B }; MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .setFilterFeatureTypeId(RevFeatureTypeBuilder.build(modifiedPointsType).getId()) .call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(expectedPoints.length, featureCollection.size()); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, expectedPoints)); }
@Test public void testExportFromHEAD() throws Exception { Feature[] points = new Feature[] { points1, points2, points3 }; for (Feature feature : points) { insert(feature); } geogig.command(AddOp.class).call(); geogig.command(CommitOp.class).setAll(true).call(); MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath("HEAD:" + pointsName) .call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), points.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, points)); }
@Test public void testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId() throws Exception { Feature[] points = new Feature[] { points2, points1B, points3 }; for (Feature feature : points) { insert(feature); } Feature[] expectedPoints = new Feature[] { points1B }; MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName) .setFilterFeatureTypeId( RevFeatureType.builder().type(modifiedPointsType).build().getId()) .call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(expectedPoints.length, featureCollection.size()); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, expectedPoints)); }
@Test public void testExportFromHEAD() throws Exception { Feature[] points = new Feature[] { points1, points2, points3 }; for (Feature feature : points) { insert(feature); } geogig.command(AddOp.class).call(); geogig.command(CommitOp.class).setAll(true).call(); MemoryDataStore dataStore = new MemoryDataStore(pointsType); final String typeName = dataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath("HEAD:" + pointsName) .call(); featureSource = dataStore.getFeatureSource(typeName); featureStore = (SimpleFeatureStore) featureSource; SimpleFeatureCollection featureCollection = featureStore.getFeatures(); assertEquals(featureCollection.size(), points.length); SimpleFeatureIterator features = featureCollection.features(); assertTrue(collectionsAreEqual(features, points)); }