Search in sources :

Example 61 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class ProtectedModeTest method queryCollection.

@Test
public void queryCollection() throws XMLDBException {
    final Collection root = DatabaseManager.getCollection("xmldb:exist:///db/protected", "admin", "");
    final EXistXPathQueryService service = (EXistXPathQueryService) root.getService("XQueryService", "1.0");
    try {
        service.beginProtected();
        final ResourceSet result = service.query("collection('/db/protected/test5')//book");
        assertEquals(DOCUMENT_COUNT, result.getSize());
    } finally {
        service.endProtected();
    }
}
Also used : EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 62 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class ProtectedModeTest method queryRoot.

@Test
public void queryRoot() throws XMLDBException {
    final Collection root = DatabaseManager.getCollection("xmldb:exist:///db/protected", "admin", "");
    final EXistXPathQueryService service = (EXistXPathQueryService) root.getService("XQueryService", "1.0");
    try {
        service.beginProtected();
        final ResourceSet result = service.query("//book");
        assertEquals(COLLECTION_COUNT * DOCUMENT_COUNT, result.getSize());
    } finally {
        service.endProtected();
    }
}
Also used : EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 63 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class CollectionConfigurationValidationModeTest method storeDocument.

private void storeDocument(final String collection, final String name, final String document) throws XMLDBException {
    final ResourceSet result = existEmbeddedServer.executeQuery("xmldb:store(\"" + collection + "\", \"" + name + "\", " + document + ")");
    final String r = (String) result.getResource(0).getContent();
    assertEquals("Store doc", collection + "/" + name, r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 64 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class JavaFunctionsTest method lists.

/**
 * Tests simple list functions to make sure java functions are being
 * called properly
 */
@Test
public void lists() throws XPathException {
    try {
        String query = "declare namespace list='java:java.util.ArrayList'; " + "let $list := list:new() " + "let $actions := (list:add($list,'a'),list:add($list,'b'),list:add($list,'c')) " + "return list:get($list,1)";
        ResourceSet result = existEmbeddedServer.executeQuery(query);
        String r = (String) result.getResource(0).getContent();
        assertEquals("b", r);
    } catch (XMLDBException e) {
        // if exception is a java binding exception and java binding is disabled then this is a success
        if (e.getMessage().indexOf("Java binding is disabled in the current configuration") > -1 && !javabindingenabled) {
            return;
        }
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 65 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class OptimizerTest method execute.

private void execute(String query, boolean optimize, String message, long expected) throws XMLDBException {
    XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
    if (optimize) {
        query = NAMESPACES + OPTIMIZE + query;
    } else {
        query = NAMESPACES + NO_OPTIMIZE + query;
    }
    ResourceSet result = service.query(query);
    assertEquals(message, expected, result.getSize());
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

ResourceSet (org.xmldb.api.base.ResourceSet)383 XPathQueryService (org.xmldb.api.modules.XPathQueryService)123 Test (org.junit.Test)117 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)100 XMLResource (org.xmldb.api.modules.XMLResource)80 Collection (org.xmldb.api.base.Collection)55 Resource (org.xmldb.api.base.Resource)45 XQueryService (org.xmldb.api.modules.XQueryService)29 XMLDBException (org.xmldb.api.base.XMLDBException)23 EXistResource (org.exist.xmldb.EXistResource)20 BinaryResource (org.xmldb.api.modules.BinaryResource)17 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 Node (org.w3c.dom.Node)11 IndexQueryService (org.exist.xmldb.IndexQueryService)9 Diff (org.xmlunit.diff.Diff)9 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)8 UserManagementService (org.exist.xmldb.UserManagementService)8 Source (javax.xml.transform.Source)7 ResourceIterator (org.xmldb.api.base.ResourceIterator)7 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)6