Search in sources :

Example 6 with MCRJDOMContent

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

the class MCRMetadataStoreTest method exists.

@Test
public void exists() throws Exception {
    int id = getMetaDataStore().getNextFreeID();
    assertFalse(getMetaDataStore().exists(id));
    Document xml1 = new Document(new Element("root"));
    getMetaDataStore().create(new MCRJDOMContent(xml1), id);
    assertTrue(getMetaDataStore().exists(id));
    getMetaDataStore().delete(id);
    assertFalse(getMetaDataStore().exists(id));
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 7 with MCRJDOMContent

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

the class MCRMetadataStoreTest method lastModified.

@Test
public void lastModified() throws Exception {
    Document xml1 = new Document(new Element("root"));
    Date date1 = new Date();
    synchronized (this) {
        wait(1000);
    }
    MCRStoredMetadata sm = getMetaDataStore().create(new MCRJDOMContent(xml1));
    Date date2 = sm.getLastModified();
    assertTrue(date2.after(date1));
    synchronized (this) {
        wait(1000);
    }
    Document xml2 = new Document(new Element("root"));
    sm.update(new MCRJDOMContent(xml2));
    assertTrue(sm.getLastModified().after(date2));
    @SuppressWarnings("deprecation") Date date = new Date(109, 1, 1);
    sm.setLastModified(date);
    sm = getMetaDataStore().retrieve(sm.getID());
    assertEquals(date, sm.getLastModified());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Date(java.util.Date) Test(org.junit.Test)

Example 8 with MCRJDOMContent

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

the class MCRVersioningMetadataStoreTest method delete.

@Test
public void delete() throws Exception {
    System.out.println("TEST DELETE");
    Document xml1 = new Document(new Element("root"));
    int id = getVersStore().create(new MCRJDOMContent(xml1)).getID();
    assertTrue(getVersStore().exists(id));
    getVersStore().delete(id);
    assertFalse(getVersStore().exists(id));
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 9 with MCRJDOMContent

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

the class MCRVersioningMetadataStoreTest method createUpdateDeleteCreate.

@Test
public void createUpdateDeleteCreate() throws Exception {
    Element root = new Element("bingo");
    Document xml1 = new Document(root);
    MCRVersionedMetadata vm = getVersStore().create(new MCRJDOMContent(xml1));
    root.setName("bango");
    vm.update(new MCRJDOMContent(xml1));
    vm.delete();
    root.setName("bongo");
    vm = getVersStore().create(new MCRJDOMContent(xml1), vm.getID());
    List<MCRMetadataVersion> versions = vm.listVersions();
    assertEquals(4, versions.size());
    assertEquals(MCRMetadataVersion.CREATED, versions.get(0).getType());
    assertEquals(MCRMetadataVersion.UPDATED, versions.get(1).getType());
    assertEquals(MCRMetadataVersion.DELETED, versions.get(2).getType());
    assertEquals(MCRMetadataVersion.CREATED, versions.get(3).getType());
    versions.get(1).restore();
    assertEquals("bango", vm.getMetadata().asXML().getRootElement().getName());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) Test(org.junit.Test)

Example 10 with MCRJDOMContent

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

the class MCRVersioningMetadataStoreTest method createDocument.

@Test
public void createDocument() throws Exception {
    Document testXmlDoc = new Document(new Element("root"));
    MCRContent testContent = new MCRJDOMContent(testXmlDoc);
    MCRVersionedMetadata versionedMetadata = getVersStore().create(testContent);
    MCRContent contentFromStore = getVersStore().retrieve(versionedMetadata.getID()).getMetadata();
    String contentStrFromStore = contentFromStore.asString();
    MCRContent mcrContent = new MCRJDOMContent(testXmlDoc);
    String expectedContentStr = mcrContent.asString();
    assertNotNull(versionedMetadata);
    assertEquals(expectedContentStr, contentStrFromStore);
    assertTrue(versionedMetadata.getID() > 0);
    assertTrue(versionedMetadata.getRevision() > 0);
    MCRVersionedMetadata vm3 = getVersStore().create(new MCRJDOMContent(testXmlDoc));
    assertTrue(vm3.getID() > versionedMetadata.getID());
    assertTrue(vm3.getRevision() > versionedMetadata.getRevision());
}
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)

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