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);
}
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);
}
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");
}
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());
}
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());
}
Aggregations