Search in sources :

Example 81 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class VariablesTest method createCollection.

private static Collection createCollection(final String collectionName) throws XMLDBException {
    Collection collection = existEmbeddedServer.getRoot().getChildCollection(collectionName);
    final CollectionManagementService cmService = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    if (collection == null) {
        // cmService.removeCollection(collectionName);
        cmService.createCollection(collectionName);
    }
    collection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + collectionName, TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
    assertNotNull(collection);
    return collection;
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection)

Example 82 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class FunSubSequenceTest method cleanup.

@AfterClass
public static void cleanup() throws XMLDBException {
    final CollectionManagementService collectionManagementService = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    collectionManagementService.removeCollection(test.getName());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) AfterClass(org.junit.AfterClass)

Example 83 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class XQueryFunctionsTest method base64BinaryCast.

@Test
public void base64BinaryCast() throws XMLDBException, URISyntaxException {
    final String TEST_BINARY_COLLECTION = "testBinary";
    final String TEST_COLLECTION = "/db/" + TEST_BINARY_COLLECTION;
    final String BINARY_RESOURCE_FILENAME = "logo.jpg";
    final String XML_RESOURCE_FILENAME = "logo.xml";
    // create a test collection
    CollectionManagementService colService = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    Collection testCollection = colService.createCollection(TEST_BINARY_COLLECTION);
    assertNotNull(testCollection);
    final Path fLogo = Paths.get(getClass().getResource("value/logo.jpg").toURI());
    // store the eXist logo in the test collection
    BinaryResource br = (BinaryResource) testCollection.createResource(BINARY_RESOURCE_FILENAME, "BinaryResource");
    br.setContent(fLogo);
    testCollection.storeResource(br);
    // create an XML resource with the logo base64 embedded in it
    String queryStore = "xquery version \"1.0\";\n\n" + "let $embedded := <logo><image>{util:binary-doc(\"" + TEST_COLLECTION + "/" + BINARY_RESOURCE_FILENAME + "\")}</image></logo> return\n" + "xmldb:store(\"" + TEST_COLLECTION + "\", \"" + XML_RESOURCE_FILENAME + "\", $embedded)";
    ResourceSet resultStore = existEmbeddedServer.executeQuery(queryStore);
    assertEquals("store, Expect single result", 1, resultStore.getSize());
    assertEquals("Expect stored filename as result", TEST_COLLECTION + "/" + XML_RESOURCE_FILENAME, resultStore.getResource(0).getContent().toString());
    // retrieve the base64 image from the XML resource and try to cast to xs:base64Binary
    String queryRetreive = "xquery version \"1.0\";\n\n" + "let $image := doc(\"" + TEST_COLLECTION + "/" + XML_RESOURCE_FILENAME + "\")/logo/image return\n" + "$image/text() cast as xs:base64Binary";
    ResourceSet resultRetreive = existEmbeddedServer.executeQuery(queryRetreive);
    assertEquals("retreive, Expect single result", 1, resultRetreive.getSize());
}
Also used : Path(java.nio.file.Path) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) BinaryResource(org.xmldb.api.modules.BinaryResource) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 84 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class ProtectedModeTest method cleanupDb.

@AfterClass
public static void cleanupDb() throws XMLDBException {
    final CollectionManagementService cmgr = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    cmgr.removeCollection("protected");
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) AfterClass(org.junit.AfterClass)

Example 85 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class AbstractTestUpdate method tearDown.

@After
public void tearDown() throws XMLDBException {
    CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    service.removeCollection("test");
    Collection confColl = DatabaseManager.getCollection("xmldb:exist:///db/system/config/db", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
    service = (CollectionManagementService) confColl.getService("CollectionManagementService", "1.0");
    service.removeCollection("test");
    testCollection = null;
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) After(org.junit.After)

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