use of org.exist.stax.EmbeddedXMLStreamReaderTest.NamedEvent in project exist by eXist-db.
the class EmbeddedXMLStreamReaderTest method assertNodesIn.
public void assertNodesIn(final NamedEvent[] expected, final Function<Document, NodeHandle> initialNodeFun, final Optional<Function<Document, NodeHandle>> containerFun) throws EXistException, PermissionDeniedException, IOException, XMLStreamException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
try (final LockedDocument lockedDocument = broker.getXMLResource(TEST_MIXED_XML_COLLECTION.append(MIXED_XML_NAME), Lock.LockMode.WRITE_LOCK)) {
assertNotNull(lockedDocument);
final Document document = lockedDocument.getDocument();
assertNotNull(document);
final NodeHandle initialNode = initialNodeFun.apply(document);
final Optional<NodeHandle> maybeContainerNode = containerFun.map(f -> f.apply(document));
final IEmbeddedXMLStreamReader xmlStreamReader = broker.getXMLStreamReader(initialNode, false);
final NamedEvent[] actual = readAllEvents(maybeContainerNode, xmlStreamReader);
assertArrayEquals(formatExpectedActual(expected, actual), expected, actual);
}
transaction.commit();
}
}
use of org.exist.stax.EmbeddedXMLStreamReaderTest.NamedEvent in project exist by eXist-db.
the class EmbeddedXMLStreamReaderTest method readAllEvents.
private NamedEvent[] readAllEvents(final Optional<NodeHandle> maybeContainerNode, final IEmbeddedXMLStreamReader xmlStreamReader) throws XMLStreamException {
final List<NamedEvent> events = new ArrayList<>();
while (xmlStreamReader.hasNext()) {
final NamedEvent namedEvent = NamedEvent.fromEvent(xmlStreamReader.next());
// filter for descendant-or-self if specified
if (maybeContainerNode.isPresent() && !descendantOrSelf(maybeContainerNode.get(), xmlStreamReader)) {
// exit-while
break;
}
events.add(namedEvent);
}
return events.toArray(new NamedEvent[events.size()]);
}
Aggregations