use of org.exist.xquery.XQuery in project exist by eXist-db.
the class InspectModuleTest method xqDoc_onAnnotatedFunction.
@Test
public void xqDoc_onAnnotatedFunction() throws PermissionDeniedException, XPathException, EXistException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xqueryService = pool.getXQueryService();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final String query = "import module namespace inspect = \"http://exist-db.org/xquery/inspection\";\n" + "inspect:inspect-module(xs:anyURI(\"xmldb:exist://" + TEST_COLLECTION.append(TEST_MODULE).toCollectionPathURI() + "\"))\n" + "/function[@name eq \"x:fun4\"]";
final Sequence result = xqueryService.execute(broker, query, null);
assertNotNull(result);
assertEquals(1, result.getItemCount());
final Item item1 = result.itemAt(0);
assertTrue(item1 instanceof ElementImpl);
final Element function = (Element) item1;
final NodeList descriptions = function.getElementsByTagName("description");
assertEquals(1, descriptions.getLength());
assertEquals("An annotated function.", descriptions.item(0).getFirstChild().getNodeValue());
final NodeList annotations = function.getElementsByTagName("annotation");
assertEquals(2, annotations.getLength());
assertEquals("public", ((Element) annotations.item(0)).getAttribute("name"));
assertEquals("x:path", ((Element) annotations.item(1)).getAttribute("name"));
assertEquals("/x/y/z", annotations.item(1).getFirstChild().getFirstChild().getNodeValue());
final NodeList arguments = function.getElementsByTagName("argument");
assertEquals(0, arguments.getLength());
final NodeList returns = function.getElementsByTagName("returns");
assertEquals(1, returns.getLength());
assertEquals("another result", returns.item(0).getFirstChild().getNodeValue());
transaction.commit();
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class InspectModuleTest method xqDoc_multilineDesciption.
@Test
public void xqDoc_multilineDesciption() throws PermissionDeniedException, XPathException, EXistException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xqueryService = pool.getXQueryService();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final String query = "import module namespace inspect = \"http://exist-db.org/xquery/inspection\";\n" + "inspect:inspect-module(xs:anyURI(\"xmldb:exist://" + TEST_COLLECTION.append(TEST_MODULE).toCollectionPathURI() + "\"))\n" + "/function[@name eq \"x:fun3\"]";
final Sequence result = xqueryService.execute(broker, query, null);
assertNotNull(result);
assertEquals(1, result.getItemCount());
final Item item1 = result.itemAt(0);
assertTrue(item1 instanceof ElementImpl);
final Element function = (Element) item1;
final NodeList descriptions = function.getElementsByTagName("description");
assertEquals(1, descriptions.getLength());
assertEquals("This is a multiline description and therefore\n spans multiple\n lines.", descriptions.item(0).getFirstChild().getNodeValue());
final NodeList arguments = function.getElementsByTagName("argument");
assertEquals(0, arguments.getLength());
final NodeList returns = function.getElementsByTagName("returns");
assertEquals(1, returns.getLength());
assertEquals("another result", returns.item(0).getFirstChild().getNodeValue());
transaction.commit();
}
}
use of org.exist.xquery.XQuery 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.XQuery 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.XQuery 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