Search in sources :

Example 21 with XMLResource

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

the class CollectionConfigurationTest method missingRangeIndexes.

@Test
public void missingRangeIndexes() throws Exception {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    @SuppressWarnings("unused") ResourceSet result;
    boolean exceptionThrown = false;
    // Configure collection automatically
    @SuppressWarnings("unused") IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    // ... then index document
    XMLResource doc = (XMLResource) testCollection.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT2);
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    try {
        exceptionThrown = false;
        result = service.query("/test/c[(# exist:force-index-use #) { . = xs:dateTime(\"2002-12-07T12:20:46.275+01:00\") }]");
    } catch (Exception e) {
        // e.printStackTrace();
        if (e.getMessage().indexOf("XQDYxxxx") != Constants.STRING_NOT_FOUND)
            exceptionThrown = true;
        else
            throw e;
    }
    assertTrue("Exception expected : missing index", exceptionThrown);
    try {
        exceptionThrown = false;
        result = service.query("/test/d[(# exist:force-index-use #) { . = xs:double(1) }]");
    } catch (Exception e) {
        if (e.getMessage().indexOf("XQDYxxxx") != Constants.STRING_NOT_FOUND)
            exceptionThrown = true;
        else
            throw e;
    }
    assertTrue("Exception expected : missing index", exceptionThrown);
    try {
        exceptionThrown = false;
        result = service.query("/test/e[(# exist:force-index-use #) { . = xs:float(1) }]");
    } catch (Exception e) {
        if (e.getMessage().indexOf("XQDYxxxx") != Constants.STRING_NOT_FOUND)
            exceptionThrown = true;
        else
            throw e;
    }
    assertTrue("Exception expected : missing index", exceptionThrown);
    try {
        exceptionThrown = false;
        result = service.query("/test/f[(# exist:force-index-use #) { . = true() }]");
    } catch (Exception e) {
        if (e.getMessage().indexOf("XQDYxxxx") != Constants.STRING_NOT_FOUND)
            exceptionThrown = true;
        else
            throw e;
    }
    assertTrue("Exception expected : missing index", exceptionThrown);
    try {
        exceptionThrown = false;
        result = service.query("/test/g[(# exist:force-index-use #) { . = 1 }]");
    } catch (Exception e) {
        if (e.getMessage().indexOf("XQDYxxxx") != Constants.STRING_NOT_FOUND)
            exceptionThrown = true;
        else
            throw e;
    }
    assertTrue("Exception expected : missing index", exceptionThrown);
    try {
        exceptionThrown = false;
        result = service.query("/test/h[(# exist:force-index-use #) { . = '1' }]");
    } catch (Exception e) {
        if (e.getMessage().indexOf("XQDYxxxx") != Constants.STRING_NOT_FOUND)
            exceptionThrown = true;
        else
            throw e;
    }
    assertTrue("Exception expected : missing index", exceptionThrown);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 22 with XMLResource

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

the class CollectionConfigurationTest method collectionConfigurationService8.

/**
 * Overwrite configuration in a sub collection
 */
@Test
public void collectionConfigurationService8() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    CollectionManagementService cms = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
    Collection sub2 = cms.createCollection(COLLECTION_SUB2.toString());
    UserManagementService ums = (UserManagementService) sub2.getService("UserManagementService", "1.0");
    ums.chmod("rwxr-xr-x");
    // Configure collection automatically
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(CONFIG1);
    // Overwrite main configuration with an empty configuration in the subcollection
    idxConf = (IndexQueryService) sub2.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(EMPTY_CONFIG);
    // ... then index document
    XMLResource doc = (XMLResource) sub2.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    sub2.storeResource(doc);
    XPathQueryService service = (XPathQueryService) sub2.getService("XPathQueryService", "1.0");
    // index should be empty
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals(0, result.getSize());
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals(0, result.getSize());
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(0, result.getSize());
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(0, result.getSize());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 23 with XMLResource

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

the class CollectionConfigurationTest method invalidConfiguration1.

@Test
public void invalidConfiguration1() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    CollectionManagementService cms = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
    Collection sub2 = cms.createCollection(COLLECTION_SUB2.toString());
    UserManagementService ums = (UserManagementService) sub2.getService("UserManagementService", "1.0");
    ums.chmod("rwxr-xr-x");
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(INVALID_CONFIG1);
    // ... then index document
    XMLResource doc = (XMLResource) sub2.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    sub2.storeResource(doc);
    XPathQueryService service = (XPathQueryService) sub2.getService("XPathQueryService", "1.0");
    // index should be empty since configuration was invalid
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals(0, result.getSize());
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(0, result.getSize());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 24 with XMLResource

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

the class AbstractTestUpdate method storeXMLStringAndGetQueryService.

/**
 * stores XML String and get Query Service
 * @param documentName to be stored in the DB
 * @param content to be stored in the DB
 * @return the XQuery Service
 * @throws XMLDBException
 */
protected XQueryService storeXMLStringAndGetQueryService(final String documentName, final String content) throws XMLDBException {
    final XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
    doc.setContent(content);
    testCollection.storeResource(doc);
    final XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
    return service;
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 25 with XMLResource

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

the class ExpandTest method expandPersistentDomAttr.

@Test
public void expandPersistentDomAttr() throws XMLDBException {
    final String query = "util:expand(doc('/db/expand-test/doc3.xml')/doc3/@foo)";
    final ResourceSet result = existEmbeddedServer.executeQuery(query);
    final Resource res = result.getResource(0);
    assertEquals(XMLResource.RESOURCE_TYPE, res.getResourceType());
    final XMLResource xmlRes = (XMLResource) res;
    final Node node = xmlRes.getContentAsDOM();
    assertEquals(Node.ATTRIBUTE_NODE, node.getNodeType());
    assertNull(node.getNamespaceURI());
    assertEquals("foo", node.getNodeName());
    assertEquals("bar", node.getNodeValue());
}
Also used : Node(org.w3c.dom.Node) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource) Test(org.junit.Test)

Aggregations

XMLResource (org.xmldb.api.modules.XMLResource)142 Collection (org.xmldb.api.base.Collection)56 ResourceSet (org.xmldb.api.base.ResourceSet)56 XPathQueryService (org.xmldb.api.modules.XPathQueryService)49 Test (org.junit.Test)33 Resource (org.xmldb.api.base.Resource)24 XQueryService (org.xmldb.api.modules.XQueryService)23 Node (org.w3c.dom.Node)22 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)20 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)18 Document (org.w3c.dom.Document)16 XMLDBException (org.xmldb.api.base.XMLDBException)15 EXistResource (org.exist.xmldb.EXistResource)9 EXistXQueryService (org.exist.xmldb.EXistXQueryService)9 BinaryResource (org.xmldb.api.modules.BinaryResource)9 Path (java.nio.file.Path)8 Before (org.junit.Before)8 Element (org.w3c.dom.Element)8 Source (javax.xml.transform.Source)7 SAXSerializer (org.exist.util.serializer.SAXSerializer)7