Search in sources :

Example 11 with ResourceSet

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

the class SerializationTest method xqueryUpdateNsTest.

@Test
public void xqueryUpdateNsTest() throws XMLDBException {
    final XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
    final ResourceSet result = service.query("xquery version \"1.0\";" + EOL + "declare namespace foo=\"http://foo.com\";" + EOL + "let $in-memory :=" + EOL + XML + EOL + "let $on-disk := doc('/db/" + TEST_COLLECTION_NAME + '/' + XML_DOC_NAME + "')" + EOL + "let $new-node := <entry xml:id='aargh'/>" + EOL + "let $update := update insert $new-node into $on-disk/foo:root" + EOL + "return" + EOL + "    (" + EOL + "        $in-memory," + EOL + "        $on-disk" + EOL + "    )" + EOL);
    assertEquals(2, result.getSize());
    final Resource inMemoryResource = result.getResource(0);
    assertXMLEquals(XML, inMemoryResource);
    final Resource onDiskResource = result.getResource(1);
    assertXMLEquals(XML_UPDATED_EXPECTED, onDiskResource);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 12 with ResourceSet

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

the class CollectionConfigurationTest method rangeIndex2.

@Test
@Ignore
public void rangeIndex2() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    // Configure collection automatically
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(QNAME_CONFIG2);
    // ... 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");
    ResourceSet result = service.query("util:index-key-occurrences(/test/c, xs:dateTime(\"2002-12-07T12:20:46.275+01:00\") )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/c)");
    assertEquals("xs:dateTime", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/d, xs:double(1) )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/d)");
    assertEquals("xs:double", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/e, xs:float(1) )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/e)");
    assertEquals("xs:float", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/f, true())");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/f)");
    assertEquals("xs:boolean", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/g, xs:integer(1))");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/g)");
    assertEquals("xs:integer", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/h, '1')");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/h)");
    assertEquals("xs:string", result.getResource(0).getContent());
    result = service.query("(# exist:force-index-use #) { /test/c[. = xs:dateTime(\"2002-12-07T12:20:46.275+01:00\")] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[c = xs:dateTime(\"2002-12-07T12:20:46.275+01:00\")] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/d[. = xs:double(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[d = xs:double(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/e[. = xs:float(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[e = xs:float(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/f[. = true()] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[f = true()] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/g[. = 1] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[g = 1] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/h[. = '1'] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[h = '1'] }");
    assertEquals(1, result.getSize());
    boolean exceptionCaught = false;
    try {
        result = service.query("(# exist:force-index-use #) { /test[contains(d, '1')] }");
        assertEquals(0, result.getSize());
    } catch (XMLDBException e) {
        exceptionCaught = true;
    }
    assertTrue("contains() should not use index of type xs:double", exceptionCaught);
    exceptionCaught = false;
    try {
        result = service.query("(# exist:force-index-use #) { /test[matches(d, '1')] }");
        assertEquals(0, result.getSize());
    } catch (XMLDBException e) {
        exceptionCaught = true;
    }
    assertTrue("matches() should not use index of type xs:double", exceptionCaught);
    result = service.query("/test[matches(h, '1')]");
    assertEquals(1, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 13 with ResourceSet

use of org.xmldb.api.base.ResourceSet 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 14 with ResourceSet

use of org.xmldb.api.base.ResourceSet 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 15 with ResourceSet

use of org.xmldb.api.base.ResourceSet 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)

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