use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class DocTest method docAvailable_dynamicallyAvailableDocument_relativeUri.
@Test
public void docAvailable_dynamicallyAvailableDocument_relativeUri() throws XPathException, EXistException, PermissionDeniedException, URISyntaxException {
final BrokerPool pool = BrokerPool.getInstance();
final String doc = "<timestamp>" + System.currentTimeMillis() + "</timestamp>";
final String baseUri = "http://from-dynamic-context/";
final String docRelativeUri = "doc1";
final String query = "fn:doc-available('" + docRelativeUri + "')";
try (final DBBroker broker = pool.getBroker()) {
final XQueryContext context = new XQueryContext(pool);
context.setBaseURI(new AnyURIValue(new URI(baseUri)));
context.addDynamicallyAvailableDocument(baseUri + docRelativeUri, (broker2, transaction, uri) -> asInMemoryDocument(doc));
final XQuery xqueryService = pool.getXQueryService();
final CompiledXQuery compiled = xqueryService.compile(context, query);
final Sequence result = xqueryService.execute(broker, compiled, null);
assertFalse(result.isEmpty());
assertEquals(1, result.getItemCount());
assertTrue(result.itemAt(0).toJavaObject(Boolean.class).booleanValue());
}
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class DocTest method doc_dynamicallyAvailableDocument_absoluteUri.
@Test
public void doc_dynamicallyAvailableDocument_absoluteUri() throws XPathException, EXistException, PermissionDeniedException {
final BrokerPool pool = BrokerPool.getInstance();
final String doc = "<timestamp>" + System.currentTimeMillis() + "</timestamp>";
final String docUri = "http://from-dynamic-context/doc1";
final String query = "fn:doc('" + docUri + "')";
try (final DBBroker broker = pool.getBroker()) {
final XQueryContext context = new XQueryContext(pool);
context.addDynamicallyAvailableDocument(docUri, (broker2, transaction, uri) -> asInMemoryDocument(doc));
final XQuery xqueryService = pool.getXQueryService();
final CompiledXQuery compiled = xqueryService.compile(context, query);
final Sequence result = xqueryService.execute(broker, compiled, null);
assertFalse(result.isEmpty());
assertEquals(1, result.getItemCount());
assertTrue(result.itemAt(0) instanceof Node);
final Source expectedSource = Input.fromString(doc).build();
final Source actualSource = Input.fromNode((Node) result.itemAt(0)).build();
final Diff diff = DiffBuilder.compare(expectedSource).withTest(actualSource).checkForIdentical().checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class FunUnparsedTextTest method unparsedTextAvailable_dynamicallyAvailableDocument_relativeUri.
@Test
public void unparsedTextAvailable_dynamicallyAvailableDocument_relativeUri() throws XPathException, EXistException, PermissionDeniedException, URISyntaxException {
final BrokerPool pool = BrokerPool.getInstance();
final String text = "hello, the time is: " + System.currentTimeMillis();
final String baseUri = "http://from-dynamic-context/";
final String textRelativeUri = "doc1";
final String query = "fn:unparsed-text-available('" + textRelativeUri + "')";
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQueryContext context = new XQueryContext(pool);
context.setBaseURI(new AnyURIValue(new URI(baseUri)));
context.addDynamicallyAvailableTextResource(baseUri + textRelativeUri, UTF_8, (broker2, transaction, uri, charset) -> new InputStreamReader(new ByteArrayInputStream(text.getBytes(UTF_8)), charset));
final XQuery xqueryService = pool.getXQueryService();
final CompiledXQuery compiled = xqueryService.compile(context, query);
final Sequence result = xqueryService.execute(broker, compiled, null);
assertFalse(result.isEmpty());
assertEquals(1, result.getItemCount());
assertTrue(result.itemAt(0).toJavaObject(Boolean.class).booleanValue());
}
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class FunUnparsedTextTest method unparsedTextLines_noDataStream.
@Test(expected = XPathException.class)
public void unparsedTextLines_noDataStream() throws XPathException, EXistException, PermissionDeniedException {
final BrokerPool pool = BrokerPool.getInstance();
final String text = "hello, the time is: " + System.currentTimeMillis();
final String textUri = "http://from-dynamic-context/doc1";
final String query = "fn:unparsed-text-lines('" + textUri + "')";
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQueryContext context = new XQueryContext(pool);
context.addDynamicallyAvailableTextResource(textUri, UTF_8, (broker2, transaction, uri, charset) -> new InputStreamReader(null, charset));
final XQuery xqueryService = pool.getXQueryService();
final CompiledXQuery compiled = xqueryService.compile(context, query);
final Sequence result = xqueryService.execute(broker, compiled, null);
}
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class FunUnparsedTextTest method unparsedText_dynamicallyAvailableDocument_relativeUri.
@Test
public void unparsedText_dynamicallyAvailableDocument_relativeUri() throws XPathException, EXistException, PermissionDeniedException, URISyntaxException {
final BrokerPool pool = BrokerPool.getInstance();
final String text = "hello, the time is: " + System.currentTimeMillis();
final String baseUri = "http://from-dynamic-context/";
final String textRelativeUri = "doc1";
final String query = "fn:unparsed-text('" + textRelativeUri + "')";
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQueryContext context = new XQueryContext(pool);
context.setBaseURI(new AnyURIValue(new URI(baseUri)));
context.addDynamicallyAvailableTextResource(baseUri + textRelativeUri, UTF_8, (broker2, transaction, uri, charset) -> new InputStreamReader(new ByteArrayInputStream(text.getBytes(UTF_8)), charset));
final XQuery xqueryService = pool.getXQueryService();
final CompiledXQuery compiled = xqueryService.compile(context, query);
final Sequence result = xqueryService.execute(broker, compiled, null);
assertFalse(result.isEmpty());
assertEquals(1, result.getItemCount());
assertEquals(Type.STRING, result.itemAt(0).getType());
assertEquals(text, result.itemAt(0).getStringValue());
}
}
Aggregations