use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class CreateCollectionsTest method setUp.
@Before
public void setUp() throws XMLDBException {
// create a test collection
final CollectionManagementService cms = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
final Collection test = cms.createCollection(TEST_COLLECTION);
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
// change ownership to guest
Account guest = ums.getAccount(GUEST_DB_USER);
ums.chown(guest, guest.getPrimaryGroup());
ums.chmod("rwxrwxrwx");
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class CreateCollectionsTest method storeSamplesShakespeare.
@Test
public void storeSamplesShakespeare() 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 List<String> storedResourceNames = new ArrayList<>();
final List<String> filenames = new ArrayList<>();
// store the samples
for (final String sampleName : SAMPLES.getShakespeareXmlSampleNames()) {
final Resource res = storeResourceFromFile(SAMPLES.getShakespeareSample(sampleName), testCollection, sampleName);
storedResourceNames.add(res.getId());
filenames.add(sampleName);
}
assertEquals(filenames, storedResourceNames);
// get a list from the database of stored resource names
final List<String> retrievedStoredResourceNames = Arrays.asList(testCollection.listResources());
// order of names from database may not be the order in which the files were loaded!
Collections.sort(filenames);
Collections.sort(retrievedStoredResourceNames);
assertEquals(filenames, retrievedStoredResourceNames);
}
use of org.xmldb.api.modules.CollectionManagementService 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.modules.CollectionManagementService 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.modules.CollectionManagementService 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);
}
Aggregations