Search in sources :

Example 6 with XMLStartElement

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

the class MultiMergerTest method mixedMerge.

/**
 * Test if the merger fails if chunks with a different type should be merged
 * @param context the Vert.x test context
 */
@Test
public void mixedMerge(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();
    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)).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) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) XMLStartElement(io.georocket.util.XMLStartElement) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Example 7 with XMLStartElement

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

the class XMLMergerTest method mergeNamespaces.

/**
 * Test if chunks with different namespaces can be merged
 * @param context the Vert.x test context
 */
@Test
public void mergeNamespaces(TestContext context) {
    XMLStartElement root1 = new XMLStartElement(null, "CityModel", new String[] { "", "gml", "gen", XSI }, new String[] { NS_CITYGML_1_0, NS_GML, NS_CITYGML_1_0_GENERICS, NS_SCHEMA_INSTANCE }, new String[] { XSI }, new String[] { SCHEMA_LOCATION }, new String[] { NS_CITYGML_1_0_GENERICS_SCHEMA_LOCATION });
    XMLStartElement root2 = new XMLStartElement(null, "CityModel", new String[] { "", "gml", "bldg", XSI }, new String[] { NS_CITYGML_1_0, NS_GML, NS_CITYGML_1_0_BUILDING, NS_SCHEMA_INSTANCE }, new String[] { XSI }, new String[] { SCHEMA_LOCATION }, new String[] { NS_CITYGML_1_0_BUILDING_SCHEMA_LOCATION });
    String contents1 = "<cityObjectMember><gen:GenericCityObject></gen:GenericCityObject></cityObjectMember>";
    Buffer chunk1 = Buffer.buffer(XMLHEADER + root1 + contents1 + "</" + root1.getName() + ">");
    String contents2 = "<cityObjectMember><bldg:Building></bldg:Building></cityObjectMember>";
    Buffer chunk2 = Buffer.buffer(XMLHEADER + root2 + contents2 + "</" + root2.getName() + ">");
    XMLChunkMeta cm1 = new XMLChunkMeta(Arrays.asList(root1), XMLHEADER.length() + root1.toString().length(), chunk1.length() - root1.getName().length() - 3);
    XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(root2), XMLHEADER.length() + root2.toString().length(), chunk2.length() - root2.getName().length() - 3);
    XMLStartElement expectedRoot = new XMLStartElement(null, "CityModel", new String[] { "", "gml", "gen", XSI, "bldg" }, new String[] { NS_CITYGML_1_0, NS_GML, NS_CITYGML_1_0_GENERICS, NS_SCHEMA_INSTANCE, NS_CITYGML_1_0_BUILDING }, new String[] { XSI }, new String[] { SCHEMA_LOCATION }, new String[] { NS_CITYGML_1_0_GENERICS_SCHEMA_LOCATION + " " + NS_CITYGML_1_0_BUILDING_SCHEMA_LOCATION });
    doMerge(context, Observable.just(chunk1, chunk2), Observable.just(cm1, cm2), expectedRoot + contents1 + contents2 + "</" + expectedRoot.getName() + ">");
}
Also used : Buffer(io.vertx.core.buffer.Buffer) XMLStartElement(io.georocket.util.XMLStartElement) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) Test(org.junit.Test)

Example 8 with XMLStartElement

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

the class XMLMergerTest method simple.

/**
 * Test if simple chunks can be merged
 * @param context the Vert.x test context
 */
@Test
public void simple(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), "<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 9 with XMLStartElement

use of io.georocket.util.XMLStartElement 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 10 with XMLStartElement

use of io.georocket.util.XMLStartElement 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

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