Search in sources :

Example 11 with XMLChunkMeta

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

the class FirstLevelSplitterTest method full.

/**
 * Test if an XML string with two chunks, a namespace and attributes can be split
 * @throws Exception if an error has occurred
 */
@Test
public void full() throws Exception {
    String root = "<root xmlns=\"http://example.com\" xmlns:p=\"http://example.com\" key=\"value\" key2=\"value2\">";
    String xml = XMLHEADER + root + "<p:object ok=\"ov\"><p:child></p:child></p:object>" + "<p:object><child2></child2></p:object></root>";
    List<Result<XMLChunkMeta>> chunks = split(xml);
    assertEquals(2, chunks.size());
    Result<XMLChunkMeta> chunk1 = chunks.get(0);
    Result<XMLChunkMeta> chunk2 = chunks.get(1);
    List<XMLStartElement> parents = Arrays.asList(new XMLStartElement(null, "root", new String[] { "", "p" }, new String[] { "http://example.com", "http://example.com" }, new String[] { "", "" }, new String[] { "key", "key2" }, new String[] { "value", "value2" }));
    XMLChunkMeta meta1 = new XMLChunkMeta(parents, XMLHEADER.length() + root.length() + 1, XMLHEADER.length() + root.length() + 1 + 48);
    XMLChunkMeta meta2 = new XMLChunkMeta(parents, XMLHEADER.length() + root.length() + 1, XMLHEADER.length() + root.length() + 1 + 38);
    assertEquals(meta1, chunk1.getMeta());
    assertEquals(meta2, chunk2.getMeta());
    assertEquals(XMLHEADER + root + "\n<p:object ok=\"ov\"><p:child></p:child></p:object>\n</root>", chunk1.getChunk());
    assertEquals(XMLHEADER + root + "\n<p:object><child2></child2></p:object>\n</root>", chunk2.getChunk());
}
Also used : XMLStartElement(io.georocket.util.XMLStartElement) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) Result(io.georocket.input.Splitter.Result) Test(org.junit.Test)

Example 12 with XMLChunkMeta

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

the class MultiMergerTest method xmlSimple.

/**
 * Test if simple XML chunks can be merged
 * @param context the Vert.x test context
 */
@Test
public void xmlSimple(TestContext context) {
    Buffer chunk1 = Buffer.buffer(XMLHEADER + "<root><test chunk=\"1\"></test></root>");
    Buffer chunk2 = Buffer.buffer(XMLHEADER + "<root><test chunk=\"2\"></test></root>");
    XMLChunkMeta cm = new XMLChunkMeta(Arrays.asList(new XMLStartElement("root")), XMLHEADER.length() + 6, chunk1.length() - 7);
    doMerge(context, Observable.just(chunk1, chunk2), Observable.just(cm, cm), XMLHEADER + "<root><test chunk=\"1\"></test><test chunk=\"2\"></test></root>");
}
Also used : Buffer(io.vertx.core.buffer.Buffer) XMLStartElement(io.georocket.util.XMLStartElement) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) Test(org.junit.Test)

Example 13 with XMLChunkMeta

use of io.georocket.storage.XMLChunkMeta 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)

Example 14 with XMLChunkMeta

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

the class AllSameStrategyTest method canMerge.

/**
 * Test if canMerge works correctly
 * @param context the test context
 */
@Test
public void canMerge(TestContext context) {
    XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("other")), 10, 20);
    XMLChunkMeta cm3 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("pre", "root")), 10, 20);
    XMLChunkMeta cm4 = new XMLChunkMeta(Arrays.asList(new XMLStartElement(null, "root", new String[] { "" }, new String[] { "uri" })), 10, 20);
    Async async = context.async();
    MergeStrategy strategy = new AllSameStrategy();
    strategy.canMerge(cm).doOnNext(c -> context.assertTrue(c)).flatMap(v -> strategy.init(cm)).flatMap(v -> strategy.canMerge(cm)).doOnNext(c -> context.assertTrue(c)).flatMap(v -> strategy.canMerge(cm2)).doOnNext(c -> context.assertFalse(c)).flatMap(v -> strategy.canMerge(cm3)).doOnNext(c -> context.assertFalse(c)).flatMap(v -> strategy.canMerge(cm4)).doOnNext(c -> context.assertFalse(c)).subscribe(v -> {
        async.complete();
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) 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) XMLStartElement(io.georocket.util.XMLStartElement) Async(io.vertx.ext.unit.Async) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) Test(org.junit.Test)

Example 15 with XMLChunkMeta

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

the class AllSameStrategyTest method mergeFail.

/**
 * Test if the merge method fails if it is called with an unexpected chunk
 * @param context the test context
 */
@Test
public void mergeFail(TestContext context) {
    XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("other")), 10, 20);
    Async async = context.async();
    MergeStrategy strategy = new AllSameStrategy();
    BufferWriteStream bws = new BufferWriteStream();
    strategy.init(cm).flatMap(v -> strategy.merge(new DelegateChunkReadStream(chunk2), cm2, bws)).subscribe(v -> context.fail(), err -> {
        context.assertTrue(err instanceof IllegalArgumentException);
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) 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) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) XMLStartElement(io.georocket.util.XMLStartElement) Async(io.vertx.ext.unit.Async) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Aggregations

XMLChunkMeta (io.georocket.storage.XMLChunkMeta)16 XMLStartElement (io.georocket.util.XMLStartElement)15 Test (org.junit.Test)14 Buffer (io.vertx.core.buffer.Buffer)8 Result (io.georocket.input.Splitter.Result)7 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 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 Arrays (java.util.Arrays)5 RunWith (org.junit.runner.RunWith)5 ChunkReadStream (io.georocket.storage.ChunkReadStream)3 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)3 Pair (org.apache.commons.lang3.tuple.Pair)3 Rule (org.junit.Rule)3 Observable (rx.Observable)3 ChunkMeta (io.georocket.storage.ChunkMeta)2 GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)2 ArrayList (java.util.ArrayList)2