Search in sources :

Example 11 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method retrieve.

@Test
public void retrieve() throws Exception {
    Document xml1 = new Document(new Element("root"));
    int id = getVersStore().create(new MCRJDOMContent(xml1)).getID();
    MCRVersionedMetadata sm1 = getVersStore().retrieve(id);
    MCRContent xml2 = sm1.getMetadata();
    assertEquals(new MCRJDOMContent(xml1).asString(), xml2.asString());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent) Test(org.junit.Test)

Example 12 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method deletedVersions.

@Test
public void deletedVersions() throws Exception {
    Element root = new Element("bingo");
    Document xml1 = new Document(root);
    MCRVersionedMetadata vm = getVersStore().create(new MCRJDOMContent(xml1));
    assertFalse(vm.isDeleted());
    vm.delete();
    assertTrue(vm.isDeleted());
    assertFalse(getVersStore().exists(vm.getID()));
    vm = getVersStore().retrieve(vm.getID());
    assertTrue(vm.isDeletedInRepository());
    List<MCRMetadataVersion> versions = vm.listVersions();
    MCRMetadataVersion v1 = versions.get(0);
    MCRMetadataVersion v2 = versions.get(1);
    boolean cannotRestoreDeleted = false;
    try {
        v2.restore();
    } catch (MCRUsageException ex) {
        cannotRestoreDeleted = true;
    }
    assertTrue(cannotRestoreDeleted);
    v1.restore();
    assertFalse(vm.isDeletedInRepository());
    assertEquals(root.getName(), vm.getMetadata().asXML().getRootElement().getName());
}
Also used : MCRUsageException(org.mycore.common.MCRUsageException) Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 13 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method createDocumentInt.

@Test
public void createDocumentInt() throws Exception {
    int id = getVersStore().getNextFreeID();
    assertTrue(id > 0);
    Document xml1 = new Document(new Element("root"));
    MCRVersionedMetadata vm1 = getVersStore().create(new MCRJDOMContent(xml1), id);
    MCRContent xml2 = getVersStore().retrieve(id).getMetadata();
    assertNotNull(vm1);
    assertEquals(new MCRJDOMContent(xml1).asString(), xml2.asString());
    getVersStore().create(new MCRJDOMContent(xml1), id + 1);
    MCRContent xml3 = getVersStore().retrieve(id + 1).getMetadata();
    assertEquals(new MCRJDOMContent(xml1).asString(), xml3.asString());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent) Test(org.junit.Test)

Example 14 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRFileStoreTest method equals.

private boolean equals(Document a, Document b) throws Exception {
    sortChildren(a.getRootElement());
    sortChildren(b.getRootElement());
    String sa = new MCRJDOMContent(a).asString();
    String sb = new MCRJDOMContent(b).asString();
    return sa.equals(sb);
}
Also used : MCRJDOMContent(org.mycore.common.content.MCRJDOMContent)

Example 15 with MCRJDOMContent

use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.

the class MCRFileStoreTest method basicFunctionality.

@Test
public void basicFunctionality() throws Exception {
    Date first = new Date();
    synchronized (this) {
        wait(1000);
    }
    MCRFileCollection col = getStore().create();
    assertNotNull(col);
    assertTrue(col.getID() > 0);
    Date created = col.getLastModified();
    assertFalse(first.after(created));
    bzzz();
    MCRFile build = col.createFile("build.xml");
    assertNotNull(build);
    Date modified = col.getLastModified();
    assertTrue(modified.after(created));
    assertEquals(1, col.getNumChildren());
    assertEquals(1, col.getChildren().size());
    assertEquals(0, build.getSize());
    assertTrue(created.before(build.getLastModified()));
    build.setContent(new MCRJDOMContent(new Element("project")));
    assertTrue(build.getSize() > 0);
    assertNotNull(build.getContent().asByteArray());
    bzzz();
    MCRDirectory dir = col.createDir("documentation");
    assertEquals(2, col.getNumChildren());
    assertTrue(modified.before(col.getLastModified()));
    byte[] content = "Hello World!".getBytes("UTF-8");
    dir.createFile("readme.txt").setContent(new MCRByteContent(content, System.currentTimeMillis()));
    MCRFile child = (MCRFile) dir.getChild("readme.txt");
    assertNotNull(child);
    assertEquals(content.length, child.getSize());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRByteContent(org.mycore.common.content.MCRByteContent) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)54 Document (org.jdom2.Document)33 Element (org.jdom2.Element)28 Test (org.junit.Test)21 MCRContent (org.mycore.common.content.MCRContent)20 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)6 IOException (java.io.IOException)5 File (java.io.File)4 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4 Date (java.util.Date)3 JDOMException (org.jdom2.JDOMException)3 MCRContentTransformer (org.mycore.common.content.transformer.MCRContentTransformer)3 MCRPath (org.mycore.datamodel.niofs.MCRPath)3 FileObject (org.apache.commons.vfs2.FileObject)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 MCRException (org.mycore.common.MCRException)2 MCRPersistenceException (org.mycore.common.MCRPersistenceException)2 MCRFileContent (org.mycore.common.content.MCRFileContent)2