use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method userEscalationForInMemoryNodes.
@Test
public void userEscalationForInMemoryNodes() throws XMLDBException {
String query = "xmldb:login(\"xmldb:exist:///db\", \"guest\", \"guest\"), sm:id()/sm:id/sm:effective/sm:username/text(), let $node := <node id=\"1\">value</node>, $null := $node[@id eq '1'] return sm:id()/sm:id/sm:effective/sm:username/text()";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
Resource loggedIn = result.getResource(0);
Resource currentUser = result.getResource(1);
Resource currentUserAfterInMemoryOp = result.getResource(2);
// check the login as guest worked
assertEquals("Logged in as quest: " + loggedIn.getContent().toString(), "true", loggedIn.getContent().toString());
// check that we are guest
assertEquals("After Login as guest, User should be guest and is: " + currentUser.getContent().toString(), "guest", currentUser.getContent().toString());
// check that we are still guest
assertEquals("After Query, User should still be guest and is: " + currentUserAfterInMemoryOp.getContent().toString(), "guest", currentUserAfterInMemoryOp.getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method serialization.
@Test
public void serialization() throws XMLDBException {
@SuppressWarnings("unused") ResourceSet result;
String query;
@SuppressWarnings("unused") boolean exceptionThrown;
String message;
XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
query = "let $a := <test><foo name='bar'/><foo name='bar'/></test>" + "return <attribute>{$a/foo/@name}</attribute>";
try {
message = "";
result = service.query(query);
} catch (XMLDBException e) {
message = e.getMessage();
}
assertTrue(message.indexOf("XQDY0025") > -1);
query = "let $a := <foo name='bar'/> return $a/@name";
try {
message = "";
result = service.query(query);
} catch (XMLDBException e) {
message = e.getMessage();
}
// TODO : how toserialize this resultand get the error ? -pb
// assertTrue(message.indexOf("XQDY0025") > -1);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method descendantOrSelf_1460791.
/**
* @see http://sourceforge.net/support/tracker.php?aid=1460791
*/
@Test
public void descendantOrSelf_1460791() throws XMLDBException {
String query = "declare option exist:serialize 'indent=no';" + "let $test:=<z> <a> aaa </a> <z> zzz </z> </z> " + "return " + "( " + "<one> {$test//z} </one>, " + "<two> {$test/descendant-or-self::node()/child::z} </two> " + "(: note that these should be the same *by definition* :) " + ")";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(2, result.getSize());
assertEquals(query, result.getResource(0).getContent().toString(), "<one><z> zzz </z></one>");
assertEquals(query, result.getResource(1).getContent().toString(), "<two><z> zzz </z></two>");
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method constructedAttributeValue.
@Test
public void constructedAttributeValue() throws XMLDBException {
String query = "let $attr := attribute d { \"xxx\" } " + "return string($attr)";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals("xxx", result.getResource(0).getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method noNamepaceDefinedForPrefix_1959010.
/**
* @see http://sourceforge.net/support/tracker.php?aid=1959010
*/
@Test
public void noNamepaceDefinedForPrefix_1959010() throws XMLDBException {
String query = "declare function local:copy($nodes as node()*) as node()* " + "{ " + "for $n in $nodes " + "return " + " if ($n instance of element()) then " + " element {node-name($n)} {(local:copy($n/@*), local:copy($n/node()))} " + " else if ($n instance of attribute()) then " + " attribute {node-name($n)} {$n} " + " else if ($n instance of text()) then " + " text {$n} " + " else " + " <Other/> " + "}; " + "let $c := <c:C xmlns:c=\"http://c\" xmlns:d=\"http://d\" d:d=\"ddd\">ccc</c:C> " + "return local:copy($c)";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals(query, "<c:C xmlns:c=\"http://c\" xmlns:d=\"http://d\" d:d=\"ddd\">ccc</c:C>", result.getResource(0).getContent().toString());
}
Aggregations