use of org.opengis.filter.identity.ResourceId in project GeoGig by boundlessgeo.
the class GeoGigFeatureStoreTest method testAddFeatures.
@Test
public void testAddFeatures() throws Exception {
FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
try {
points.addFeatures(collection);
fail("Expected UnsupportedOperationException on AUTO_COMMIT");
} catch (UnsupportedOperationException e) {
assertTrue(e.getMessage().contains("AUTO_COMMIT"));
}
Transaction tx = new DefaultTransaction();
points.setTransaction(tx);
assertSame(tx, points.getTransaction());
try {
List<FeatureId> addedFeatures = points.addFeatures(collection);
assertNotNull(addedFeatures);
assertEquals(3, addedFeatures.size());
for (FeatureId id : addedFeatures) {
assertFalse(id instanceof ResourceId);
assertNotNull(id.getFeatureVersion());
}
// assert transaction isolation
assertEquals(3, points.getFeatures().size());
assertEquals(0, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
tx.commit();
assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
}
use of org.opengis.filter.identity.ResourceId in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testFeatureIdsAreVersioned.
@Test
public void testFeatureIdsAreVersioned() throws IOException {
SimpleFeatureCollection collection = pointsSource.getFeatures(Query.ALL);
SimpleFeatureIterator features = collection.features();
Set<FeatureId> ids = Sets.newHashSet();
try {
while (features.hasNext()) {
SimpleFeature next = features.next();
FeatureId identifier = next.getIdentifier();
ids.add(identifier);
}
} finally {
features.close();
}
List<NodeRef> refs = toList(repo.command(LsTreeOp.class).setReference(pointsName).setStrategy(Strategy.FEATURES_ONLY).call());
assertEquals(3, refs.size());
Map<String, NodeRef> expected = new HashMap<String, NodeRef>();
for (NodeRef ref : refs) {
expected.put(ref.path(), ref);
}
for (FeatureId id : ids) {
assertFalse("ResourceId is a query object", id instanceof ResourceId);
assertNotNull(id.getID());
assertNotNull(id + " has no featureVersion set", id.getFeatureVersion());
NodeRef ref = expected.get(id.getID());
assertNotNull(ref);
assertEquals(ref.objectId().toString(), id.getFeatureVersion());
}
}
Aggregations