use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class RevFeatureTypeSerializationTest method testSerialization.
@Test
public void testSerialization() throws Exception {
RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
ObjectWriter<RevFeatureType> writer = factory.createObjectWriter(TYPE.FEATURETYPE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
writer.write(revFeatureType, output);
byte[] data = output.toByteArray();
assertTrue(data.length > 0);
ObjectReader<RevFeatureType> reader = factory.createObjectReader(TYPE.FEATURETYPE);
ByteArrayInputStream input = new ByteArrayInputStream(data);
RevFeatureType rft = reader.read(revFeatureType.getId(), input);
assertNotNull(rft);
SimpleFeatureType serializedFeatureType = (SimpleFeatureType) rft.type();
assertEquals(serializedFeatureType.getDescriptors().size(), featureType.getDescriptors().size());
for (int i = 0; i < featureType.getDescriptors().size(); i++) {
assertEquals(featureType.getDescriptor(i), serializedFeatureType.getDescriptor(i));
}
assertEquals(featureType.getGeometryDescriptor(), serializedFeatureType.getGeometryDescriptor());
assertEquals(featureType.getCoordinateReferenceSystem(), serializedFeatureType.getCoordinateReferenceSystem());
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class GeoGigDataStoreTest method testGetSchemaProvidedNamespace.
@Test
public void testGetSchemaProvidedNamespace() throws Exception {
String namespace = "http://www.geogig.org/test";
dataStore.setNamespaceURI(namespace);
insertAndAdd(lines1);
commit();
SimpleFeatureType lines = dataStore.getSchema(RepositoryTestCase.linesTypeName);
Name expectedName = new NameImpl(namespace, linesName);
assertEquals(expectedName, lines.getName());
assertEquals(super.linesType.getAttributeDescriptors(), lines.getAttributeDescriptors());
insertAndAdd(points1);
commit();
SimpleFeatureType points = dataStore.getSchema(RepositoryTestCase.pointsTypeName);
assertEquals(new NameImpl(namespace, pointsName), points.getName());
assertEquals(super.pointsType.getAttributeDescriptors(), points.getAttributeDescriptors());
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class GeoGigDataStoreTest method testFeatureWriterAppend.
@Test
public void testFeatureWriterAppend() throws Exception {
dataStore.createSchema(linesType);
Transaction tx = new DefaultTransaction();
FeatureWriter<SimpleFeatureType, SimpleFeature> fw = dataStore.getFeatureWriterAppend(linesTypeName.getLocalPart(), tx);
LineString line = new GeometryBuilder().lineString(0, 0, 1, 1);
SimpleFeature f = (SimpleFeature) fw.next();
f.setAttribute("sp", "foo");
f.setAttribute("ip", 10);
f.setAttribute("pp", line);
fw.write();
fw.close();
tx.commit();
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(linesTypeName);
assertEquals(1, source.getCount(null));
FeatureReader<SimpleFeatureType, SimpleFeature> r = dataStore.getFeatureReader(new Query(linesTypeName.getLocalPart()), Transaction.AUTO_COMMIT);
assertTrue(r.hasNext());
f = r.next();
assertEquals("foo", f.getAttribute("sp"));
assertEquals(10, f.getAttribute("ip"));
assertTrue(line.equals((Geometry) f.getAttribute("pp")));
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class GeoGigDataStoreTest method testCreateSchemaOnBranch.
@Test
public void testCreateSchemaOnBranch() throws IOException {
final String branchName = "testBranch";
geogig.command(BranchCreateOp.class).setName(branchName).setOrphan(true).call();
dataStore.setHead(branchName);
final SimpleFeatureType featureType = super.linesType;
dataStore.createSchema(featureType);
List<String> typeNames;
typeNames = getTypeNames(Ref.HEAD);
assertTrue(typeNames.isEmpty());
typeNames = getTypeNames(branchName);
assertEquals(1, typeNames.size());
assertEquals(linesName, typeNames.get(0));
dataStore.createSchema(super.pointsType);
typeNames = getTypeNames(Ref.HEAD);
assertTrue(typeNames.isEmpty());
typeNames = getTypeNames(branchName);
assertEquals(2, typeNames.size());
assertTrue(typeNames.contains(linesName));
assertTrue(typeNames.contains(pointsName));
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class GeoGigDataStoreTest method testCreateSchema.
@Test
public void testCreateSchema() throws IOException {
final SimpleFeatureType featureType = super.linesType;
dataStore.createSchema(featureType);
List<String> typeNames;
typeNames = getTypeNames(Ref.HEAD);
assertEquals(1, typeNames.size());
assertEquals(linesName, typeNames.get(0));
dataStore.createSchema(super.pointsType);
typeNames = getTypeNames(Ref.HEAD);
assertEquals(2, typeNames.size());
assertTrue(typeNames.contains(linesName));
assertTrue(typeNames.contains(pointsName));
try {
dataStore.createSchema(super.pointsType);
fail("Expected IOException on existing type");
} catch (IOException e) {
assertTrue(e.getMessage().contains("already exists"));
}
}
Aggregations