Search in sources :

Example 81 with Collection

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

Example 82 with Collection

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);
}
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 83 with Collection

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);
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Database(org.xmldb.api.base.Database) Collection(org.xmldb.api.base.Collection) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Document(org.w3c.dom.Document) XMLResource(org.xmldb.api.modules.XMLResource)

Example 84 with Collection

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

Example 85 with Collection

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

Aggregations

Collection (org.xmldb.api.base.Collection)345 XMLResource (org.xmldb.api.modules.XMLResource)140 Test (org.junit.Test)115 Resource (org.xmldb.api.base.Resource)111 UserManagementService (org.exist.xmldb.UserManagementService)91 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)85 BinaryResource (org.xmldb.api.modules.BinaryResource)80 XMLDBException (org.xmldb.api.base.XMLDBException)68 ResourceSet (org.xmldb.api.base.ResourceSet)55 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)48 XPathQueryService (org.xmldb.api.modules.XPathQueryService)31 EXistResource (org.exist.xmldb.EXistResource)25 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)20 Before (org.junit.Before)20 URISyntaxException (java.net.URISyntaxException)18 Path (java.nio.file.Path)18 InputStream (java.io.InputStream)17 BuildException (org.apache.tools.ant.BuildException)14 XmldbURI (org.exist.xmldb.XmldbURI)13 Account (org.exist.security.Account)10