use of io.georocket.util.XMLStartElement 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.util.XMLStartElement 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.util.XMLStartElement 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.util.XMLStartElement 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();
});
}
use of io.georocket.util.XMLStartElement in project georocket by georocket.
the class XMLSplitter method makeResult.
/**
* Create a new chunk starting from the marked position and ending on the
* given position. Reset the mark afterwards and advance the window to the
* end position. Return a {@link io.georocket.input.Splitter.Result} object
* with the new chunk and its metadata.
* @param pos the end position
* @return the {@link io.georocket.input.Splitter.Result} object
*/
protected Result<XMLChunkMeta> makeResult(int pos) {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
// append the full stack of start elements (backwards)
List<XMLStartElement> chunkParents = new ArrayList<>();
startElements.descendingIterator().forEachRemaining(e -> {
chunkParents.add(e);
sb.append(e + "\n");
});
// get chunk start in bytes
int chunkStart = sb.toString().getBytes(StandardCharsets.UTF_8).length;
// append current element
byte[] bytes = window.getBytes(mark, pos);
sb.append(new String(bytes, StandardCharsets.UTF_8));
window.advanceTo(pos);
mark = -1;
// get chunk end in bytes
int chunkEnd = chunkStart + bytes.length;
// append the full stack of end elements
startElements.iterator().forEachRemaining(e -> sb.append("\n</" + e.getName() + ">"));
XMLChunkMeta meta = new XMLChunkMeta(chunkParents, chunkStart, chunkEnd);
return new Result<XMLChunkMeta>(sb.toString(), meta);
}
Aggregations