Search in sources :

Example 66 with XQueryService

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

the class DuplicateAttributesTest method appendConstrAttr.

/**
 * Add constructed in-memory attribute to element which already has an
 * attribute of that name.
 */
@Test(expected = XMLDBException.class)
public void appendConstrAttr() throws XMLDBException {
    XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
    String query = "let $a := <root attr=\"ab\"/>" + "let $b := \n" + "   <node attr=\"a\" b=\"c\">{$a//@attr}</node>" + "return $a";
    xqs.query(query);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Example 67 with XQueryService

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

the class DuplicateAttributesTest method appendStoredAttrOK.

/**
 * Add attribute to element which has no conflicting attributes.
 */
@Test
public void appendStoredAttrOK() {
    try {
        XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
        String query = "let $a := \n" + "<node attr=\"a\" b=\"c\">{doc(\"/db/test/stored2.xml\")//@attr2}</node>" + "return $a";
        ResourceSet result = xqs.query(query);
        assertEquals(1, result.getSize());
        assertEquals("<node attr=\"a\" b=\"c\" attr2=\"ab\"/>", result.getResource(0).getContent());
    } catch (XMLDBException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLDBException(org.xmldb.api.base.XMLDBException) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 68 with XQueryService

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

the class EntitiesTest method uriConstructor.

@Test
public void uriConstructor() throws XMLDBException {
    XQueryService service = getQueryService();
    ResourceSet result;
    result = queryAndAssert(service, "xs:anyURI(\"index.xql?a=1&amp;b=2\")", 1, null);
    // TODO: could check result
    result = queryAndAssert(service, "xs:anyURI('a') le xs:anyURI('b')", 1, null);
    assertEquals("true", result.getResource(0).getContent());
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Example 69 with XQueryService

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

the class EntitiesTest method storeXMLStringAndGetQueryService.

/**
 * stores XML String and get Query Service
 * @param documentName to be stored in the DB
 * @param content to be stored in the DB
 * @return the XQuery Service
 * @throws XMLDBException
 */
@SuppressWarnings("unused")
private XQueryService storeXMLStringAndGetQueryService(String documentName, String content) throws XMLDBException {
    XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
    doc.setContent(content);
    testCollection.storeResource(doc);
    XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
    return service;
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 70 with XQueryService

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

the class EntitiesTest method stringConstructor.

@Test
public void stringConstructor() throws XMLDBException {
    XQueryService service = getQueryService();
    @SuppressWarnings("unused") ResourceSet result;
    result = queryAndAssert(service, "'&amp;'", 1, null);
    result = queryAndAssert(service, "'&lt;'", 1, null);
    result = queryAndAssert(service, "'&gt;'", 1, null);
    result = queryAndAssert(service, "'&apos;'", 1, null);
    result = queryAndAssert(service, "'&quot;'", 1, null);
// TODO: could check result
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Aggregations

XQueryService (org.xmldb.api.modules.XQueryService)129 EXistXQueryService (org.exist.xmldb.EXistXQueryService)71 XMLResource (org.xmldb.api.modules.XMLResource)33 ResourceSet (org.xmldb.api.base.ResourceSet)29 Test (org.junit.Test)28 Resource (org.xmldb.api.base.Resource)8 Node (org.w3c.dom.Node)6 EXistResource (org.exist.xmldb.EXistResource)5 Document (org.w3c.dom.Document)5 Collection (org.xmldb.api.base.Collection)5 Source (javax.xml.transform.Source)4 IndexQueryService (org.exist.xmldb.IndexQueryService)4 CompiledExpression (org.xmldb.api.base.CompiledExpression)4 XMLDBException (org.xmldb.api.base.XMLDBException)4 Diff (org.xmlunit.diff.Diff)4 Path (java.nio.file.Path)2 XmlRpcTest (org.exist.xmlrpc.XmlRpcTest)2 StringWriter (java.io.StringWriter)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1