Search in sources :

Example 61 with XQueryService

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

the class UpdateValueTest method updateNamespacedAttribute.

@Test
public void updateNamespacedAttribute() throws XMLDBException {
    final String docName = "pathNs.xml";
    final XQueryService service = storeXMLStringAndGetQueryService(docName, "<test><t xml:id=\"id1\"/></test>");
    queryResource(service, docName, "//t[@xml:id eq 'id1']", 1);
    queryResource(service, docName, "update value //t/@xml:id with 'id2'", 0);
    queryResource(service, docName, "//t[@xml:id eq 'id2']", 1);
    queryResource(service, docName, "id('id2', /test)", 1);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Example 62 with XQueryService

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

the class UpdateValueTest method updateAttributeInNamespacedElement.

@Test
public void updateAttributeInNamespacedElement() throws XMLDBException {
    final String docName = "docNs.xml";
    final XQueryService service = storeXMLStringAndGetQueryService(docName, "<test xmlns=\"http://test.com\" id=\"id1\"/>");
    queryResource(service, docName, "declare namespace t=\"http://test.com\"; update value /t:test/@id with " + "'id2'", 0);
    queryResource(service, docName, "declare namespace t=\"http://test.com\"; /t:test[@id = 'id2']", 1);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Example 63 with XQueryService

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

the class MapTest method effectiveBooleanValue.

@Test
public void effectiveBooleanValue() {
    try {
        final XQueryService queryService = (XQueryService) server.getRoot().getService("XQueryService", "1.0");
        queryService.query("fn:boolean(map{})");
    } catch (final XMLDBException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof XPathException) {
            final XPathException xpe = (XPathException) cause;
            assertEquals(ErrorCodes.FORG0006, xpe.getErrorCode());
            return;
        }
    }
    fail("effectiveBooleanValue of a map should cause the error FORG0006");
}
Also used : XPathException(org.exist.xquery.XPathException) XQueryService(org.xmldb.api.modules.XQueryService) XMLDBException(org.xmldb.api.base.XMLDBException) Test(org.junit.Test)

Example 64 with XQueryService

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

the class UpdateReplaceTest method replaceOnlyChildWhereParentHasNoAttributes.

@Test
public void replaceOnlyChildWhereParentHasNoAttributes() throws XMLDBException {
    final String testDocName = "replaceOnlyChildWhereParentHasNoAttributes.xml";
    final String testDoc = "<Test><Content><A/></Content></Test>";
    final String updateQuery = "let $content := doc('/db/test/" + testDocName + "')/Test/Content\n" + "    let $legacy := $content/A\n" + "    return\n" + "      update replace $legacy with <AA/>,\n" + "    doc('/db/test/" + testDocName + "')/Test";
    final XQueryService xqueryService = storeXMLStringAndGetQueryService(testDocName, testDoc);
    final ResourceSet result = xqueryService.query(updateQuery);
    assertNotNull(result);
    assertEquals(1, result.getSize());
    final Resource res1 = result.getResource(0);
    assertNotNull(res1);
    assertEquals(XMLResource.RESOURCE_TYPE, res1.getResourceType());
    final Document doc = ((XMLResource) res1).getContentAsDOM().getOwnerDocument();
    final Source actual = Input.fromDocument(doc).build();
    final Source expected = Input.fromString("<Test><Content><AA/></Content></Test>").build();
    final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
    assertFalse(diff.toString(), diff.hasDifferences());
}
Also used : Diff(org.xmlunit.diff.Diff) XQueryService(org.xmldb.api.modules.XQueryService) EXistResource(org.exist.xmldb.EXistResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Document(org.w3c.dom.Document) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 65 with XQueryService

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

the class UpdateReplaceTest method replaceFirstChildWhereParentHasNoAttributes.

@Test
public void replaceFirstChildWhereParentHasNoAttributes() throws XMLDBException {
    final String testDocName = "replaceFirstChildWhereParentHasNoAttributes.xml";
    final String testDoc = "<Test><Content><A/><A/></Content></Test>";
    final String updateQuery = "let $content := doc('/db/test/" + testDocName + "')/Test/Content\n" + "    let $legacy := $content/A[1]\n" + "    return\n" + "      update replace $legacy with <AA/>,\n" + "    doc('/db/test/" + testDocName + "')/Test";
    final XQueryService xqueryService = storeXMLStringAndGetQueryService(testDocName, testDoc);
    final ResourceSet result = xqueryService.query(updateQuery);
    assertNotNull(result);
    assertEquals(1, result.getSize());
    final Resource res1 = result.getResource(0);
    assertNotNull(res1);
    assertEquals(XMLResource.RESOURCE_TYPE, res1.getResourceType());
    final Document doc = ((XMLResource) res1).getContentAsDOM().getOwnerDocument();
    final Source actual = Input.fromDocument(doc).build();
    final Source expected = Input.fromString("<Test><Content><AA/><A/></Content></Test>").build();
    final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
    assertFalse(diff.toString(), diff.hasDifferences());
}
Also used : Diff(org.xmlunit.diff.Diff) XQueryService(org.xmldb.api.modules.XQueryService) EXistResource(org.exist.xmldb.EXistResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Document(org.w3c.dom.Document) Source(javax.xml.transform.Source) 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