Search in sources :

Example 51 with XQueryService

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();
    }
}
Also used : IMocksControl(org.easymock.IMocksControl) DBBroker(org.exist.storage.DBBroker) XQueryService(org.xmldb.api.modules.XQueryService) XQueryContext(org.exist.xquery.XQueryContext) BrokerPool(org.exist.storage.BrokerPool)

Example 52 with XQueryService

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);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Example 53 with XQueryService

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);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Example 54 with XQueryService

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());
}
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 55 with XQueryService

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