Search in sources :

Example 16 with GeoJsonChunkMeta

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

the class GeoJsonSplitterTest method point.

/**
 * Test if a Point can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void point() throws IOException {
    String filename = "point.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("Point", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("Point", 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)

Example 17 with GeoJsonChunkMeta

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

the class GeoJsonSplitterTest method extraAttributes.

/**
 * Test if extra attributes not part of the standard are ignored
 * @throws IOException if the test file could not be read
 */
@Test
public void extraAttributes() throws IOException {
    String filename = "featurecollectionext.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 18 with GeoJsonChunkMeta

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

the class GeoJsonSplitterTest method feature.

/**
 * Test if a Feature can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void feature() throws IOException {
    String filename = "feature.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("Feature", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("Feature", o1.getString("type"));
    assertEquals("Fraunhofer IGD", o1.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 19 with GeoJsonChunkMeta

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

the class GeoJsonSplitterTest method lineString.

/**
 * Test if a LineString can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void lineString() throws IOException {
    String filename = "linestring.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("LineString", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("LineString", o1.getString("type"));
    assertEquals(13, 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 20 with GeoJsonChunkMeta

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

the class MultiMergerTest method mixedInit.

/**
 * Test if the merger fails if chunks with a different type should be merged
 * @param context the Vert.x test context
 */
@Test
public void mixedInit(TestContext context) {
    String strChunk1 = "{\"type\":\"Feature\"}";
    String strChunk2 = XMLHEADER + "<root><test chunk=\"2\"></test></root>";
    Buffer chunk1 = Buffer.buffer(strChunk1);
    Buffer chunk2 = Buffer.buffer(strChunk2);
    GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Feature", "features", 0, chunk1.length());
    XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("root")), XMLHEADER.length() + 6, chunk2.length() - 7);
    MultiMerger m = new MultiMerger();
    Async async = context.async();
    m.init(cm1).flatMap(v -> m.init(cm2)).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) Arrays(java.util.Arrays) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) RunWith(org.junit.runner.RunWith) XMLStartElement(io.georocket.util.XMLStartElement) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) ChunkMeta(io.georocket.storage.ChunkMeta) 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) XMLStartElement(io.georocket.util.XMLStartElement) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) 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