Search in sources :

Example 61 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method predicatePositionLast_1665213.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1665213
 */
@Test
public void predicatePositionLast_1665213() throws XMLDBException {
    // OK, regression
    String query = "(1, 2, 3)[ position() = last() ]";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals("First", "3", result.getResource(0).getContent().toString());
    query = "(1, 2, 3)[(position()=last() and position() < 4)]";
    service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals("First", "3", result.getResource(0).getContent().toString());
    query = "(1, 2, 3)[(position()=last())]";
    service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals("First", "3", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 62 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method documentNode_1730690.

@Test
public void documentNode_1730690() throws XMLDBException {
    String query = "let $doc := document { <element/> } " + "return $doc/root() instance of document-node()";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals("true", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 63 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method asDouble_1840775.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1840775
 *
 * Same as {@link #wrongAttributeTypeCheck_1805612()}
 */
@Ignore
@Test
public void asDouble_1840775() throws XMLDBException {
    String query = "declare function local:testCase($failure as element(Failure)?)" + "as element(TestCase) { <TestCase/> };" + "local:testCase(" + "(: work-around for this eXist 1.1.2dev-rev:6992-20071127 bug: let $ltValue := 0.0 :)" + "let $ltValue as xs:double := 0.0e0 return <Failure/>)";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    service.query(query);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService)

Example 64 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method testFor.

@Test
public void testFor() throws XMLDBException {
    ResourceSet result;
    String query;
    XMLResource resu;
    XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
    query = "for $f in /*/item return $f";
    result = service.queryResource(NUMBERS_XML, query);
    assertEquals("XQuery: " + query, 4, result.getSize());
    query = "for $f in /*/item  order by $f ascending  return $f";
    result = service.queryResource(NUMBERS_XML, query);
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "3", ((Element) resu.getContentAsDOM()).getAttribute("id"));
    query = "for $f in /*/item  order by $f descending  return $f";
    result = service.queryResource(NUMBERS_XML, query);
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "2", ((Element) resu.getContentAsDOM()).getAttribute("id"));
    query = "for $f in /*/item  order by xs:double($f/price) descending  return $f";
    result = service.queryResource(NUMBERS_XML, query);
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "4", ((Element) resu.getContentAsDOM()).getAttribute("id"));
    query = "for $f in //item where $f/@id = '3' return $f";
    result = service.queryResource(NUMBERS_XML, query);
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "3", ((Element) resu.getContentAsDOM()).getAttribute("id"));
    // Non null context sequence
    query = "/test/item[for $id in ./@id return $id]";
    result = service.queryResource(NUMBERS_XML, query);
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, 4, result.getSize());
    // Ordered value sequence
    query = "let $doc := <doc><value>Z</value><value>Y</value><value>X</value></doc> " + "return " + "let $ordered_values := " + "	for $value in $doc/value order by $value ascending " + "	return $value " + "for $value in $doc/value " + "	return $value[. = $ordered_values[position() = 1]]";
    result = service.queryResource(NUMBERS_XML, query);
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "<value>X</value>", resu.getContent());
    // Ordered value sequence
    query = "for $e in (1) order by $e return $e";
    result = service.queryResource(NUMBERS_XML, query);
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "1", resu.getContent());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 65 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method divYieldsWrongInf_1816496.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1816496
 */
@Test
public void divYieldsWrongInf_1816496() throws XMLDBException {
    String query = "let $negativeZero := xs:double(-1.0e-1024) let $positiveZero := xs:double(1.0e-1024) " + "return (" + "(xs:double(1)  div xs:double(0)),   (xs:double(1)  div $positiveZero),  (xs:double(1)  div $negativeZero), " + "(xs:double(-1) div xs:double(0)),   (xs:double(-1) div $positiveZero),  (xs:double(-1) div $negativeZero), " + "($negativeZero div $positiveZero),  ($positiveZero div $negativeZero), " + "(xs:double(0) div $positiveZero),   (xs:double(0) div $negativeZero),  " + "(xs:double(0) div xs:double(0))  " + ")";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(11, result.getSize());
    assertEquals(query, "INF", result.getResource(0).getContent().toString());
    assertEquals(query, "INF", result.getResource(1).getContent().toString());
    assertEquals(query, "-INF", result.getResource(2).getContent().toString());
    assertEquals(query, "-INF", result.getResource(3).getContent().toString());
    assertEquals(query, "-INF", result.getResource(4).getContent().toString());
    assertEquals(query, "INF", result.getResource(5).getContent().toString());
    assertEquals(query, "NaN", result.getResource(6).getContent().toString());
    assertEquals(query, "NaN", result.getResource(7).getContent().toString());
    assertEquals(query, "NaN", result.getResource(8).getContent().toString());
    assertEquals(query, "NaN", result.getResource(9).getContent().toString());
    assertEquals(query, "NaN", result.getResource(10).getContent().toString());
    query = "xs:float(2) div xs:float(0)";
    service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals(query, "INF", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

XPathQueryService (org.xmldb.api.modules.XPathQueryService)148 ResourceSet (org.xmldb.api.base.ResourceSet)123 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)92 XMLResource (org.xmldb.api.modules.XMLResource)60 Collection (org.xmldb.api.base.Collection)31 Test (org.junit.Test)22 Resource (org.xmldb.api.base.Resource)18 XMLDBException (org.xmldb.api.base.XMLDBException)14 EXistResource (org.exist.xmldb.EXistResource)10 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)9 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)8 IndexQueryService (org.exist.xmldb.IndexQueryService)6 IOException (java.io.IOException)3 ResourceIterator (org.xmldb.api.base.ResourceIterator)3 BinaryResource (org.xmldb.api.modules.BinaryResource)3 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Node (org.w3c.dom.Node)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1