Search in sources :

Example 11 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonMergerTest method twoGeometries.

/**
 * Test if two geometries can be merged to a geometry collection
 * @param context the Vert.x test context
 */
@Test
public void twoGeometries(TestContext context) {
    String strChunk1 = "{\"type\":\"Polygon\"}";
    String strChunk2 = "{\"type\":\"Point\"}";
    Buffer chunk1 = Buffer.buffer(strChunk1);
    Buffer chunk2 = Buffer.buffer(strChunk2);
    GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Polygon", "geometries", 0, chunk1.length());
    GeoJsonChunkMeta cm2 = new GeoJsonChunkMeta("Point", "geometries", 0, chunk2.length());
    doMerge(context, Observable.just(chunk1, chunk2), Observable.just(cm1, cm2), "{\"type\":\"GeometryCollection\",\"geometries\":[" + strChunk1 + "," + strChunk2 + "]}");
}
Also used : Buffer(io.vertx.core.buffer.Buffer) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) Test(org.junit.Test)

Example 12 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonMergerTest method notEnoughInits.

/**
 * Test if the merger fails if {@link GeoJsonMerger#init(GeoJsonChunkMeta)} has
 * not been called often enough
 * @param context the Vert.x test context
 */
@Test
public void notEnoughInits(TestContext context) {
    String strChunk1 = "{\"type\":\"Feature\"}";
    String strChunk2 = "{\"type\":\"Feature\",\"properties\":{}}";
    Buffer chunk1 = Buffer.buffer(strChunk1);
    Buffer chunk2 = Buffer.buffer(strChunk2);
    GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Feature", "features", 0, chunk1.length());
    GeoJsonChunkMeta cm2 = new GeoJsonChunkMeta("Feature", "features", 0, chunk2.length());
    GeoJsonMerger m = new GeoJsonMerger();
    BufferWriteStream bws = new BufferWriteStream();
    Async async = context.async();
    m.init(cm1).flatMap(v -> m.merge(new DelegateChunkReadStream(chunk1), cm1, bws)).flatMap(v -> m.merge(new DelegateChunkReadStream(chunk2), cm2, bws)).last().subscribe(v -> {
        context.fail();
    }, err -> {
        context.assertTrue(err instanceof IllegalStateException);
        async.complete();
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Observable(rx.Observable) Rule(org.junit.Rule) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Pair(org.apache.commons.lang3.tuple.Pair) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) ChunkReadStream(io.georocket.storage.ChunkReadStream) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Example 13 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonSplitterTest method muliLineString.

/**
 * Test if a MultiLineString can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void muliLineString() throws IOException {
    String filename = "multilinestring.json";
    long size = getFileSize(filename);
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = split(filename);
    assertEquals(1, chunks.size());
    Tuple2<GeoJsonChunkMeta, JsonObject> t1 = chunks.get(0);
    GeoJsonChunkMeta m1 = t1.v1;
    assertNull(m1.getParentFieldName());
    assertEquals(0, m1.getStart());
    assertEquals(size, m1.getEnd());
    assertEquals("MultiLineString", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("MultiLineString", o1.getString("type"));
    assertEquals(3, o1.getJsonArray("coordinates").size());
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 14 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonSplitterTest method featureCollection.

/**
 * Test if a FeatureCollection can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void featureCollection() throws IOException {
    String filename = "featurecollection.json";
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = split(filename);
    assertEquals(2, chunks.size());
    Tuple2<GeoJsonChunkMeta, JsonObject> t1 = chunks.get(0);
    GeoJsonChunkMeta m1 = t1.v1;
    assertEquals("features", m1.getParentFieldName());
    assertEquals(0, m1.getStart());
    assertEquals(307, m1.getEnd());
    assertEquals("Feature", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("Feature", o1.getString("type"));
    assertEquals("Fraunhofer IGD", o1.getJsonObject("properties").getString("name"));
    Tuple2<GeoJsonChunkMeta, JsonObject> t2 = chunks.get(1);
    GeoJsonChunkMeta m2 = t2.v1;
    assertEquals("features", m2.getParentFieldName());
    assertEquals(0, m2.getStart());
    assertEquals(305, m2.getEnd());
    assertEquals("Feature", m2.getType());
    JsonObject o2 = t2.v2;
    assertEquals("Feature", o2.getString("type"));
    assertEquals("Darmstadtium", o2.getJsonObject("properties").getString("name"));
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 15 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonSplitterTest method multiPoint.

/**
 * Test if a MultiPoint can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void multiPoint() throws IOException {
    String filename = "multipoint.json";
    long size = getFileSize(filename);
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = split(filename);
    assertEquals(1, chunks.size());
    Tuple2<GeoJsonChunkMeta, JsonObject> t1 = chunks.get(0);
    GeoJsonChunkMeta m1 = t1.v1;
    assertNull(m1.getParentFieldName());
    assertEquals(0, m1.getStart());
    assertEquals(size, m1.getEnd());
    assertEquals("MultiPoint", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("MultiPoint", o1.getString("type"));
    assertEquals(2, o1.getJsonArray("coordinates").size());
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)28 Test (org.junit.Test)27 Buffer (io.vertx.core.buffer.Buffer)17 JsonObject (io.vertx.core.json.JsonObject)11 Tuple2 (org.jooq.lambda.tuple.Tuple2)11 ChunkReadStream (io.georocket.storage.ChunkReadStream)5 BufferWriteStream (io.georocket.util.io.BufferWriteStream)5 DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)5 Async (io.vertx.ext.unit.Async)5 TestContext (io.vertx.ext.unit.TestContext)5 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Rule (org.junit.Rule)5 RunWith (org.junit.runner.RunWith)5 Observable (rx.Observable)5 ChunkMeta (io.georocket.storage.ChunkMeta)2 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)2 XMLStartElement (io.georocket.util.XMLStartElement)2 Arrays (java.util.Arrays)2