use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class CreateCollectionsTest method testMultipleCreates.
@Test
public void testMultipleCreates() throws XMLDBException {
Collection testCol = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
CollectionManagementService cms = (CollectionManagementService) testCol.getService("CollectionManagementService", "1.0");
assertNotNull(cms);
cms.createCollection("dummy1");
Collection c1 = testCol.getChildCollection("dummy1");
assertNotNull(c1);
cms.setCollection(c1);
cms.createCollection("dummy2");
Collection c2 = c1.getChildCollection("dummy2");
assertNotNull(c2);
cms.setCollection(c2);
cms.createCollection("dummy3");
Collection c3 = c2.getChildCollection("dummy3");
assertNotNull(c3);
cms.setCollection(testCol);
cms.removeCollection("dummy1");
c1 = testCol.getChildCollection("dummy1");
assertNull(c1);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class CreateCollectionsTest method storeRemoveStoreResource.
@Test
public void storeRemoveStoreResource() throws XMLDBException, IOException, URISyntaxException {
final Collection colTest = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
final CollectionManagementService service = (CollectionManagementService) colTest.getService("CollectionManagementService", "1.0");
final Collection testCollection = service.createCollection("test");
UserManagementService ums = (UserManagementService) testCollection.getService("UserManagementService", "1.0");
ums.chmod("rwxr-xr-x");
final String testFile = "macbeth.xml";
try (final InputStream is = SAMPLES.getMacbethSample()) {
storeResourceFromFile(is, testCollection, testFile);
}
Resource resMacbeth = testCollection.getResource(testFile);
assertNotNull("getResource(" + testFile + "\")", resMacbeth);
final int resourceCount = testCollection.getResourceCount();
testCollection.removeResource(resMacbeth);
assertEquals("After removal resource count must decrease", resourceCount - 1, testCollection.getResourceCount());
resMacbeth = testCollection.getResource(testFile);
assertNull(resMacbeth);
// restore the resource just removed
try (final InputStream is = SAMPLES.getMacbethSample()) {
storeResourceFromFile(is, testCollection, testFile);
}
assertEquals("After re-store resource count must increase", resourceCount, testCollection.getResourceCount());
resMacbeth = testCollection.getResource(testFile);
assertNotNull("getResource(" + testFile + "\")", resMacbeth);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class IndexingTest method irregularilyStructured.
private void irregularilyStructured(boolean getContentAsDOM) throws XMLDBException, ParserConfigurationException, SAXException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Database database = null;
final String testName = "IrregularilyStructured";
startTime = System.currentTimeMillis();
Collection coll = DatabaseManager.getCollection(baseURI, username, password);
XMLResource resource = (XMLResource) coll.createResource(name, XMLResource.RESOURCE_TYPE);
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
effectiveSiblingCount = populate(doc);
resource.setContentAsDOM(doc);
coll.storeResource(resource);
coll.close();
coll = DatabaseManager.getCollection(baseURI, username, password);
resource = (XMLResource) coll.getResource(name);
Node n;
if (getContentAsDOM) {
n = resource.getContentAsDOM();
} else {
String s = (String) resource.getContent();
byte[] bytes = s.getBytes(UTF_8);
UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(bytes);
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
n = db.parse(bais);
}
Element documentElement = null;
if (n instanceof Element) {
documentElement = (Element) n;
} else if (n instanceof Document) {
documentElement = ((Document) n).getDocumentElement();
}
assertions(documentElement);
coll.removeResource(resource);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class MoveCollectionTest method setUp.
@Before
public void setUp() throws XMLDBException {
final Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
final CollectionManagementService service = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
testCollection = service.createCollection(TEST_COLLECTION_NAME);
assertNotNull(testCollection);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class MoveCollectionTest method tearDown.
@After
public void tearDown() throws XMLDBException {
final Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
final CollectionManagementService service = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
service.removeCollection(TEST_COLLECTION_NAME);
testCollection = null;
}
Aggregations