Search in sources :

Example 6 with Result

use of io.georocket.input.Splitter.Result 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)

Example 7 with Result

use of io.georocket.input.Splitter.Result in project georocket by georocket.

the class FirstLevelSplitterTest method namespace.

/**
 * Test if an XML string with two chunks and a namespace can be split
 * @throws Exception if an error has occurred
 */
@Test
public void namespace() throws Exception {
    String root = "<root xmlns=\"http://example.com\" xmlns:p=\"http://example.com\">";
    String xml = XMLHEADER + root + "<p:object><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" }));
    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 + 38);
    assertEquals(meta1, chunk1.getMeta());
    assertEquals(meta2, chunk2.getMeta());
    assertEquals(XMLHEADER + root + "\n<p:object><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 8 with Result

use of io.georocket.input.Splitter.Result 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)

Aggregations

Result (io.georocket.input.Splitter.Result)8 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)7 XMLStartElement (io.georocket.util.XMLStartElement)6 Test (org.junit.Test)6 Window (io.georocket.util.Window)2 AsyncByteArrayFeeder (com.fasterxml.aalto.AsyncByteArrayFeeder)1 AsyncXMLInputFactory (com.fasterxml.aalto.AsyncXMLInputFactory)1 InputFactoryImpl (com.fasterxml.aalto.stax.InputFactoryImpl)1 AddressConstants (io.georocket.constants.AddressConstants)1 ConfigConstants (io.georocket.constants.ConfigConstants)1 XMLCRSIndexer (io.georocket.index.xml.XMLCRSIndexer)1 GeoJsonSplitter (io.georocket.input.geojson.GeoJsonSplitter)1 FirstLevelSplitter (io.georocket.input.xml.FirstLevelSplitter)1 XMLSplitter (io.georocket.input.xml.XMLSplitter)1 ChunkMeta (io.georocket.storage.ChunkMeta)1 IndexMeta (io.georocket.storage.IndexMeta)1 RxStore (io.georocket.storage.RxStore)1 StoreFactory (io.georocket.storage.StoreFactory)1 JsonParserOperator (io.georocket.util.JsonParserOperator)1 MimeTypeUtils.belongsTo (io.georocket.util.MimeTypeUtils.belongsTo)1