Search in sources :

Example 11 with XMLResource

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

the class CollectionConfigurationTest method collectionConfigurationService6.

@Test
public void collectionConfigurationService6() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    // Add document....
    XMLResource doc = (XMLResource) testCollection.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    testCollection.storeResource(doc);
    // ... then configure collection *manually*
    XmldbURI configurationFileName = XmldbURI.create(CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE);
    storeConfiguration(CONF_COLL_URI, configurationFileName, CONFIG1);
    // ... then configure collection automatically
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(CONFIG1);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    // our config file
    ResourceSet result = service.query("xmldb:get-child-resources('" + CONF_COLL_URI + "')");
    assertEquals(configurationFileName.toString(), result.getResource(0).getContent());
    // No numeric values because we have no index
    result = service.query("util:index-key-occurrences( /test/a, 1 ) ");
    assertEquals(0, result.getSize());
    // No string value because we have no index
    result = service.query("util:index-key-occurrences( /test/b, \"1\" ) ");
    assertEquals(0, result.getSize());
    // No numeric values because we have no index
    result = service.query("util:qname-index-lookup( xs:QName(\"a\"), 1 ) ");
    assertEquals(0, result.getSize());
    // No string value because we have no index
    result = service.query("util:qname-index-lookup( xs:QName(\"b\"), \"1\" ) ");
    assertEquals(0, result.getSize());
    // ...let's activate the index
    idxConf.reindexCollection();
    // WARNING : the code hereafter used to *not* work whereas
    // testCollectionConfigurationService4 did.
    // Adding confMgr.invalidateAll(getName()); in Collection.storeInternal solved the problem
    // Strange case that needs investigations... -pb
    // 3 numeric values
    result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals("3", result.getResource(0).getContent());
    // ... but 1 string value
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals("1", result.getResource(0).getContent());
    // 3 numeric values
    result = service.query("util:qname-index-lookup( xs:QName(\"a\"), 1 ) ");
    assertEquals(3, result.getSize());
    // ... but 1 string value
    result = service.query("util:qname-index-lookup( xs:QName(\"b\"), \"1\" ) ");
    assertEquals(1, result.getSize());
}
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)

Example 12 with XMLResource

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

the class CollectionConfigurationTest method collectionConfigurationService10.

/**
 * Remove config document
 */
@Test
public void collectionConfigurationService10() 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(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");
    // 3 numeric values
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals("3", result.getResource(0).getContent());
    // ... but 1 string value
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals("1", result.getResource(0).getContent());
    // 3 numeric values
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(3, result.getSize());
    // ... but 1 string value
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(1, result.getSize());
    // remove config document thus dropping the configuration
    Collection confCol = DatabaseManager.getCollection("xmldb:exist://" + CONF_COLL_URI.toString(), ADMIN_DB_USER, ADMIN_DB_PWD);
    Resource confDoc = confCol.getResource(DEFAULT_COLLECTION_CONFIG_FILE);
    assertNotNull(confDoc);
    confCol.removeResource(confDoc);
    // cms = (CollectionManagementService) confCol.getService("CollectionManagementService", "1.0");
    // cms.removeCollection(".");
    idxConf.reindexCollection();
    // index should be empty since configuration was removed
    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) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 13 with XMLResource

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

the class CollectionConfigurationTest method collectionConfigurationService3.

@Test
public void collectionConfigurationService3() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    // Configure collection *manually*
    storeConfiguration(CONF_COLL_URI, CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE_URI, CONFIG1);
    // ... then index document
    XMLResource doc = (XMLResource) testCollection.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    // 3 numeric values
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals(1, result.getSize());
    assertEquals("3", result.getResource(0).getContent());
    // ... but 1 string value
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    // 3 numeric values
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(3, result.getSize());
    // ... but 1 string value
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(1, result.getSize());
}
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)

Example 14 with XMLResource

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

the class CollectionConfigurationTest method collectionConfigurationService7.

/**
 * Check if configurations are properly passed down the collection hierarchy.
 */
@Test
public void collectionConfigurationService7() 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
    // sub2 should inherit its index configuration from the top collection
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(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");
    // 3 numeric values
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals("3", result.getResource(0).getContent());
    // ... but 1 string value
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals("1", result.getResource(0).getContent());
    // 3 numeric values
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(3, result.getSize());
    // ... but 1 string value
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(1, 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 XMLResource

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

the class CollectionConfigurationTest method collectionConfigurationService1.

@Test
public void collectionConfigurationService1() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    // Configure collection automatically
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(CONFIG1);
    // ... then index document
    XMLResource doc = (XMLResource) testCollection.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    // 3 numeric values
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals("3", result.getResource(0).getContent());
    // ... but 1 string value
    result = service.query("util:index-key-occurrences(/test/b, \"1\")");
    assertEquals("1", result.getResource(0).getContent());
    // 3 numeric values
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(3, result.getSize());
    // ... but 1 string value
    result = service.query("util:qname-index-lookup(xs:QName(\"b\"), \"1\" ) ");
    assertEquals(1, result.getSize());
}
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)

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