use of org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testGetFileSystemItem.
@Test
public void testGetFileSystemItem() throws Exception {
// Get top level folder
String topLevelFolderItemId = fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId();
Blob fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", topLevelFolderItemId).execute();
assertNotNull(fileSystemItemJSON);
DefaultTopLevelFolderItem topLevelFolderItem = mapper.readValue(fileSystemItemJSON.getStream(), DefaultTopLevelFolderItem.class);
assertNotNull(topLevelFolderItem);
assertEquals(topLevelFolderItemId, topLevelFolderItem.getId());
assertNull(topLevelFolderItem.getParentId());
assertEquals("Nuxeo Drive", topLevelFolderItem.getName());
assertTrue(topLevelFolderItem.isFolder());
assertEquals("system", topLevelFolderItem.getCreator());
assertEquals("system", topLevelFolderItem.getLastContributor());
assertFalse(topLevelFolderItem.getCanRename());
assertFalse(topLevelFolderItem.getCanDelete());
assertFalse(topLevelFolderItem.getCanCreateChild());
// Get sync root
fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).execute();
assertNotNull(fileSystemItemJSON);
DefaultSyncRootFolderItem syncRootFolderItem = mapper.readValue(fileSystemItemJSON.getStream(), DefaultSyncRootFolderItem.class);
assertNotNull(syncRootFolderItem);
assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), syncRootFolderItem.getId());
assertTrue(syncRootFolderItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
assertEquals("folder1", syncRootFolderItem.getName());
assertTrue(syncRootFolderItem.isFolder());
assertEquals("Administrator", syncRootFolderItem.getCreator());
assertEquals("Administrator", syncRootFolderItem.getLastContributor());
assertTrue(syncRootFolderItem.getCanRename());
assertTrue(syncRootFolderItem.getCanDelete());
assertTrue(syncRootFolderItem.getCanCreateChild());
// Get file in sync root
fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
assertNotNull(fileSystemItemJSON);
DocumentBackedFileItem fileItem = mapper.readValue(fileSystemItemJSON.getStream(), DocumentBackedFileItem.class);
assertNotNull(fileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId(), fileItem.getId());
assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), fileItem.getParentId());
assertEquals("First file.odt", fileItem.getName());
assertFalse(fileItem.isFolder());
assertEquals("Administrator", fileItem.getCreator());
assertEquals("Administrator", fileItem.getLastContributor());
assertTrue(fileItem.getCanRename());
assertTrue(fileItem.getCanDelete());
assertTrue(fileItem.getCanUpdate());
assertEquals("nxfile/test/" + file1.getId() + "/blobholder:0/First%20file.odt", fileItem.getDownloadURL());
assertEquals("MD5", fileItem.getDigestAlgorithm());
assertEquals(((org.nuxeo.ecm.core.api.Blob) file1.getPropertyValue("file:content")).getDigest(), fileItem.getDigest());
// Get deleted file
file1.followTransition("delete");
// Need to flush VCS cache to be aware of changes in the session used by the file system item
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
assertNotNull(fileSystemItemJSON);
assertNull(mapper.readValue(fileSystemItemJSON.getStream(), Object.class));
}
use of org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testGetTopLevelChildren.
@Test
public void testGetTopLevelChildren() throws Exception {
Blob topLevelFolderJSON = (Blob) clientSession.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
assertNotNull(topLevelFolderJSON);
// Check children
FolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), new TypeReference<DefaultTopLevelFolderItem>() {
});
Blob topLevelChildrenJSON = (Blob) clientSession.newRequest(NuxeoDriveGetChildren.ID).set("id", topLevelFolder.getId()).execute();
List<DefaultSyncRootFolderItem> topLevelChildren = mapper.readValue(topLevelChildrenJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
});
assertNotNull(topLevelChildren);
assertEquals(2, topLevelChildren.size());
DefaultSyncRootFolderItem child = topLevelChildren.get(0);
assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), child.getId());
assertTrue(child.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
assertEquals("folder1", child.getName());
assertTrue(child.isFolder());
assertEquals("Administrator", child.getCreator());
assertEquals("Administrator", child.getLastContributor());
assertTrue(child.getCanRename());
assertTrue(child.getCanDelete());
assertTrue(child.getCanCreateChild());
child = topLevelChildren.get(1);
assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId(), child.getId());
assertTrue(child.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
assertEquals("folder2", child.getName());
assertTrue(child.isFolder());
assertEquals("Administrator", child.getCreator());
assertEquals("Administrator", child.getLastContributor());
assertTrue(child.getCanRename());
assertTrue(child.getCanDelete());
assertTrue(child.getCanCreateChild());
// Check descendants
assertFalse(topLevelFolder.getCanScrollDescendants());
try {
clientSession.newRequest(NuxeoDriveScrollDescendants.ID).set("id", topLevelFolder.getId()).set("batchSize", 10).execute();
fail("Scrolling through the descendants of the default top level folder item should be unsupported.");
} catch (Exception e) {
assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
}
}
Aggregations