use of org.opengis.feature.simple.SimpleFeature in project GeoGig by boundlessgeo.
the class GeoGigFeatureStoreTest method testTransactionCommitMessage.
@Test
public void testTransactionCommitMessage() throws Exception {
FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
DefaultTransaction tx = new DefaultTransaction();
points.setTransaction(tx);
assertSame(tx, points.getTransaction());
try {
points.addFeatures(collection);
tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "John Doe");
tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message");
tx.commit();
assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
List<RevCommit> commits = toList(geogig.command(LogOp.class).call());
assertFalse(commits.isEmpty());
assertTrue(commits.get(0).getAuthor().getName().isPresent());
assertEquals("John Doe", commits.get(0).getAuthor().getName().get());
assertEquals("test message", commits.get(0).getMessage());
}
use of org.opengis.feature.simple.SimpleFeature in project GeoGig by boundlessgeo.
the class GeoGigFeatureStoreTest method testModifyFeatures.
@Test
public void testModifyFeatures() throws Exception {
// add features circumventing FeatureStore.addFeatures to keep the test
// independent of the addFeatures functionality
insertAndAdd(lines1, lines2, lines3, points1, points2, points3);
geogig.command(CommitOp.class).call();
Id filter = ff.id(Collections.singleton(ff.featureId(idP1)));
Transaction tx = new DefaultTransaction();
points.setTransaction(tx);
try {
// initial value
SimpleFeature initial = points.getFeatures(filter).features().next();
assertEquals("StringProp1_1", initial.getAttribute("sp"));
// modify
points.modifyFeatures("sp", "modified", filter);
// modified value before commit
SimpleFeature modified = points.getFeatures(filter).features().next();
assertEquals("modified", modified.getAttribute("sp"));
// unmodified value before commit on another store instance (tx isolation)
assertEquals("StringProp1_1", dataStore.getFeatureSource(pointsTypeName).getFeatures(filter).features().next().getAttribute("sp"));
tx.commit();
// modified value after commit on another store instance
assertEquals("modified", dataStore.getFeatureSource(pointsTypeName).getFeatures(filter).features().next().getAttribute("sp"));
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
points.setTransaction(Transaction.AUTO_COMMIT);
SimpleFeature modified = points.getFeatures(filter).features().next();
assertEquals("modified", modified.getAttribute("sp"));
}
use of org.opengis.feature.simple.SimpleFeature 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.feature.simple.SimpleFeature in project GeoGig by boundlessgeo.
the class TestHelper method createFactoryWithGetFeatureSourceException.
public static AbstractDataStoreFactory createFactoryWithGetFeatureSourceException() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setCRS(CRS.decode("EPSG:4326"));
builder.add("geom", Point.class);
builder.add("label", String.class);
builder.setName("table1");
SimpleFeatureType type = builder.buildFeatureType();
SimpleFeatureTypeBuilder builder2 = new SimpleFeatureTypeBuilder();
builder2.setCRS(CRS.decode("EPSG:4326"));
builder2.add("geom", Point.class);
builder2.add("name", String.class);
builder2.setName("table2");
SimpleFeatureType type2 = builder2.buildFeatureType();
GeometryFactory gf = new GeometryFactory();
SimpleFeature f1 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 8)), "feature1" }, null);
SimpleFeature f2 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 4)), "feature2" }, null);
SimpleFeature f3 = SimpleFeatureBuilder.build(type2, new Object[] { gf.createPoint(new Coordinate(3, 2)), "feature3" }, null);
MemoryDataStore testDataStore = new MemoryDataStore();
testDataStore.addFeature(f1);
testDataStore.addFeature(f2);
testDataStore.addFeature(f3);
MemoryDataStore spyDataStore = spy(testDataStore);
when(spyDataStore.getFeatureSource("table1")).thenThrow(new IOException("Exception"));
final AbstractDataStoreFactory factory = mock(AbstractDataStoreFactory.class);
when(factory.createDataStore(anyMapOf(String.class, Serializable.class))).thenReturn(spyDataStore);
when(factory.canProcess(anyMapOf(String.class, Serializable.class))).thenReturn(true);
return factory;
}
use of org.opengis.feature.simple.SimpleFeature 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