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();
});
}
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() + ">");
}
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>");
}
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());
}
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());
}
Aggregations