use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class XQueryTriggerTest method documentBinaryDelete.
/**
* test a trigger fired by a Binary Document Delete
*/
@Test
public void documentBinaryDelete() throws XMLDBException {
final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
idxConf.configureCollection(COLLECTION_CONFIG);
// this will fire the trigger
final Resource res = testCollection.createResource(BINARY_DOCUMENT_NAME, "BinaryResource");
final byte[] content = Base64.decodeBase64(BINARY_DOCUMENT_CONTENT);
res.setContent(content);
testCollection.storeResource(res);
testCollection.removeResource(testCollection.getResource(BINARY_DOCUMENT_NAME));
idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
service.setProperty(OutputKeys.INDENT, "no");
ResourceSet result = service.query(BEFORE + CREATE + DOCUMENT + binaryURI);
assertEquals(1, result.getSize());
result = service.query(AFTER + CREATE + DOCUMENT + binaryURI);
assertEquals(1, result.getSize());
result = service.query(BEFORE + DELETE + DOCUMENT + binaryURI);
assertEquals(1, result.getSize());
result = service.query(AFTER + DELETE + DOCUMENT + binaryURI);
assertEquals(1, result.getSize());
result = service.query(EVENTS);
assertEquals(4, result.getSize());
// TODO: document itself
// result = service.query("/events/event[@id = 'trigger3'][@type = 'prepare'][collection = '" + DBBroker.ROOT_COLLECTION + "/" + TEST_COLLECTION + "'][uri = '" + DBBroker.ROOT_COLLECTION + "/" + TEST_COLLECTION + "/" + BINARY_DOCUMENT_NAME + "'][event = 'DELETE-DOCUMENT']/document");
// assertEquals(1, result.getSize());
// assertEquals("<document>" + BINARY_DOCUMENT_CONTENT + "</document>", result.getResource(0).getContent().toString());
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class ValueIndexTest method strings.
@Test
public void strings() throws XMLDBException, URISyntaxException {
configureCollection(CONFIG_PATH);
XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
queryResource(service, ITEMS_FILENAME, "//item[@id = 'i2']", 1);
queryResource(service, ITEMS_FILENAME, "//item[name = 'Racing Bicycle']", 1);
queryResource(service, ITEMS_FILENAME, "//item[name > 'Racing Bicycle']", 4);
queryResource(service, ITEMS_FILENAME, "//item[itemno = 3]", 1);
queryResource(service, ITEMS_FILENAME, "//item[itemno eq 3]", 1);
ResourceSet result = queryResource(service, ITEMS_FILENAME, "for $i in //item[stock <= 10] return $i/itemno", 5);
for (long i = 0; i < result.getSize(); i++) {
Resource res = result.getResource(i);
}
queryResource(service, ITEMS_FILENAME, "//item[stock > 20]", 1);
queryResource(service, ITEMS_FILENAME, "declare namespace x=\"http://www.foo.com\"; //item[x:rating > 8.0]", 2);
queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test = 123]", 1);
queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test eq 123]", 1);
queryResource(service, ITEMS_FILENAME, "//item[mixed = 'uneven']", 1);
queryResource(service, ITEMS_FILENAME, "//item[mixed eq 'uneven']", 1);
queryResource(service, ITEMS_FILENAME, "//item[mixed = 'external']", 1);
queryResource(service, ITEMS_FILENAME, "//item[fn:matches(mixed, 'un.*')]", 2);
queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = false()]", 2);
queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = true()]", 1);
queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice eq true()]", 1);
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class ConcurrencyTest method storeDocs.
private void storeDocs(final String collectionName) throws XMLDBException, IOException, URISyntaxException {
Collection collection = null;
try {
collection = existEmbeddedServer.createCollection(test, collectionName);
final IndexQueryService iqs = (IndexQueryService) collection.getService("IndexQueryService", "1.0");
iqs.configureCollection(COLLECTION_CONFIG1);
for (final String sampleName : SAMPLES.getShakespeareXmlSampleNames()) {
final Resource resource = collection.createResource(sampleName, XMLResource.RESOURCE_TYPE);
try (final InputStream is = SAMPLES.getShakespeareSample(sampleName)) {
resource.setContent(InputStreamUtil.readString(is, UTF_8));
}
collection.storeResource(resource);
}
} finally {
if (collection != null) {
collection.close();
}
}
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class CopyCollectionRecoveryTest method xmldbRead.
private void xmldbRead() throws XMLDBException {
final org.xmldb.api.base.Collection test = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/destination/test3", "admin", "");
assertNotNull(test);
final Resource res = test.getResource("test_xmldb.xml");
assertNotNull("Document should not be null", res);
final org.xmldb.api.base.Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, "admin", "");
assertNotNull(root);
final EXistCollectionManagementService mgr = (EXistCollectionManagementService) root.getService("CollectionManagementService", "1.0");
assertNotNull(mgr);
mgr.removeCollection("destination");
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class XmldbApiSecurityTest method chownRes.
@Override
protected void chownRes(final String resourceUri, final String owner_uid, final String group_gid, final String uid, final String pwd) throws ApiException {
Collection col = null;
try {
col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
final Resource resource = col.getResource(getResourceName(resourceUri));
final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
ums.chown(resource, ums.getAccount(owner_uid), group_gid);
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
} finally {
if (col != null) {
try {
col.close();
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
}
}
}
}
Aggregations