use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class IndexIntegrationTest method run.
private void run(final XmldbURI docUri, final String data, final BiConsumer<IndexWorker, StreamListener> setup, ConsumerE<XQueryService, XMLDBException> test) throws Exception {
final XQueryService service = storeXMLStringAndGetQueryService(docUri.lastSegment().toString(), data);
final IMocksControl control = createStrictControl();
final IndexWorker worker = control.createMock(IndexWorker.class);
final StreamListener stream = control.createMock(AbstractStreamListener.class);
final AbstractIndex index = new TestIndex(worker);
final BrokerPool pool = BrokerPool.getInstance();
expect(worker.getIndexId()).andReturn("TestIndex").anyTimes();
control.replay();
pool.getIndexManager().registerIndex(index);
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
control.verify();
control.resetToStrict();
// common
expect(worker.getQueryRewriter(anyObject(XQueryContext.class))).andStubReturn(null);
expect(worker.getIndexName()).andStubReturn("TestIndex");
expect(worker.getListener()).andStubReturn(stream);
stream.setNextInChain(anyObject());
expectLastCall().asStub();
setup.accept(worker, stream);
control.replay();
test.accept(service);
control.verify();
control.resetToStrict();
index.close();
pool.getIndexManager().unregisterIndex(index);
} finally {
control.resetToStrict();
}
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class UpdateInsertTest method insertPrecedingAttribute.
@Test
public void insertPrecedingAttribute() throws XMLDBException {
final String tempId = "tmp-1512257166656";
final String doc = "<annotation-list>" + EOL + " <annotation-item generator=\"earlyPrint\" status=\"pending\" visibility=\"public\" temp-id=\"" + tempId + "\" reason=\"\" creator=\"craig\" created=\"2017-12-02T23:26:06.656Z\" modified=\"2017-12-02T23:26:06.656Z\" generated=\"2017-12-02T23:26:06.656Z\" ticket=\"s-1512257166639\">" + EOL + " <annotation-body subtype=\"update\" format=\"text/xml\" type=\"TEI\" original-value=\"Worthies\">" + EOL + " <w>test123</w>" + EOL + " </annotation-body>" + EOL + " <annotation-target source=\"A00969\" version=\"\">" + EOL + " <target-selector type=\"IdSelector\" value=\"A00969-001-b-0240\"/>" + EOL + " </annotation-target>" + EOL + " </annotation-item>" + EOL + "</annotation-list>";
final String docName = "A00969_annotations.xml";
final XQueryService service = storeXMLStringAndGetQueryService(docName, doc);
queryResource(service, docName, "//annotation-item[@temp-id = '" + tempId + "']/@status", 1);
queryResource(service, docName, "//annotation-item[@temp-id = '" + tempId + "']/@id", 0);
final String uuid = UUID.randomUUID().toString();
final String update = "update insert attribute id {'" + uuid + "'} preceding //annotation-item[@temp-id = '" + tempId + "']/@status";
queryResource(service, docName, update, 0);
queryResource(service, docName, "//annotation-item[@temp-id = '" + tempId + "']/@id", 1);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class UpdateInsertTest method insertInMemoryDocument.
@Test
public void insertInMemoryDocument() throws XMLDBException {
final String doc = "<empty/>";
final String docName = "empty.xml";
final XQueryService service = storeXMLStringAndGetQueryService(docName, doc);
queryResource(service, docName, "//empty/child::node()", 0);
final String uuid = UUID.randomUUID().toString();
final String update = "update insert document { <uuid>" + uuid + "</uuid> } into /empty";
queryResource(service, docName, update, 0);
queryResource(service, docName, "//empty/uuid", 1);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class UpdateReplaceTest method replaceOnlyChildWhereParentHasAttribute.
@Test
public void replaceOnlyChildWhereParentHasAttribute() throws XMLDBException {
final String testDocName = "replaceOnlyChildWhereParentHasAttribute.xml";
final String testDoc = "<Test><Content Foo=\"bar\"><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 Foo='bar'><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 replaceFirstChildWhereParentHasAttribute.
@Test
public void replaceFirstChildWhereParentHasAttribute() throws XMLDBException {
final String testDocName = "replaceFirstChildWhereParentHasAttribute.xml";
final String testDoc = "<Test><Content Foo=\"bar\"><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 Foo='bar'><AA/><A/></Content></Test>").build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
Aggregations