use of org.nuxeo.ecm.automation.client.model.StringBlob in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testUpdateFile.
@Test
public void testUpdateFile() throws Exception {
StringBlob blob = new StringBlob("This is the updated content of file 1.");
blob.setFileName("Updated file 1.odt");
Blob updatedFileJSON = (Blob) clientSession.newRequest(NuxeoDriveUpdateFile.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).setInput(blob).execute();
assertNotNull(updatedFileJSON);
DocumentBackedFileItem updatedFile = mapper.readValue(updatedFileJSON.getStream(), DocumentBackedFileItem.class);
assertNotNull(updatedFile);
// Need to flush VCS cache to be aware of changes in the session used by the file system item
session.save();
DocumentModel updatedFileDoc = session.getDocument(new IdRef(file1.getId()));
assertEquals("File", updatedFileDoc.getType());
assertEquals("file1", updatedFileDoc.getTitle());
org.nuxeo.ecm.core.api.Blob updatedFileBlob = (org.nuxeo.ecm.core.api.Blob) updatedFileDoc.getPropertyValue("file:content");
assertNotNull(updatedFileBlob);
assertEquals("Updated file 1.odt", updatedFileBlob.getFilename());
assertEquals("This is the updated content of file 1.", updatedFileBlob.getString());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + updatedFileDoc.getId(), updatedFile.getId());
assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), updatedFile.getParentId());
assertEquals("Updated file 1.odt", updatedFile.getName());
assertFalse(updatedFile.isFolder());
assertEquals("Administrator", updatedFile.getCreator());
assertEquals("Administrator", updatedFile.getLastContributor());
assertTrue(updatedFile.getCanRename());
assertTrue(updatedFile.getCanDelete());
assertTrue(updatedFile.getCanUpdate());
assertEquals("nxfile/test/" + updatedFileDoc.getId() + "/blobholder:0/Updated%20file%201.odt", updatedFile.getDownloadURL());
assertEquals("MD5", updatedFile.getDigestAlgorithm());
assertEquals(updatedFileBlob.getDigest(), updatedFile.getDigest());
}
use of org.nuxeo.ecm.automation.client.model.StringBlob in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testCreateFile.
@Test
public void testCreateFile() throws Exception {
StringBlob blob = new StringBlob("This is the content of a new file.");
blob.setFileName("New file.odt");
Blob newFileJSON = (Blob) clientSession.newRequest(NuxeoDriveCreateFile.ID).set("parentId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId()).setInput(blob).execute();
assertNotNull(newFileJSON);
DocumentBackedFileItem newFile = mapper.readValue(newFileJSON.getStream(), DocumentBackedFileItem.class);
assertNotNull(newFile);
// Need to flush VCS cache to be aware of changes in the session used by the file system item
session.save();
DocumentModel newFileDoc = session.getDocument(new PathRef("/folder1/subFolder1/New file.odt"));
assertEquals("File", newFileDoc.getType());
assertEquals("New file.odt", newFileDoc.getTitle());
org.nuxeo.ecm.core.api.Blob newFileBlob = (org.nuxeo.ecm.core.api.Blob) newFileDoc.getPropertyValue("file:content");
assertNotNull(newFileBlob);
assertEquals("New file.odt", newFileBlob.getFilename());
assertEquals("This is the content of a new file.", newFileBlob.getString());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + newFileDoc.getId(), newFile.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId(), newFile.getParentId());
assertEquals("New file.odt", newFile.getName());
assertFalse(newFile.isFolder());
assertEquals("Administrator", newFile.getCreator());
assertEquals("Administrator", newFile.getLastContributor());
assertTrue(newFile.getCanRename());
assertTrue(newFile.getCanDelete());
assertTrue(newFile.getCanUpdate());
assertEquals("nxfile/test/" + newFileDoc.getId() + "/blobholder:0/New%20file.odt", newFile.getDownloadURL());
assertEquals("MD5", newFile.getDigestAlgorithm());
assertEquals(newFileBlob.getDigest(), newFile.getDigest());
}
Aggregations