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());
}
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());
}
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());
}
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);
}
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());
}
Aggregations