Search in sources :

Example 1 with XMLStartElement

use of io.georocket.util.XMLStartElement in project georocket by georocket.

the class AbstractMergeStrategy method finish.

@Override
public void finish(WriteStream<Buffer> out) {
    // close all parent elements
    for (int i = parents.size() - 1; i >= 0; --i) {
        XMLStartElement e = parents.get(i);
        out.write(Buffer.buffer("</" + e.getName() + ">"));
    }
}
Also used : XMLStartElement(io.georocket.util.XMLStartElement)

Example 2 with XMLStartElement

use of io.georocket.util.XMLStartElement in project georocket by georocket.

the class FirstLevelSplitterTest method oneChunk.

/**
 * Test if an XML string with one chunk can be split
 * @throws Exception if an error has occurred
 */
@Test
public void oneChunk() throws Exception {
    String xml = XMLHEADER + "<root>\n<object><child></child></object>\n</root>";
    List<Result<XMLChunkMeta>> chunks = split(xml);
    assertEquals(1, chunks.size());
    Result<XMLChunkMeta> chunk = chunks.get(0);
    XMLChunkMeta meta = new XMLChunkMeta(Arrays.asList(new XMLStartElement("root")), XMLHEADER.length() + 7, xml.length() - 8);
    assertEquals(meta, chunk.getMeta());
    assertEquals(xml, chunk.getChunk());
}
Also used : XMLStartElement(io.georocket.util.XMLStartElement) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) Result(io.georocket.input.Splitter.Result) Test(org.junit.Test)

Example 3 with XMLStartElement

use of io.georocket.util.XMLStartElement in project georocket by georocket.

the class FirstLevelSplitterTest method twoChunks.

/**
 * Test if an XML string with tow chunks can be split
 * @throws Exception if an error has occurred
 */
@Test
public void twoChunks() throws Exception {
    String xml = XMLHEADER + "<root><object><child></child></object>" + "<object><child2></child2></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("root"));
    XMLChunkMeta meta1 = new XMLChunkMeta(parents, XMLHEADER.length() + 7, XMLHEADER.length() + 7 + 32);
    XMLChunkMeta meta2 = new XMLChunkMeta(parents, XMLHEADER.length() + 7, XMLHEADER.length() + 7 + 34);
    assertEquals(meta1, chunk1.getMeta());
    assertEquals(meta2, chunk2.getMeta());
    assertEquals(XMLHEADER + "<root>\n<object><child></child></object>\n</root>", chunk1.getChunk());
    assertEquals(XMLHEADER + "<root>\n<object><child2></child2></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 4 with XMLStartElement

use of io.georocket.util.XMLStartElement in project georocket by georocket.

the class FirstLevelSplitterTest method attributes.

/**
 * Test if an XML string with two chunks and a attributes can be split
 * @throws Exception if an error has occurred
 */
@Test
public void attributes() throws Exception {
    String root = "<root key=\"value\" key2=\"value2\">";
    String xml = XMLHEADER + root + "<object ok=\"ov\"><child></child></object>" + "<object><child2></child2></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[] { "", "" }, new String[] { "key", "key2" }, new String[] { "value", "value2" }));
    XMLChunkMeta meta1 = new XMLChunkMeta(parents, XMLHEADER.length() + root.length() + 1, XMLHEADER.length() + root.length() + 1 + 40);
    XMLChunkMeta meta2 = new XMLChunkMeta(parents, XMLHEADER.length() + root.length() + 1, XMLHEADER.length() + root.length() + 1 + 34);
    assertEquals(meta1, chunk1.getMeta());
    assertEquals(meta2, chunk2.getMeta());
    assertEquals(XMLHEADER + root + "\n<object ok=\"ov\"><child></child></object>\n</root>", chunk1.getChunk());
    assertEquals(XMLHEADER + root + "\n<object><child2></child2></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 5 with XMLStartElement

use of io.georocket.util.XMLStartElement in project georocket by georocket.

the class FirstLevelSplitterTest method utf8.

/**
 * Test if an XML string with an UTF8 character can be split
 * @throws Exception if an error has occurred
 */
@Test
public void utf8() throws Exception {
    String xml = XMLHEADER + "<root>\n<object><child name=\"\u2248\"></child></object>\n</root>";
    List<Result<XMLChunkMeta>> chunks = split(xml);
    assertEquals(1, chunks.size());
    Result<XMLChunkMeta> chunk = chunks.get(0);
    XMLChunkMeta meta = new XMLChunkMeta(Arrays.asList(new XMLStartElement("root")), XMLHEADER.length() + 7, xml.getBytes(StandardCharsets.UTF_8).length - 8);
    assertEquals(meta, chunk.getMeta());
    assertEquals(xml, chunk.getChunk());
}
Also used : XMLStartElement(io.georocket.util.XMLStartElement) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) Result(io.georocket.input.Splitter.Result) Test(org.junit.Test)

Aggregations

XMLStartElement (io.georocket.util.XMLStartElement)17 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)14 Test (org.junit.Test)13 Buffer (io.vertx.core.buffer.Buffer)7 Result (io.georocket.input.Splitter.Result)6 BufferWriteStream (io.georocket.util.io.BufferWriteStream)4 DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)4 Async (io.vertx.ext.unit.Async)4 TestContext (io.vertx.ext.unit.TestContext)4 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)4 Arrays (java.util.Arrays)4 Pair (org.apache.commons.lang3.tuple.Pair)4 RunWith (org.junit.runner.RunWith)4 ChunkMeta (io.georocket.storage.ChunkMeta)2 ChunkReadStream (io.georocket.storage.ChunkReadStream)2 GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)2 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)2 ArrayList (java.util.ArrayList)2 Rule (org.junit.Rule)2 Observable (rx.Observable)2