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