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