Search in sources :

Example 16 with CollectionManagementService

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");
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Account(org.exist.security.Account) Collection(org.xmldb.api.base.Collection)

Example 17 with CollectionManagementService

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) ArrayList(java.util.ArrayList) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection)

Example 18 with CollectionManagementService

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection)

Example 19 with CollectionManagementService

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) InputStream(java.io.InputStream) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection)

Example 20 with CollectionManagementService

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) Before(org.junit.Before)

Aggregations

CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)148 Collection (org.xmldb.api.base.Collection)84 XMLResource (org.xmldb.api.modules.XMLResource)33 Resource (org.xmldb.api.base.Resource)25 Before (org.junit.Before)23 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)21 After (org.junit.After)21 Test (org.junit.Test)19 UserManagementService (org.exist.xmldb.UserManagementService)14 ResourceSet (org.xmldb.api.base.ResourceSet)14 BinaryResource (org.xmldb.api.modules.BinaryResource)13 XPathQueryService (org.xmldb.api.modules.XPathQueryService)9 Account (org.exist.security.Account)7 IndexQueryService (org.exist.xmldb.IndexQueryService)6 AfterClass (org.junit.AfterClass)6 Database (org.xmldb.api.base.Database)6 XMLDBException (org.xmldb.api.base.XMLDBException)6 Path (java.nio.file.Path)5 BeforeClass (org.junit.BeforeClass)5 InputStream (java.io.InputStream)4