Search in sources :

Example 81 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method exclusiveLock.

@Test
public void exclusiveLock() throws XPathException, XMLDBException {
    String query = "let $query1 := (<a/>)\n" + "let $query2 := (2, 3)\n" + "let $a := util:exclusive-lock(//*,($query1, $query2))\n" + "return $a";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    assertEquals(3, result.getSize());
    String r = (String) result.getResource(0).getContent();
    assertEquals("<a/>", r);
    r = (String) result.getResource(1).getContent();
    assertEquals("2", r);
    r = (String) result.getResource(2).getContent();
    assertEquals("3", r);
    query = "let $query1 := (<a/>)\n" + "let $query2 := (2, 3)\n" + "let $a := util:exclusive-lock((),($query1, $query2))\n" + "return $a";
    result = existEmbeddedServer.executeQuery(query);
    assertEquals(3, result.getSize());
    r = (String) result.getResource(0).getContent();
    assertEquals("<a/>", r);
    r = (String) result.getResource(1).getContent();
    assertEquals("2", r);
    r = (String) result.getResource(2).getContent();
    assertEquals("3", r);
    query = "let $query1 := (<a/>)\n" + "let $query2 := (2, 3)\n" + "let $a := util:exclusive-lock((),($query1, $query2))\n" + "return $a";
    result = existEmbeddedServer.executeQuery(query);
    assertEquals(3, result.getSize());
    r = (String) result.getResource(0).getContent();
    assertEquals("<a/>", r);
    r = (String) result.getResource(1).getContent();
    assertEquals("2", r);
    r = (String) result.getResource(2).getContent();
    assertEquals("3", r);
    query = "let $a := util:exclusive-lock(//*,<root/>)\n" + "return $a";
    result = existEmbeddedServer.executeQuery(query);
    r = (String) result.getResource(0).getContent();
    assertEquals("<root/>", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 82 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method sharedLock.

@Test
public void sharedLock() throws XPathException, XMLDBException {
    String query = "let $query1 := (<a/>)\n" + "let $query2 := (2, 3)\n" + "let $a := util:shared-lock(//*,($query1, $query2))\n" + "return $a";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    assertEquals(3, result.getSize());
    String r = (String) result.getResource(0).getContent();
    assertEquals("<a/>", r);
    r = (String) result.getResource(1).getContent();
    assertEquals("2", r);
    r = (String) result.getResource(2).getContent();
    assertEquals("3", r);
    query = "let $query1 := (<a/>)\n" + "let $query2 := (2, 3)\n" + "let $a := util:shared-lock((),($query1, $query2))\n" + "return $a";
    result = existEmbeddedServer.executeQuery(query);
    assertEquals(3, result.getSize());
    r = (String) result.getResource(0).getContent();
    assertEquals("<a/>", r);
    r = (String) result.getResource(1).getContent();
    assertEquals("2", r);
    r = (String) result.getResource(2).getContent();
    assertEquals("3", r);
    query = "let $query1 := (<a/>)\n" + "let $query2 := (2, 3)\n" + "let $a := util:shared-lock((),($query1, $query2))\n" + "return $a";
    result = existEmbeddedServer.executeQuery(query);
    assertEquals(3, result.getSize());
    r = (String) result.getResource(0).getContent();
    assertEquals("<a/>", r);
    r = (String) result.getResource(1).getContent();
    assertEquals("2", r);
    r = (String) result.getResource(2).getContent();
    assertEquals("3", r);
    query = "let $a := util:shared-lock(//*,<root/>)\n" + "return $a";
    result = existEmbeddedServer.executeQuery(query);
    r = (String) result.getResource(0).getContent();
    assertEquals("<root/>", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 83 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method data0.

@Test
public void data0() throws XMLDBException {
    final String query = "let $a := <a><b>1</b><b>1</b></a> " + "for $b in $a/b[data() = '1'] return $b";
    final ResourceSet result = existEmbeddedServer.executeQuery(query);
    assertEquals(2, result.getSize());
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 84 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method ceiling.

@Test
public void ceiling() throws XMLDBException {
    String query = "let $a := <a><b>-1</b><b>-2</b></a> " + "return $a/b[abs(ceiling(.))]";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    assertEquals(2, result.getSize());
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 85 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method stringJoin.

@Test
public void stringJoin() throws XMLDBException {
    String query = "let $s := ('','a','b','') " + "return string-join($s,'/')";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    String r = (String) result.getResource(0).getContent();
    assertEquals("/a/b/", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

ResourceSet (org.xmldb.api.base.ResourceSet)383 XPathQueryService (org.xmldb.api.modules.XPathQueryService)123 Test (org.junit.Test)117 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)100 XMLResource (org.xmldb.api.modules.XMLResource)80 Collection (org.xmldb.api.base.Collection)55 Resource (org.xmldb.api.base.Resource)45 XQueryService (org.xmldb.api.modules.XQueryService)29 XMLDBException (org.xmldb.api.base.XMLDBException)23 EXistResource (org.exist.xmldb.EXistResource)20 BinaryResource (org.xmldb.api.modules.BinaryResource)17 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 Node (org.w3c.dom.Node)11 IndexQueryService (org.exist.xmldb.IndexQueryService)9 Diff (org.xmlunit.diff.Diff)9 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)8 UserManagementService (org.exist.xmldb.UserManagementService)8 Source (javax.xml.transform.Source)7 ResourceIterator (org.xmldb.api.base.ResourceIterator)7 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)6