Search in sources :

Example 76 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class DtdEntityTest method bugloadWithEntities.

@Test
@Ignore("Entity resolve bug")
public void bugloadWithEntities() throws XMLDBException {
    final String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE procedure PUBLIC \"-//AAAA//DTD Procedure 0.4//EN\" \"aaaa.dtd\" >" + "<a>first empty: &empty; then trade: &trade; </a>";
    Collection col = null;
    try {
        col = existEmbeddedServer.createCollection(existEmbeddedServer.getRoot(), "entity");
        ExistXmldbEmbeddedServer.storeResource(col, "docname.xml", input.getBytes(UTF_8));
        // should throw XMLDBException
        ExistXmldbEmbeddedServer.getXMLResource(col, "docname.xml");
    } catch (final XMLDBException e) {
        assertTrue(e.getMessage().contains("The entity \"empty\" was referenced, but not declared"));
        return;
    } finally {
        if (col != null) {
            col.close();
        }
    }
    fail("Should have thrown XMLDBException");
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 77 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class DtdEntityTest method loadWithEntities.

@Test
public void loadWithEntities() throws XMLDBException {
    final String input = "<a>first empty: &empty; then trade: &trade; </a>";
    Collection col = null;
    try {
        col = existEmbeddedServer.createCollection(existEmbeddedServer.getRoot(), "entity");
        ExistXmldbEmbeddedServer.storeResource(col, "docname.xml", input.getBytes());
        // should throw XMLDBException
        ExistXmldbEmbeddedServer.getXMLResource(col, "docname.xml");
    } catch (final XMLDBException e) {
        assertTrue(e.getMessage().contains("The entity \"empty\" was referenced, but not declared"));
        return;
    } finally {
        if (col != null) {
            col.close();
        }
    }
    fail("Should have thrown XMLDBException");
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 78 with Collection

use of org.xmldb.api.base.Collection 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 79 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class CreateCollectionsTest method rootCollectionHasNoParent.

@Test
public void rootCollectionHasNoParent() throws XMLDBException {
    final Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, ADMIN_DB_USER, ADMIN_DB_PWD);
    assertNull("root collection has no parent", root.getParentCollection());
}
Also used : Collection(org.xmldb.api.base.Collection)

Example 80 with Collection

use of org.xmldb.api.base.Collection 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)

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